1
0
Эх сурвалжийг харах

lib/model: Fail test instead of panic due to closing channel twice (#5508)

Simon Frei 6 жил өмнө
parent
commit
af4fb97538

+ 44 - 3
lib/model/requests_test.go

@@ -43,6 +43,11 @@ func TestRequestSimple(t *testing.T) {
 	done := make(chan struct{})
 	fc.mut.Lock()
 	fc.indexFn = func(folder string, fs []protocol.FileInfo) {
+		select {
+		case <-done:
+			t.Fatalf("More than one index update sent")
+		default:
+		}
 		for _, f := range fs {
 			if f.Name == "testfile" {
 				close(done)
@@ -86,6 +91,11 @@ func TestSymlinkTraversalRead(t *testing.T) {
 	done := make(chan struct{})
 	fc.mut.Lock()
 	fc.indexFn = func(folder string, fs []protocol.FileInfo) {
+		select {
+		case <-done:
+			t.Fatalf("More than one index update sent")
+		default:
+		}
 		for _, f := range fs {
 			if f.Name == "symlink" {
 				close(done)
@@ -661,9 +671,14 @@ func TestRequestSymlinkWindows(t *testing.T) {
 		testOs.Remove(w.ConfigPath())
 	}()
 
-	first := make(chan struct{})
+	done := make(chan struct{})
 	fc.mut.Lock()
 	fc.indexFn = func(folder string, fs []protocol.FileInfo) {
+		select {
+		case <-done:
+			t.Fatalf("More than one index update sent")
+		default:
+		}
 		// expected first index
 		if len(fs) != 1 {
 			t.Fatalf("Expected just one file in index, got %v", fs)
@@ -675,7 +690,7 @@ func TestRequestSymlinkWindows(t *testing.T) {
 		if !f.IsInvalid() {
 			t.Errorf(`File info was not marked as invalid`)
 		}
-		close(first)
+		close(done)
 	}
 	fc.mut.Unlock()
 
@@ -683,7 +698,7 @@ func TestRequestSymlinkWindows(t *testing.T) {
 	fc.sendIndexUpdate()
 
 	select {
-	case <-first:
+	case <-done:
 	case <-time.After(time.Second):
 		t.Fatalf("timed out before pull was finished")
 	}
@@ -772,6 +787,11 @@ func TestRequestRemoteRenameChanged(t *testing.T) {
 	done := make(chan struct{})
 	fc.mut.Lock()
 	fc.indexFn = func(folder string, fs []protocol.FileInfo) {
+		select {
+		case <-done:
+			t.Fatalf("More than one index update sent")
+		default:
+		}
 		if len(fs) != 2 {
 			t.Fatalf("Received index with %v indexes instead of 2", len(fs))
 		}
@@ -795,6 +815,11 @@ func TestRequestRemoteRenameChanged(t *testing.T) {
 		done = make(chan struct{})
 		fc.mut.Lock()
 		fc.indexFn = func(folder string, fs []protocol.FileInfo) {
+			select {
+			case <-done:
+				t.Fatalf("More than one index update sent")
+			default:
+			}
 			close(done)
 		}
 		fc.mut.Unlock()
@@ -954,6 +979,11 @@ func TestRequestDeleteChanged(t *testing.T) {
 	done := make(chan struct{})
 	fc.mut.Lock()
 	fc.indexFn = func(folder string, fs []protocol.FileInfo) {
+		select {
+		case <-done:
+			t.Fatalf("More than one index update sent")
+		default:
+		}
 		close(done)
 	}
 	fc.mut.Unlock()
@@ -970,6 +1000,17 @@ func TestRequestDeleteChanged(t *testing.T) {
 		t.Fatal("timed out")
 	}
 
+	fc.mut.Lock()
+	fc.indexFn = func(folder string, fs []protocol.FileInfo) {
+		select {
+		case <-done:
+			t.Fatalf("More than one index update sent")
+		default:
+		}
+		close(done)
+	}
+	fc.mut.Unlock()
+
 	fd, err := tfs.OpenFile(a, fs.OptReadWrite, 0644)
 	if err != nil {
 		t.Fatal(err)