lib/protocol: Prioritize close msg and add close timeout (#5746)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user