config sync test passing

This commit is contained in:
Gareth
2025-11-01 13:55:52 -07:00
parent eae80020cd
commit cd76086c15
2 changed files with 12 additions and 3 deletions
+6 -1
View File
@@ -26,6 +26,7 @@ import (
"github.com/garethgeorge/backrest/internal/testutil"
"github.com/google/go-cmp/cmp"
"github.com/ncruces/go-sqlite3/vfs/memdb"
"go.uber.org/zap"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
"google.golang.org/protobuf/encoding/protojson"
@@ -172,6 +173,7 @@ func TestSyncConfigChange(t *testing.T) {
peerHostConfig := &v1.Config{
Version: migrations.CurrentVersion,
Modno: 0,
Instance: defaultHostID,
Repos: []*v1.Repo{
{
@@ -247,13 +249,16 @@ func TestSyncConfigChange(t *testing.T) {
},
})
hostConfigChanged := proto.Clone(peerHostConfig).(*v1.Config)
hostConfigChanged.Repos[0].Env = []string{"SOME_ENV=VALUE"}
hostConfigChanged.Repos[1].Env = []string{"SOME_ENV=VALUE"}
hostConfigChanged.Modno += 1
zap.S().Infof("updating host config to: %s", protojson.Format(hostConfigChanged))
peerHost.configMgr.Update(hostConfigChanged)
tryConnect(t, ctx, peerClient, peerClientConfig.Multihost.KnownHosts[0])
tryExpectConfigFromHost(t, ctx, peerClient, peerClientConfig.Multihost.KnownHosts[0], &v1sync.RemoteConfig{
Version: migrations.CurrentVersion,
Modno: 1,
Repos: []*v1.Repo{
{
Id: defaultRepoID,
+6 -2
View File
@@ -85,16 +85,20 @@ func (m *SyncManager) RunSync(ctx context.Context) {
configWatchCh := m.configMgr.OnChange.Subscribe()
defer m.configMgr.OnChange.Unsubscribe(configWatchCh)
defer func() {
zap.L().Info("syncmanager exited")
}()
runSyncWithNewConfig := func() {
m.mu.Lock()
defer m.mu.Unlock()
// TODO: rather than cancel the top level context, something clever e.g. diffing the set of peers could be done here.
if cancelLastSync != nil {
cancelLastSync()
zap.L().Info("syncmanager applying new config, waiting for existing sync goroutines to exit")
syncWg.Wait()
} else {
zap.L().Info("syncmanager applying new config, starting sync goroutines")
}
syncCtx, cancel := context.WithCancel(ctx)
cancelLastSync = cancel
@@ -129,7 +133,7 @@ func (m *SyncManager) RunSync(ctx context.Context) {
return
}
zap.S().Infof("syncmanager applying new config, starting sync with identity %v, spawning goroutines for %d known peers",
zap.S().Infof("sync using identity %v, spawning goroutines for %d known peers",
config.Multihost.GetIdentity().GetKeyid(), len(config.Multihost.GetKnownHosts()))
for _, knownHostPeer := range config.Multihost.KnownHosts {
if knownHostPeer.InstanceId == "" {