Просмотр исходного кода

lib/model: Also wait for ItemFinished in TestDeregister (#4951)

Simon Frei 7 лет назад
Родитель
Сommit
eabce48761
1 измененных файлов с 17 добавлено и 0 удалено
  1. 17 0
      lib/model/folder_sendrecv_test.go

+ 17 - 0
lib/model/folder_sendrecv_test.go

@@ -19,6 +19,7 @@ import (
 
 
 	"github.com/syncthing/syncthing/lib/config"
 	"github.com/syncthing/syncthing/lib/config"
 	"github.com/syncthing/syncthing/lib/db"
 	"github.com/syncthing/syncthing/lib/db"
+	"github.com/syncthing/syncthing/lib/events"
 	"github.com/syncthing/syncthing/lib/fs"
 	"github.com/syncthing/syncthing/lib/fs"
 	"github.com/syncthing/syncthing/lib/ignore"
 	"github.com/syncthing/syncthing/lib/ignore"
 	"github.com/syncthing/syncthing/lib/protocol"
 	"github.com/syncthing/syncthing/lib/protocol"
@@ -474,6 +475,8 @@ func TestDeregisterOnFailInCopy(t *testing.T) {
 	// Unblock copier
 	// Unblock copier
 	<-pullChan
 	<-pullChan
 
 
+	s := events.Default.Subscribe(events.ItemFinished)
+	timeout = time.Second
 	select {
 	select {
 	case state := <-finisherBufferChan:
 	case state := <-finisherBufferChan:
 		// At this point the file should still be registered with both the job
 		// At this point the file should still be registered with both the job
@@ -484,6 +487,12 @@ func TestDeregisterOnFailInCopy(t *testing.T) {
 
 
 		// Pass the file down the real finisher, and give it time to consume
 		// Pass the file down the real finisher, and give it time to consume
 		finisherChan <- state
 		finisherChan <- state
+
+		if ev, err := s.Poll(timeout); err != nil {
+			t.Fatal("Got error waiting for ItemFinished event:", err)
+		} else if n := ev.Data.(map[string]interface{})["item"]; n != state.file.Name {
+			t.Fatal("Got ItemFinished event for wrong file:", n)
+		}
 		time.Sleep(100 * time.Millisecond)
 		time.Sleep(100 * time.Millisecond)
 
 
 		state.mut.Lock()
 		state.mut.Lock()
@@ -541,6 +550,8 @@ func TestDeregisterOnFailInPull(t *testing.T) {
 
 
 	// Receive at finisher, we should error out as puller has nowhere to pull
 	// Receive at finisher, we should error out as puller has nowhere to pull
 	// from.
 	// from.
+	s := events.Default.Subscribe(events.ItemFinished)
+	timeout = time.Second
 	select {
 	select {
 	case state := <-finisherBufferChan:
 	case state := <-finisherBufferChan:
 		// At this point the file should still be registered with both the job
 		// At this point the file should still be registered with both the job
@@ -551,6 +562,12 @@ func TestDeregisterOnFailInPull(t *testing.T) {
 
 
 		// Pass the file down the real finisher, and give it time to consume
 		// Pass the file down the real finisher, and give it time to consume
 		finisherChan <- state
 		finisherChan <- state
+
+		if ev, err := s.Poll(timeout); err != nil {
+			t.Fatal("Got error waiting for ItemFinished event:", err)
+		} else if n := ev.Data.(map[string]interface{})["item"]; n != state.file.Name {
+			t.Fatal("Got ItemFinished event for wrong file:", n)
+		}
 		time.Sleep(100 * time.Millisecond)
 		time.Sleep(100 * time.Millisecond)
 
 
 		state.mut.Lock()
 		state.mut.Lock()