lib/model: Prevent test deadlock (#7110)

This commit is contained in:
Simon Frei 2020-11-10 12:32:07 +01:00 committed by GitHub
parent 1d3b9876f6
commit b8051fb37e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1149,6 +1149,9 @@ func TestRequestLastFileProgress(t *testing.T) {
} }
func TestRequestIndexSenderPause(t *testing.T) { func TestRequestIndexSenderPause(t *testing.T) {
done := make(chan struct{})
defer close(done)
m, fc, fcfg := setupModelWithConnection() m, fc, fcfg := setupModelWithConnection()
tfs := fcfg.Filesystem() tfs := fcfg.Filesystem()
defer cleanupModelAndRemoveDir(m, tfs.URI()) defer cleanupModelAndRemoveDir(m, tfs.URI())
@ -1156,7 +1159,10 @@ func TestRequestIndexSenderPause(t *testing.T) {
indexChan := make(chan []protocol.FileInfo) indexChan := make(chan []protocol.FileInfo)
fc.mut.Lock() fc.mut.Lock()
fc.indexFn = func(_ context.Context, folder string, fs []protocol.FileInfo) { fc.indexFn = func(_ context.Context, folder string, fs []protocol.FileInfo) {
indexChan <- fs select {
case indexChan <- fs:
case <-done:
}
} }
fc.mut.Unlock() fc.mut.Unlock()
@ -1167,7 +1173,6 @@ func TestRequestIndexSenderPause(t *testing.T) {
localIndexUpdate(m, fcfg.ID, files) localIndexUpdate(m, fcfg.ID, files)
select { select {
case <-time.After(5 * time.Second): case <-time.After(5 * time.Second):
l.Infoln("timeout")
t.Fatal("timed out before receiving index") t.Fatal("timed out before receiving index")
case <-indexChan: case <-indexChan:
} }