소스 검색

lib/model: Locking in the request test

Jakob Borg 9 년 전
부모
커밋
e4db86836b
2개의 변경된 파일6개의 추가작업 그리고 0개의 파일을 삭제
  1. 4 0
      lib/model/model_test.go
  2. 2 0
      lib/model/requests_test.go

+ 4 - 0
lib/model/model_test.go

@@ -253,6 +253,8 @@ func (f *fakeConnection) Option(string) string {
 }
 
 func (f *fakeConnection) Index(folder string, fs []protocol.FileInfo) error {
+	f.mut.Lock()
+	defer f.mut.Unlock()
 	if f.indexFn != nil {
 		f.indexFn(folder, fs)
 	}
@@ -260,6 +262,8 @@ func (f *fakeConnection) Index(folder string, fs []protocol.FileInfo) error {
 }
 
 func (f *fakeConnection) IndexUpdate(folder string, fs []protocol.FileInfo) error {
+	f.mut.Lock()
+	defer f.mut.Unlock()
 	if f.indexFn != nil {
 		f.indexFn(folder, fs)
 	}

+ 2 - 0
lib/model/requests_test.go

@@ -29,6 +29,7 @@ func TestRequestSimple(t *testing.T) {
 	// We listen for incoming index updates and trigger when we see one for
 	// the expected test file.
 	done := make(chan struct{})
+	fc.mut.Lock()
 	fc.indexFn = func(folder string, fs []protocol.FileInfo) {
 		for _, f := range fs {
 			if f.Name == "testfile" {
@@ -37,6 +38,7 @@ func TestRequestSimple(t *testing.T) {
 			}
 		}
 	}
+	fc.mut.Unlock()
 
 	// Send an update for the test file, wait for it to sync and be reported back.
 	contents := []byte("test file contents\n")