From 1578e25537afdf9394b9fb8541c2717e53d4119e Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Thu, 25 Mar 2021 08:50:55 +0530 Subject: [PATCH] MM-34171: Fix racy test TestSentry (#17215) * MM-34171: Fix racy test TestSentry The NewServer call sets the global mlog Info variable. But before that, if we call UpdateConfig with the functional options, then the store.Set method will call mlog.Info before it could be set. To fix that, we prepare the updated config and pass that directly to NewServer to avoid having to call UpdateConfig. https://mattermost.atlassian.net/browse/MM-34171 ```release-note NONE ``` * disable watcher * Trying yet again Co-authored-by: Mattermod --- app/server_test.go | 54 ++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/app/server_test.go b/app/server_test.go index 17c678b004..b5582d7c0e 100644 --- a/app/server_test.go +++ b/app/server_test.go @@ -607,20 +607,19 @@ func TestSentry(t *testing.T) { require.NoError(t, err) SentryDSN = dsn.String() - s, err := NewServer(func(server *Server) error { - configStore, _ := config.NewFileStore("config.json", true) - store, _ := config.NewStoreFromBacking(configStore, nil, false) - server.configStore = store - server.UpdateConfig(func(cfg *model.Config) { - *cfg.ServiceSettings.ListenAddress = ":0" - *cfg.LogSettings.EnableSentry = false - *cfg.ServiceSettings.ConnectionSecurity = "TLS" - *cfg.ServiceSettings.TLSKeyFile = path.Join(testDir, "tls_test_key.pem") - *cfg.ServiceSettings.TLSCertFile = path.Join(testDir, "tls_test_cert.pem") - *cfg.LogSettings.EnableDiagnostics = true - }) - return nil - }) + configStore, _ := config.NewMemoryStore() + store, _ := config.NewStoreFromBacking(configStore, nil, false) + cfg := store.Get() + *cfg.ServiceSettings.ListenAddress = ":0" + *cfg.LogSettings.EnableSentry = false + *cfg.ServiceSettings.ConnectionSecurity = "TLS" + *cfg.ServiceSettings.TLSKeyFile = path.Join(testDir, "tls_test_key.pem") + *cfg.ServiceSettings.TLSCertFile = path.Join(testDir, "tls_test_cert.pem") + *cfg.LogSettings.EnableDiagnostics = true + + store.Set(cfg) + + s, err := NewServer(ConfigStore(store)) require.NoError(t, err) // Route for just panicing @@ -658,20 +657,19 @@ func TestSentry(t *testing.T) { require.NoError(t, err) SentryDSN = dsn.String() - s, err := NewServer(func(server *Server) error { - configStore, _ := config.NewFileStore("config.json", true) - store, _ := config.NewStoreFromBacking(configStore, nil, false) - server.configStore = store - server.UpdateConfig(func(cfg *model.Config) { - *cfg.ServiceSettings.ListenAddress = ":0" - *cfg.ServiceSettings.ConnectionSecurity = "TLS" - *cfg.ServiceSettings.TLSKeyFile = path.Join(testDir, "tls_test_key.pem") - *cfg.ServiceSettings.TLSCertFile = path.Join(testDir, "tls_test_cert.pem") - *cfg.LogSettings.EnableSentry = true - *cfg.LogSettings.EnableDiagnostics = true - }) - return nil - }) + configStore, _ := config.NewMemoryStore() + store, _ := config.NewStoreFromBacking(configStore, nil, false) + cfg := store.Get() + *cfg.ServiceSettings.ListenAddress = ":0" + *cfg.ServiceSettings.ConnectionSecurity = "TLS" + *cfg.ServiceSettings.TLSKeyFile = path.Join(testDir, "tls_test_key.pem") + *cfg.ServiceSettings.TLSCertFile = path.Join(testDir, "tls_test_cert.pem") + *cfg.LogSettings.EnableSentry = true + *cfg.LogSettings.EnableDiagnostics = true + + store.Set(cfg) + + s, err := NewServer(ConfigStore(store)) require.NoError(t, err) // Route for just panicing