From d83156027a36e4fcb7a4f3edf668cce9f700f590 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Fri, 15 Nov 2024 15:00:56 +0530 Subject: [PATCH] Fix race condition in the web package (#29288) Essentially applying the fix for https://github.com/mattermost/mattermost/pull/29214 to the web package. It seems like the app.StoreOverrideWithCache function was never used in this package. Just a small highlight of how much boilerplate is repeated in multiple packages ```release-note NONE ``` Co-authored-by: Mattermost Build --- server/channels/web/web_test.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/server/channels/web/web_test.go b/server/channels/web/web_test.go index cf41be9168..952fc63823 100644 --- a/server/channels/web/web_test.go +++ b/server/channels/web/web_test.go @@ -23,7 +23,6 @@ import ( "github.com/mattermost/mattermost/server/public/shared/mlog" "github.com/mattermost/mattermost/server/public/shared/request" "github.com/mattermost/mattermost/server/v8/channels/app" - "github.com/mattermost/mattermost/server/v8/channels/store/localcachelayer" "github.com/mattermost/mattermost/server/v8/channels/store/storetest/mocks" "github.com/mattermost/mattermost/server/v8/config" ) @@ -83,7 +82,12 @@ func setupTestHelper(tb testing.TB, includeCacheLayer bool, options []app.Option *newConfig.LogSettings.ConsoleLevel = mlog.LvlStdLog.Name memoryStore.Set(newConfig) options = append(options, app.ConfigStore(memoryStore)) - options = append(options, app.StoreOverride(mainHelper.Store)) + if includeCacheLayer { + // Adds the cache layer to the test store + options = append(options, app.StoreOverrideWithCache(mainHelper.Store)) + } else { + options = append(options, app.StoreOverride(mainHelper.Store)) + } testLogger, _ := mlog.NewLogger() logCfg, _ := config.MloggerConfigFromLoggerConfig(&newConfig.LogSettings, nil, config.GetLogFileLocation) @@ -98,15 +102,6 @@ func setupTestHelper(tb testing.TB, includeCacheLayer bool, options []app.Option if err != nil { panic(err) } - if includeCacheLayer { - // Adds the cache layer to the test store - var st localcachelayer.LocalCacheStore - st, err = localcachelayer.NewLocalCacheLayer(s.Store(), s.GetMetrics(), s.Platform().Cluster(), s.Platform().CacheProvider(), testLogger) - if err != nil { - panic(err) - } - s.SetStore(st) - } a := app.New(app.ServerConnector(s.Channels())) prevListenAddress := *s.Config().ServiceSettings.ListenAddress