lib/connections: Trigger dialer when connection gets closed (#7753)
This commit is contained in:
@@ -27,14 +27,18 @@ func newFakeConnection(id protocol.DeviceID, model Model) *fakeConnection {
|
||||
Connection: new(protocolmocks.Connection),
|
||||
id: id,
|
||||
model: model,
|
||||
closed: make(chan struct{}),
|
||||
}
|
||||
f.RequestCalls(func(ctx context.Context, folder, name string, blockNo int, offset int64, size int, hash []byte, weakHash uint32, fromTemporary bool) ([]byte, error) {
|
||||
return f.fileData[name], nil
|
||||
})
|
||||
f.IDReturns(id)
|
||||
f.CloseCalls(func(err error) {
|
||||
f.closeOnce.Do(func() {
|
||||
close(f.closed)
|
||||
})
|
||||
model.Closed(id, err)
|
||||
f.ClosedReturns(true)
|
||||
f.ClosedReturns(f.closed)
|
||||
})
|
||||
return f
|
||||
}
|
||||
@@ -47,6 +51,8 @@ type fakeConnection struct {
|
||||
fileData map[string][]byte
|
||||
folder string
|
||||
model Model
|
||||
closed chan struct{}
|
||||
closeOnce sync.Once
|
||||
mut sync.Mutex
|
||||
}
|
||||
|
||||
|
||||
@@ -2245,8 +2245,10 @@ func TestSharedWithClearedOnDisconnect(t *testing.T) {
|
||||
t.Error("not shared with device2")
|
||||
}
|
||||
|
||||
if conn2.Closed() {
|
||||
select {
|
||||
case <-conn2.Closed():
|
||||
t.Error("conn already closed")
|
||||
default:
|
||||
}
|
||||
|
||||
if _, err := wcfg.RemoveDevice(device2); err != nil {
|
||||
@@ -2271,7 +2273,9 @@ func TestSharedWithClearedOnDisconnect(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
if !conn2.Closed() {
|
||||
select {
|
||||
case <-conn2.Closed():
|
||||
default:
|
||||
t.Error("connection not closed")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user