lib/model, lib/testutils: Test closing a connection on folder restart (#5707)

This commit is contained in:
Simon Frei
2019-05-18 08:53:59 +02:00
committed by Jakob Borg
parent 5ffbb7668d
commit 1b2b970f32
3 changed files with 106 additions and 24 deletions

View File

@@ -31,6 +31,7 @@ import (
"github.com/syncthing/syncthing/lib/osutil"
"github.com/syncthing/syncthing/lib/protocol"
srand "github.com/syncthing/syncthing/lib/rand"
"github.com/syncthing/syncthing/lib/testutils"
"github.com/syncthing/syncthing/lib/versioner"
)
@@ -3381,3 +3382,38 @@ func TestSanitizePath(t *testing.T) {
}
}
}
// TestConnCloseOnRestart checks that there is no deadlock when calling Close
// on a protocol connection that has a blocking reader (blocking writer can't
// be done as the test requires clusterconfigs to go through).
func TestConnCloseOnRestart(t *testing.T) {
w, fcfg := tmpDefaultWrapper()
m := setupModel(w)
defer func() {
m.Stop()
m.db.Close()
os.RemoveAll(fcfg.Filesystem().URI())
os.Remove(w.ConfigPath())
}()
br := &testutils.BlockingRW{}
nw := &testutils.NoopRW{}
m.AddConnection(newFakeProtoConn(protocol.NewConnection(device1, br, nw, m, "testConn", protocol.CompressNever)), protocol.HelloResult{})
newFcfg := fcfg.Copy()
newFcfg.Paused = true
done := make(chan struct{})
go func() {
m.RestartFolder(fcfg, newFcfg)
close(done)
}()
select {
case <-done:
case <-time.After(5 * time.Second):
t.Fatal("Timed out before folder restart returned")
}
m.pmut.RLock()
if len(m.conn) != 0 {
t.Errorf("Conn wasn't removed on restart (len(m.conn) == %v)", len(m.conn))
}
}