lib/protocol: Prioritize close msg and add close timeout (#5746)

This commit is contained in:
Simon Frei
2019-06-05 08:01:59 +02:00
committed by Jakob Borg
parent 6e8aa0ec25
commit e39d3f95dd
3 changed files with 64 additions and 6 deletions

View File

@@ -86,6 +86,12 @@ func TestClose(t *testing.T) {
// Close is called while the underlying connection is broken (send blocks).
// https://github.com/syncthing/syncthing/pull/5442
func TestCloseOnBlockingSend(t *testing.T) {
oldCloseTimeout := CloseTimeout
CloseTimeout = 100 * time.Millisecond
defer func() {
CloseTimeout = oldCloseTimeout
}()
m := newTestModel()
c := NewConnection(c0ID, &testutils.BlockingRW{}, &testutils.BlockingRW{}, m, "name", CompressAlways).(wireFormatConnection).Connection.(*rawConnection)
@@ -214,6 +220,33 @@ func TestClusterConfigFirst(t *testing.T) {
}
}
// TestCloseTimeout checks that calling Close times out and proceeds, if sending
// the close message does not succeed.
func TestCloseTimeout(t *testing.T) {
oldCloseTimeout := CloseTimeout
CloseTimeout = 100 * time.Millisecond
defer func() {
CloseTimeout = oldCloseTimeout
}()
m := newTestModel()
c := NewConnection(c0ID, &testutils.BlockingRW{}, &testutils.BlockingRW{}, m, "name", CompressAlways).(wireFormatConnection).Connection.(*rawConnection)
c.Start()
done := make(chan struct{})
go func() {
c.Close(errManual)
close(done)
}()
select {
case <-done:
case <-time.After(5 * CloseTimeout):
t.Fatal("timed out before Close returned")
}
}
func TestMarshalIndexMessage(t *testing.T) {
if testing.Short() {
quickCfg.MaxCount = 10