This commit is contained in:
+60
-24
@@ -3339,17 +3339,19 @@ func TestConnCloseOnRestart(t *testing.T) {
|
||||
closed := m.closed[device1]
|
||||
m.pmut.RUnlock()
|
||||
|
||||
newFcfg := fcfg.Copy()
|
||||
newFcfg.Paused = true
|
||||
waiter, err := w.RemoveDevice(device1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
m.restartFolder(fcfg, newFcfg, false)
|
||||
waiter.Wait()
|
||||
close(done)
|
||||
}()
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("Timed out before folder restart returned")
|
||||
t.Fatal("Timed out before config took effect")
|
||||
}
|
||||
select {
|
||||
case <-closed:
|
||||
@@ -3845,8 +3847,8 @@ func TestScanRenameCaseOnly(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestConnectionTerminationOnFolderAdd(t *testing.T) {
|
||||
testConfigChangeClosesConnections(t, false, true, nil, func(cfg config.Wrapper) {
|
||||
func TestClusterConfigOnFolderAdd(t *testing.T) {
|
||||
testConfigChangeTriggersClusterConfigs(t, false, true, nil, func(cfg config.Wrapper) {
|
||||
fcfg := testFolderConfigTmp()
|
||||
fcfg.ID = "second"
|
||||
fcfg.Label = "second"
|
||||
@@ -3859,8 +3861,8 @@ func TestConnectionTerminationOnFolderAdd(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestConnectionTerminationOnFolderShare(t *testing.T) {
|
||||
testConfigChangeClosesConnections(t, true, true, nil, func(cfg config.Wrapper) {
|
||||
func TestClusterConfigOnFolderShare(t *testing.T) {
|
||||
testConfigChangeTriggersClusterConfigs(t, true, true, nil, func(cfg config.Wrapper) {
|
||||
fcfg := cfg.FolderList()[0]
|
||||
fcfg.Devices = []config.FolderDeviceConfiguration{{device2, protocol.EmptyDeviceID}}
|
||||
if w, err := cfg.SetFolder(fcfg); err != nil {
|
||||
@@ -3871,8 +3873,8 @@ func TestConnectionTerminationOnFolderShare(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestConnectionTerminationOnFolderUnshare(t *testing.T) {
|
||||
testConfigChangeClosesConnections(t, true, false, nil, func(cfg config.Wrapper) {
|
||||
func TestClusterConfigOnFolderUnshare(t *testing.T) {
|
||||
testConfigChangeTriggersClusterConfigs(t, true, false, nil, func(cfg config.Wrapper) {
|
||||
fcfg := cfg.FolderList()[0]
|
||||
fcfg.Devices = nil
|
||||
if w, err := cfg.SetFolder(fcfg); err != nil {
|
||||
@@ -3883,8 +3885,8 @@ func TestConnectionTerminationOnFolderUnshare(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestConnectionTerminationOnFolderRemove(t *testing.T) {
|
||||
testConfigChangeClosesConnections(t, true, false, nil, func(cfg config.Wrapper) {
|
||||
func TestClusterConfigOnFolderRemove(t *testing.T) {
|
||||
testConfigChangeTriggersClusterConfigs(t, true, false, nil, func(cfg config.Wrapper) {
|
||||
rcfg := cfg.RawCopy()
|
||||
rcfg.Folders = nil
|
||||
if w, err := cfg.Replace(rcfg); err != nil {
|
||||
@@ -3895,8 +3897,8 @@ func TestConnectionTerminationOnFolderRemove(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestConnectionTerminationOnFolderPause(t *testing.T) {
|
||||
testConfigChangeClosesConnections(t, true, false, nil, func(cfg config.Wrapper) {
|
||||
func TestClusterConfigOnFolderPause(t *testing.T) {
|
||||
testConfigChangeTriggersClusterConfigs(t, true, false, nil, func(cfg config.Wrapper) {
|
||||
fcfg := cfg.FolderList()[0]
|
||||
fcfg.Paused = true
|
||||
if w, err := cfg.SetFolder(fcfg); err != nil {
|
||||
@@ -3907,8 +3909,8 @@ func TestConnectionTerminationOnFolderPause(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestConnectionTerminationOnFolderUnpause(t *testing.T) {
|
||||
testConfigChangeClosesConnections(t, true, false, func(cfg config.Wrapper) {
|
||||
func TestClusterConfigOnFolderUnpause(t *testing.T) {
|
||||
testConfigChangeTriggersClusterConfigs(t, true, false, func(cfg config.Wrapper) {
|
||||
fcfg := cfg.FolderList()[0]
|
||||
fcfg.Paused = true
|
||||
if w, err := cfg.SetFolder(fcfg); err != nil {
|
||||
@@ -3984,7 +3986,7 @@ func TestScanDeletedROChangedOnSR(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testConfigChangeClosesConnections(t *testing.T, expectFirstClosed, expectSecondClosed bool, pre func(config.Wrapper), fn func(config.Wrapper)) {
|
||||
func testConfigChangeTriggersClusterConfigs(t *testing.T, expectFirst, expectSecond bool, pre func(config.Wrapper), fn func(config.Wrapper)) {
|
||||
t.Helper()
|
||||
wcfg, _ := tmpDefaultWrapper()
|
||||
m := setupModel(wcfg)
|
||||
@@ -3999,21 +4001,55 @@ func testConfigChangeClosesConnections(t *testing.T, expectFirstClosed, expectSe
|
||||
pre(wcfg)
|
||||
}
|
||||
|
||||
fc1 := &fakeConnection{id: device1, model: m}
|
||||
fc2 := &fakeConnection{id: device2, model: m}
|
||||
cc1 := make(chan struct{}, 1)
|
||||
cc2 := make(chan struct{}, 1)
|
||||
fc1 := &fakeConnection{
|
||||
id: device1,
|
||||
model: m,
|
||||
clusterConfigFn: func(_ protocol.ClusterConfig) {
|
||||
cc1 <- struct{}{}
|
||||
},
|
||||
}
|
||||
fc2 := &fakeConnection{
|
||||
id: device2,
|
||||
model: m,
|
||||
clusterConfigFn: func(_ protocol.ClusterConfig) {
|
||||
cc2 <- struct{}{}
|
||||
},
|
||||
}
|
||||
m.AddConnection(fc1, protocol.Hello{})
|
||||
m.AddConnection(fc2, protocol.Hello{})
|
||||
|
||||
// Initial CCs
|
||||
select {
|
||||
case <-cc1:
|
||||
default:
|
||||
t.Fatal("missing initial CC from device1")
|
||||
}
|
||||
select {
|
||||
case <-cc2:
|
||||
default:
|
||||
t.Fatal("missing initial CC from device2")
|
||||
}
|
||||
|
||||
t.Log("Applying config change")
|
||||
|
||||
fn(wcfg)
|
||||
|
||||
if expectFirstClosed != fc1.closed {
|
||||
t.Errorf("first connection state mismatch: %t (expected) != %t", expectFirstClosed, fc1.closed)
|
||||
timeout := time.NewTimer(time.Second)
|
||||
if expectFirst {
|
||||
select {
|
||||
case <-cc1:
|
||||
case <-timeout.C:
|
||||
t.Errorf("timed out before receiving cluste rconfig for first device")
|
||||
}
|
||||
}
|
||||
|
||||
if expectSecondClosed != fc2.closed {
|
||||
t.Errorf("second connection state mismatch: %t (expected) != %t", expectSecondClosed, fc2.closed)
|
||||
if expectSecond {
|
||||
select {
|
||||
case <-cc2:
|
||||
case <-timeout.C:
|
||||
t.Errorf("timed out before receiving cluste rconfig for second device")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user