MCPcopy
hub / github.com/syncthing/syncthing / testConfigChangeTriggersClusterConfigs

Function testConfigChangeTriggersClusterConfigs

lib/model/model_test.go:3654–3713  ·  view source on GitHub ↗
(t *testing.T, expectFirst, expectSecond bool, pre func(config.Wrapper), fn func(config.Wrapper))

Source from the content-addressed store, hash-verified

3652}
3653
3654func testConfigChangeTriggersClusterConfigs(t *testing.T, expectFirst, expectSecond bool, pre func(config.Wrapper), fn func(config.Wrapper)) {
3655 t.Helper()
3656 wcfg, _ := newDefaultCfgWrapper(t)
3657 m := setupModel(t, wcfg)
3658 defer cleanupModel(m)
3659
3660 setDevice(t, wcfg, newDeviceConfiguration(wcfg.DefaultDevice(), device2, "device2"))
3661
3662 if pre != nil {
3663 pre(wcfg)
3664 }
3665
3666 cc1 := make(chan struct{}, 1)
3667 cc2 := make(chan struct{}, 1)
3668 fc1 := newFakeConnection(device1, m)
3669 fc1.ClusterConfigCalls(func(_ *protocol.ClusterConfig, _ map[string]string) {
3670 cc1 <- struct{}{}
3671 })
3672 fc2 := newFakeConnection(device2, m)
3673 fc2.ClusterConfigCalls(func(_ *protocol.ClusterConfig, _ map[string]string) {
3674 cc2 <- struct{}{}
3675 })
3676 m.AddConnection(fc1, protocol.Hello{})
3677 m.AddConnection(fc2, protocol.Hello{})
3678 m.promoteConnections()
3679
3680 // Initial CCs
3681 initTimeout := time.NewTimer(time.Second)
3682 defer initTimeout.Stop()
3683 select {
3684 case <-cc1:
3685 case <-initTimeout.C:
3686 t.Fatal("timed out waiting for initial CC from device1")
3687 }
3688 select {
3689 case <-cc2:
3690 case <-initTimeout.C:
3691 t.Fatal("timed out waiting for initial CC from device2")
3692 }
3693
3694 t.Log("Applying config change")
3695
3696 fn(wcfg)
3697
3698 timeout := time.NewTimer(time.Second)
3699 if expectFirst {
3700 select {
3701 case <-cc1:
3702 case <-timeout.C:
3703 t.Errorf("timed out before receiving cluste rconfig for first device")
3704 }
3705 }
3706 if expectSecond {
3707 select {
3708 case <-cc2:
3709 case <-timeout.C:
3710 t.Errorf("timed out before receiving cluste rconfig for second device")
3711 }

Calls 14

newDefaultCfgWrapperFunction · 0.85
setupModelFunction · 0.85
cleanupModelFunction · 0.85
setDeviceFunction · 0.85
newFakeConnectionFunction · 0.85
HelperMethod · 0.80
promoteConnectionsMethod · 0.80
FatalMethod · 0.80
newDeviceConfigurationFunction · 0.70
DefaultDeviceMethod · 0.65
AddConnectionMethod · 0.65
LogMethod · 0.65

Tested by

no test coverage detected