diff --git a/.github/codecov.yml b/.github/codecov.yml new file mode 100644 index 0000000000..d41023ecea --- /dev/null +++ b/.github/codecov.yml @@ -0,0 +1,13 @@ +comment: + layout: "diff, flags, files" + behavior: default + require_changes: false # if true: only post the comment if coverage changes +coverage: + status: + changes: false + patch: false + project: + default: + threshold: 1.0 +ignore: + - ^store/storetest.* diff --git a/.github/workflows/server-ci-template.yml b/.github/workflows/server-ci-template.yml index e4e5dcc287..15e6ce8281 100644 --- a/.github/workflows/server-ci-template.yml +++ b/.github/workflows/server-ci-template.yml @@ -264,6 +264,18 @@ jobs: datasource: mmuser:mostest@tcp(mysql:3306)/mattermost_test?charset=utf8mb4&multiStatements=true&maxAllowedPacket=4194304 drivername: mysql logsartifact: mysql-server-test-logs + test-coverage: + name: Generate Test Coverage + needs: check-mattermost-vet + uses: ./.github/workflows/server-test-template.yml + secrets: inherit + with: + name: Generate Test Coverage + datasource: postgres://mmuser:mostest@postgres:5432/mattermost_test?sslmode=disable&connect_timeout=10 + drivername: postgres + logsartifact: coverage-server-test-logs + fullyparallel: true + enablecoverage: true test-mmctl: name: Run mmctl tests needs: check-mattermost-vet diff --git a/.github/workflows/server-test-template.yml b/.github/workflows/server-test-template.yml index 11a956a36b..710c414bf2 100644 --- a/.github/workflows/server-test-template.yml +++ b/.github/workflows/server-test-template.yml @@ -14,11 +14,20 @@ on: logsartifact: required: true type: string + fullyparallel: + required: false + type: boolean + default: false + enablecoverage: + required: false + type: boolean + default: false jobs: test: name: ${{ inputs.name }} runs-on: ubuntu-latest-8-cores + continue-on-error: ${{ inputs.fullyparallel }} # Used to avoid blocking PRs in case of flakiness env: COMPOSE_PROJECT_NAME: ghactions steps: @@ -60,12 +69,20 @@ jobs: --env MM_SQLSETTINGS_DATASOURCE="${{ inputs.datasource }}" \ --env TEST_DATABASE_MYSQL_DSN="${{ inputs.datasource }}" \ --env TEST_DATABASE_POSTGRESQL_DSN="${{ inputs.datasource }}" \ + --env ENABLE_FULLY_PARALLEL_TESTS="${{ inputs.fullyparallel }}" \ + --env ENABLE_COVERAGE="${{ inputs.enablecoverage }}" \ -v $(go env GOCACHE):/go/cache \ -e GOCACHE=/go/cache \ -v $PWD:/mattermost \ -w /mattermost/server \ $BUILD_IMAGE \ make test-server$RACE_MODE BUILD_NUMBER=$GITHUB_HEAD_REF-$GITHUB_RUN_ID + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + disable_search: true + files: server/cover.out - name: Stop docker compose run: | cd server/build @@ -78,5 +95,6 @@ jobs: path: | server/gotestsum.json server/report.xml + server/cover.out server/test-name server/pr-number diff --git a/server/.codecov.yml b/server/.codecov.yml deleted file mode 100644 index 4eb6df603b..0000000000 --- a/server/.codecov.yml +++ /dev/null @@ -1,7 +0,0 @@ -comment: - layout: "diff, flags, files" - require_changes: true - branches: "!release*" - -ignore: - - store/storetest diff --git a/server/Makefile b/server/Makefile index 3897431ed4..8df6ed1f05 100644 --- a/server/Makefile +++ b/server/Makefile @@ -41,6 +41,12 @@ GOTESTSUM_FORMAT ?= testname GOTESTSUM_JUNITFILE ?= report.xml GOTESTSUM_JSONFILE ?= gotestsum.json +# Go test coverage +ENABLE_COVERAGE ?= false +ifeq ($(ENABLE_COVERAGE),true) +COVERAGE_FLAG = -coverprofile=cover.out -covermode=atomic +endif + # mmctl MMCTL_BUILD_TAGS = MMCTL_TESTFLAGS ?= -timeout 30m @@ -451,7 +457,7 @@ test-server: export GOTESTSUM_FORMAT := $(GOTESTSUM_FORMAT) test-server: export GOTESTSUM_JUNITFILE := $(GOTESTSUM_JUNITFILE) test-server: export GOTESTSUM_JSONFILE := $(GOTESTSUM_JSONFILE) test-server: test-server-pre - $(GOBIN)/gotestsum --rerun-fails=3 --packages="$(TE_PACKAGES) $(EE_PACKAGES)" -- $(GOFLAGS) -timeout=90m + $(GOBIN)/gotestsum --rerun-fails=3 --packages="$(TE_PACKAGES) $(EE_PACKAGES)" -- $(GOFLAGS) -timeout=90m $(COVERAGE_FLAG) ifneq ($(IS_CI),true) ifneq ($(MM_NO_DOCKER),true) ifneq ($(TEMP_DOCKER_SERVICES),) diff --git a/server/build/docker/postgres.conf b/server/build/docker/postgres.conf index bbd1153e04..ee7ae24f62 100644 --- a/server/build/docker/postgres.conf +++ b/server/build/docker/postgres.conf @@ -1,4 +1,4 @@ -max_connections = 300 +max_connections = 500 listen_addresses = '*' fsync = off full_page_writes = off diff --git a/server/build/dotenv/test.env b/server/build/dotenv/test.env index 9b4eb175fd..0c6f77bcb4 100644 --- a/server/build/dotenv/test.env +++ b/server/build/dotenv/test.env @@ -11,5 +11,4 @@ CI_INBUCKET_SMTP_PORT=10025 CI_LDAP_HOST=openldap IS_CI=true MM_EMAILSETTINGS_SMTPSERVER=inbucket -MM_EMAILSETTINGS_SMTPPORT=10025 MM_ELASTICSEARCHSETTINGS_CONNECTIONURL=http://elasticsearch:9200 diff --git a/server/channels/api4/apitestlib.go b/server/channels/api4/apitestlib.go index 54db2ee006..a13196a6db 100644 --- a/server/channels/api4/apitestlib.go +++ b/server/channels/api4/apitestlib.go @@ -41,6 +41,7 @@ type TestHelper struct { App *app.App Server *app.Server ConfigStore *config.Store + Store store.Store Context *request.Context Client *model.Client4 @@ -69,8 +70,6 @@ type TestHelper struct { LogBuffer *mlog.Buffer TestLogger *mlog.Logger - - workspace string } var mainHelper *testlib.MainHelper @@ -79,7 +78,7 @@ func SetMainHelper(mh *testlib.MainHelper) { mainHelper = mh } -func setupTestHelper(tb testing.TB, dbStore store.Store, searchEngine *searchengine.Broker, enterprise bool, includeCache bool, +func setupTestHelper(tb testing.TB, dbStore store.Store, sqlSettings *model.SqlSettings, searchEngine *searchengine.Broker, enterprise bool, includeCache bool, updateConfig func(*model.Config), options []app.Option, ) *TestHelper { tempWorkspace, err := os.MkdirTemp("", "apptest") @@ -89,9 +88,11 @@ func setupTestHelper(tb testing.TB, dbStore store.Store, searchEngine *searcheng require.NoError(tb, err, "failed to initialize memory store") memoryConfig := &model.Config{ - SqlSettings: *mainHelper.GetSQLSettings(), + SqlSettings: model.SafeDereference(sqlSettings), } memoryConfig.SetDefaults() + *memoryConfig.ServiceSettings.LicenseFileLocation = filepath.Join(tempWorkspace, "license.json") + *memoryConfig.FileSettings.Directory = filepath.Join(tempWorkspace, "data") *memoryConfig.PluginSettings.Directory = filepath.Join(tempWorkspace, "plugins") *memoryConfig.PluginSettings.ClientDirectory = filepath.Join(tempWorkspace, "webapp") *memoryConfig.FileSettings.Directory = filepath.Join(tempWorkspace, "data") @@ -99,11 +100,12 @@ func setupTestHelper(tb testing.TB, dbStore store.Store, searchEngine *searcheng *memoryConfig.ServiceSettings.LocalModeSocketLocation = filepath.Join(tempWorkspace, "mattermost_local.sock") *memoryConfig.LogSettings.EnableSentry = false // disable error reporting during tests *memoryConfig.LogSettings.ConsoleLevel = mlog.LvlStdLog.Name + *memoryConfig.LogSettings.FileLocation = filepath.Join(tempWorkspace, "logs", "mattermost.log") *memoryConfig.AnnouncementSettings.AdminNoticesEnabled = false *memoryConfig.AnnouncementSettings.UserNoticesEnabled = false *memoryConfig.PluginSettings.AutomaticPrepackagedPlugins = false // Enabling Redis with Postgres. - if *memoryConfig.SqlSettings.DriverName == model.DatabaseDriverPostgres { + if *memoryConfig.SqlSettings.DriverName == model.DatabaseDriverPostgres && !mainHelper.Options.RunParallel { *memoryConfig.CacheSettings.CacheType = model.CacheTypeRedis redisHost := "localhost" if os.Getenv("IS_CI") == "true" { @@ -156,7 +158,7 @@ func setupTestHelper(tb testing.TB, dbStore store.Store, searchEngine *searcheng IncludeCacheLayer: includeCache, TestLogger: testLogger, LogBuffer: buffer, - workspace: tempWorkspace, + Store: dbStore, } if s.Platform().SearchEngine != nil && s.Platform().SearchEngine.BleveEngine != nil && searchEngine != nil { @@ -190,6 +192,14 @@ func setupTestHelper(tb testing.TB, dbStore store.Store, searchEngine *searcheng *cfg.ServiceSettings.ListenAddress = "localhost:0" }) + + // Support updating feature flags without resorting to os.Setenv which + // isn't concurrently safe. + if updateConfig != nil { + configStore.SetReadOnlyFF(false) + th.App.UpdateConfig(updateConfig) + } + err = th.Server.Start() require.NoError(tb, err) @@ -203,7 +213,6 @@ func setupTestHelper(tb testing.TB, dbStore store.Store, searchEngine *searcheng th.SystemManagerClient = th.CreateClient() // Verify handling of the supported true/false values by randomizing on each run. - rand.Seed(time.Now().UTC().UnixNano()) trueValues := []string{"1", "t", "T", "TRUE", "true", "True"} falseValues := []string{"0", "f", "F", "FALSE", "false", "False"} trueString := trueValues[rand.Intn(len(trueValues))] @@ -231,6 +240,27 @@ func getLicense(enterprise bool, cfg *model.Config) *model.License { return nil } +func setupStores(tb testing.TB) (store.Store, *model.SqlSettings, *searchengine.Broker) { + var dbStore store.Store + var dbSettings *model.SqlSettings + var searchEngine *searchengine.Broker + if mainHelper.Options.RunParallel { + dbStore, _, dbSettings, searchEngine = mainHelper.GetNewStores(tb) + tb.Cleanup(func() { + dbStore.Close() + }) + } else { + dbStore = mainHelper.GetStore() + dbStore.DropAllTables() + dbStore.MarkSystemRanUnitTests() + mainHelper.PreloadMigrations() + searchEngine = mainHelper.GetSearchEngine() + dbSettings = mainHelper.Settings + } + + return dbStore, dbSettings, searchEngine +} + func SetupEnterprise(tb testing.TB, options ...app.Option) *TestHelper { if testing.Short() { tb.SkipNow() @@ -240,13 +270,10 @@ func SetupEnterprise(tb testing.TB, options ...app.Option) *TestHelper { tb.SkipNow() } - dbStore := mainHelper.GetStore() - dbStore.DropAllTables() - dbStore.MarkSystemRanUnitTests() - mainHelper.PreloadMigrations() - searchEngine := mainHelper.GetSearchEngine() - th := setupTestHelper(tb, dbStore, searchEngine, true, true, nil, options) + dbStore, dbSettings, searchEngine := setupStores(tb) + th := setupTestHelper(tb, dbStore, dbSettings, searchEngine, true, true, nil, options) th.InitLogin(tb) + return th } @@ -259,13 +286,10 @@ func Setup(tb testing.TB) *TestHelper { tb.SkipNow() } - dbStore := mainHelper.GetStore() - dbStore.DropAllTables() - dbStore.MarkSystemRanUnitTests() - mainHelper.PreloadMigrations() - searchEngine := mainHelper.GetSearchEngine() - th := setupTestHelper(tb, dbStore, searchEngine, false, true, nil, nil) + dbStore, dbSettings, searchEngine := setupStores(tb) + th := setupTestHelper(tb, dbStore, dbSettings, searchEngine, false, true, nil, nil) th.InitLogin(tb) + return th } @@ -278,14 +302,11 @@ func SetupAndApplyConfigBeforeLogin(tb testing.TB, updateConfig func(cfg *model. tb.SkipNow() } - dbStore := mainHelper.GetStore() - dbStore.DropAllTables() - dbStore.MarkSystemRanUnitTests() - mainHelper.PreloadMigrations() - searchEngine := mainHelper.GetSearchEngine() - th := setupTestHelper(tb, dbStore, searchEngine, false, true, nil, nil) + dbStore, dbSettings, searchEngine := setupStores(tb) + th := setupTestHelper(tb, dbStore, dbSettings, searchEngine, false, true, nil, nil) th.App.UpdateConfig(updateConfig) th.InitLogin(tb) + return th } @@ -298,18 +319,15 @@ func SetupConfig(tb testing.TB, updateConfig func(cfg *model.Config)) *TestHelpe tb.SkipNow() } - dbStore := mainHelper.GetStore() - dbStore.DropAllTables() - dbStore.MarkSystemRanUnitTests() - mainHelper.PreloadMigrations() - searchEngine := mainHelper.GetSearchEngine() - th := setupTestHelper(tb, dbStore, searchEngine, false, true, updateConfig, nil) + dbStore, dbSettings, searchEngine := setupStores(tb) + th := setupTestHelper(tb, dbStore, dbSettings, searchEngine, false, true, updateConfig, nil) th.InitLogin(tb) + return th } func SetupConfigWithStoreMock(tb testing.TB, updateConfig func(cfg *model.Config)) *TestHelper { - th := setupTestHelper(tb, testlib.GetMockStoreForSetupFunctions(), nil, false, false, updateConfig, nil) + th := setupTestHelper(tb, testlib.GetMockStoreForSetupFunctions(), nil, nil, false, false, updateConfig, nil) statusMock := mocks.StatusStore{} statusMock.On("UpdateExpiredDNDStatuses").Return([]*model.Status{}, nil) statusMock.On("Get", "user1").Return(&model.Status{UserId: "user1", Status: model.StatusOnline}, nil) @@ -323,7 +341,7 @@ func SetupConfigWithStoreMock(tb testing.TB, updateConfig func(cfg *model.Config } func SetupWithStoreMock(tb testing.TB) *TestHelper { - th := setupTestHelper(tb, testlib.GetMockStoreForSetupFunctions(), nil, false, false, nil, nil) + th := setupTestHelper(tb, testlib.GetMockStoreForSetupFunctions(), nil, nil, false, false, nil, nil) statusMock := mocks.StatusStore{} statusMock.On("UpdateExpiredDNDStatuses").Return([]*model.Status{}, nil) statusMock.On("Get", "user1").Return(&model.Status{UserId: "user1", Status: model.StatusOnline}, nil) @@ -337,7 +355,7 @@ func SetupWithStoreMock(tb testing.TB) *TestHelper { } func SetupEnterpriseWithStoreMock(tb testing.TB, options ...app.Option) *TestHelper { - th := setupTestHelper(tb, testlib.GetMockStoreForSetupFunctions(), nil, true, false, nil, options) + th := setupTestHelper(tb, testlib.GetMockStoreForSetupFunctions(), nil, nil, true, false, nil, options) statusMock := mocks.StatusStore{} statusMock.On("UpdateExpiredDNDStatuses").Return([]*model.Status{}, nil) statusMock.On("Get", "user1").Return(&model.Status{UserId: "user1", Status: model.StatusOnline}, nil) @@ -359,13 +377,10 @@ func SetupWithServerOptions(tb testing.TB, options []app.Option) *TestHelper { tb.SkipNow() } - dbStore := mainHelper.GetStore() - dbStore.DropAllTables() - dbStore.MarkSystemRanUnitTests() - mainHelper.PreloadMigrations() - searchEngine := mainHelper.GetSearchEngine() - th := setupTestHelper(tb, dbStore, searchEngine, false, true, nil, options) + dbStore, dbSettings, searchEngine := setupStores(tb) + th := setupTestHelper(tb, dbStore, dbSettings, searchEngine, false, true, nil, options) th.InitLogin(tb) + return th } @@ -378,13 +393,10 @@ func SetupEnterpriseWithServerOptions(tb testing.TB, options []app.Option) *Test tb.SkipNow() } - dbStore := mainHelper.GetStore() - dbStore.DropAllTables() - dbStore.MarkSystemRanUnitTests() - mainHelper.PreloadMigrations() - searchEngine := mainHelper.GetSearchEngine() - th := setupTestHelper(tb, dbStore, searchEngine, true, true, nil, options) + dbStore, dbSettings, searchEngine := setupStores(tb) + th := setupTestHelper(tb, dbStore, dbSettings, searchEngine, true, true, nil, options) th.InitLogin(tb) + return th } @@ -413,8 +425,8 @@ func (th *TestHelper) TearDown() { th.ShutdownApp() // Cleanup the workspace - if th.workspace != "" { - err := os.RemoveAll(th.workspace) + if th.tempWorkspace != "" { + err := os.RemoveAll(th.tempWorkspace) if err != nil { panic(err) } @@ -444,29 +456,48 @@ func (th *TestHelper) InitLogin(tb testing.TB) *TestHelper { // create users once and cache them because password hashing is slow initBasicOnce.Do(func() { + var err *model.AppError + th.SystemAdminUser = th.CreateUser() th.App.UpdateUserRoles(th.Context, th.SystemAdminUser.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false) - th.SystemAdminUser, _ = th.App.GetUser(th.SystemAdminUser.Id) + th.SystemAdminUser, err = th.App.GetUser(th.SystemAdminUser.Id) + if err != nil { + panic(err) + } userCache.SystemAdminUser = th.SystemAdminUser.DeepCopy() th.SystemManagerUser = th.CreateUser() th.App.UpdateUserRoles(th.Context, th.SystemManagerUser.Id, model.SystemUserRoleId+" "+model.SystemManagerRoleId, false) - th.SystemManagerUser, _ = th.App.GetUser(th.SystemManagerUser.Id) + th.SystemManagerUser, err = th.App.GetUser(th.SystemManagerUser.Id) + if err != nil { + panic(err) + } userCache.SystemManagerUser = th.SystemManagerUser.DeepCopy() th.TeamAdminUser = th.CreateUser() th.App.UpdateUserRoles(th.Context, th.TeamAdminUser.Id, model.SystemUserRoleId, false) - th.TeamAdminUser, _ = th.App.GetUser(th.TeamAdminUser.Id) + th.TeamAdminUser, err = th.App.GetUser(th.TeamAdminUser.Id) + if err != nil { + panic(err) + } userCache.TeamAdminUser = th.TeamAdminUser.DeepCopy() th.BasicUser = th.CreateUser() - th.BasicUser, _ = th.App.GetUser(th.BasicUser.Id) + th.BasicUser, err = th.App.GetUser(th.BasicUser.Id) + if err != nil { + panic(err) + } + userCache.BasicUser = th.BasicUser.DeepCopy() th.BasicUser2 = th.CreateUser() - th.BasicUser2, _ = th.App.GetUser(th.BasicUser2.Id) + th.BasicUser2, err = th.App.GetUser(th.BasicUser2.Id) + if err != nil { + panic(err) + } userCache.BasicUser2 = th.BasicUser2.DeepCopy() }) + // restore cached users th.SystemAdminUser = userCache.SystemAdminUser.DeepCopy() th.SystemManagerUser = userCache.SystemManagerUser.DeepCopy() @@ -474,8 +505,7 @@ func (th *TestHelper) InitLogin(tb testing.TB) *TestHelper { th.BasicUser = userCache.BasicUser.DeepCopy() th.BasicUser2 = userCache.BasicUser2.DeepCopy() - users := []*model.User{th.SystemAdminUser, th.TeamAdminUser, th.BasicUser, th.BasicUser2, th.SystemManagerUser} - mainHelper.GetSQLStore().User().InsertUsers(users) + th.Store.User().InsertUsers([]*model.User{th.SystemAdminUser, th.TeamAdminUser, th.BasicUser, th.BasicUser2, th.SystemManagerUser}) // restore non hashed password for login th.SystemAdminUser.Password = "Pa$$word11" @@ -494,7 +524,9 @@ func (th *TestHelper) InitLogin(tb testing.TB) *TestHelper { th.LoginTeamAdmin() wg.Done() }() + wg.Wait() + return th } @@ -1418,3 +1450,7 @@ func (th *TestHelper) SetupScheme(scope string) *model.Scheme { } return scheme } + +func (th *TestHelper) Parallel(t *testing.T) { + mainHelper.Parallel(t) +} diff --git a/server/channels/api4/bleve_test.go b/server/channels/api4/bleve_test.go index 672a6c549b..4e6866ff2f 100644 --- a/server/channels/api4/bleve_test.go +++ b/server/channels/api4/bleve_test.go @@ -13,6 +13,7 @@ import ( ) func TestBlevePurgeIndexes(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/api4/bot_test.go b/server/channels/api4/bot_test.go index 54e42bfe16..d42d48c791 100644 --- a/server/channels/api4/bot_test.go +++ b/server/channels/api4/bot_test.go @@ -17,6 +17,7 @@ import ( ) func TestCreateBot(t *testing.T) { + mainHelper.Parallel(t) t.Run("create bot without permissions", func(t *testing.T) { th := Setup(t) defer th.TearDown() @@ -168,6 +169,7 @@ func TestCreateBot(t *testing.T) { } func TestPatchBot(t *testing.T) { + mainHelper.Parallel(t) t.Run("patch non-existent bot", func(t *testing.T) { th := Setup(t) defer th.TearDown() @@ -591,6 +593,7 @@ func TestPatchBot(t *testing.T) { } func TestGetBot(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -772,6 +775,7 @@ func TestGetBot(t *testing.T) { } func TestGetBots(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic().DeleteBots() defer th.TearDown() @@ -1080,6 +1084,7 @@ func TestGetBots(t *testing.T) { } func TestDisableBot(t *testing.T) { + mainHelper.Parallel(t) t.Run("disable non-existent bot", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -1199,7 +1204,9 @@ func TestDisableBot(t *testing.T) { }) }) } + func TestEnableBot(t *testing.T) { + mainHelper.Parallel(t) t.Run("enable non-existent bot", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -1333,6 +1340,7 @@ func TestEnableBot(t *testing.T) { } func TestAssignBot(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1513,6 +1521,7 @@ func TestAssignBot(t *testing.T) { } func TestConvertBotToUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/api4/brand_test.go b/server/channels/api4/brand_test.go index e651cbd518..5f51e54940 100644 --- a/server/channels/api4/brand_test.go +++ b/server/channels/api4/brand_test.go @@ -15,6 +15,7 @@ import ( ) func TestGetBrandImage(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -35,6 +36,7 @@ func TestGetBrandImage(t *testing.T) { } func TestUploadBrandImage(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -136,6 +138,7 @@ func TestUploadBrandImageTwice(t *testing.T) { } func TestDeleteBrandImage(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/api4/channel_bookmark_test.go b/server/channels/api4/channel_bookmark_test.go index b7f574f281..271adbb99c 100644 --- a/server/channels/api4/channel_bookmark_test.go +++ b/server/channels/api4/channel_bookmark_test.go @@ -7,7 +7,6 @@ import ( "context" "encoding/json" "net/http" - "os" "testing" "time" @@ -16,9 +15,7 @@ import ( ) func TestCreateChannelBookmark(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_ChannelBookmarks", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_ChannelBookmarks") - + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() err := th.App.SetPhase2PermissionsMigrationStatus(true) @@ -280,9 +277,7 @@ func TestCreateChannelBookmark(t *testing.T) { } func TestEditChannelBookmark(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_ChannelBookmarks", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_ChannelBookmarks") - + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() err := th.App.SetPhase2PermissionsMigrationStatus(true) @@ -690,9 +685,7 @@ func TestEditChannelBookmark(t *testing.T) { } func TestUpdateChannelBookmarkSortOrder(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_ChannelBookmarks", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_ChannelBookmarks") - + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() err := th.App.SetPhase2PermissionsMigrationStatus(true) @@ -1102,9 +1095,7 @@ func TestUpdateChannelBookmarkSortOrder(t *testing.T) { } func TestDeleteChannelBookmark(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_ChannelBookmarks", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_ChannelBookmarks") - + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() err := th.App.SetPhase2PermissionsMigrationStatus(true) @@ -1461,9 +1452,7 @@ func TestDeleteChannelBookmark(t *testing.T) { } func TestListChannelBookmarksForChannel(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_ChannelBookmarks", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_ChannelBookmarks") - + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() err := th.App.SetPhase2PermissionsMigrationStatus(true) diff --git a/server/channels/api4/channel_category_test.go b/server/channels/api4/channel_category_test.go index 5e94d6d892..4d72881aa1 100644 --- a/server/channels/api4/channel_category_test.go +++ b/server/channels/api4/channel_category_test.go @@ -18,6 +18,7 @@ import ( ) func TestCreateCategoryForTeamForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -164,6 +165,7 @@ func TestCreateCategoryForTeamForUser(t *testing.T) { } func TestUpdateCategoryForTeamForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -451,6 +453,7 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) { } func TestUpdateCategoriesForTeamForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -548,6 +551,7 @@ func TestUpdateCategoriesForTeamForUser(t *testing.T) { } func TestGetCategoriesForTeamForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -600,6 +604,7 @@ func TestGetCategoriesForTeamForUser(t *testing.T) { } func TestGetCategoryOrderForTeamForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -658,6 +663,7 @@ func TestGetCategoryOrderForTeamForUser(t *testing.T) { } func TestUpdateCategoryOrderForTeamForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -776,6 +782,7 @@ func TestUpdateCategoryOrderForTeamForUser(t *testing.T) { } func TestGetCategoryForTeamForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -874,6 +881,7 @@ func TestGetCategoryForTeamForUser(t *testing.T) { } func TestValidateSidebarCategory(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -996,6 +1004,7 @@ func TestValidateSidebarCategory(t *testing.T) { } func TestValidateSidebarCategoryChannels(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1081,6 +1090,7 @@ func TestValidateSidebarCategoryChannels(t *testing.T) { } func TestDeleteCategoryForTeamForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() t.Run("should move channels to default categories when custom category is deleted", func(t *testing.T) { diff --git a/server/channels/api4/channel_test.go b/server/channels/api4/channel_test.go index 54c71b9c69..fce6792ac4 100644 --- a/server/channels/api4/channel_test.go +++ b/server/channels/api4/channel_test.go @@ -27,6 +27,7 @@ import ( ) func TestCreateChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -203,6 +204,7 @@ func TestCreateChannel(t *testing.T) { } func TestUpdateChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -378,6 +380,7 @@ func TestUpdateChannel(t *testing.T) { } func TestPatchChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1164,6 +1167,7 @@ func TestCanEditChannelBanner(t *testing.T) { } func TestChannelUnicodeNames(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1223,6 +1227,7 @@ func TestChannelUnicodeNames(t *testing.T) { } func TestCreateDirectChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1285,6 +1290,7 @@ func TestCreateDirectChannel(t *testing.T) { } func TestCreateDirectChannelAsGuest(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1333,6 +1339,7 @@ func TestCreateDirectChannelAsGuest(t *testing.T) { } func TestDeleteDirectChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1349,6 +1356,7 @@ func TestDeleteDirectChannel(t *testing.T) { } func TestCreateGroupChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1411,6 +1419,7 @@ func TestCreateGroupChannel(t *testing.T) { } func TestCreateGroupChannelAsGuest(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1478,6 +1487,7 @@ func TestCreateGroupChannelAsGuest(t *testing.T) { } func TestDeleteGroupChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() user := th.BasicUser @@ -1497,6 +1507,7 @@ func TestDeleteGroupChannel(t *testing.T) { } func TestGetChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1547,6 +1558,7 @@ func TestGetChannel(t *testing.T) { } func TestGetDeletedChannelsForTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1622,6 +1634,7 @@ func TestGetDeletedChannelsForTeam(t *testing.T) { } func TestGetPrivateChannelsForTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() team := th.BasicTeam @@ -1660,6 +1673,7 @@ func TestGetPrivateChannelsForTeam(t *testing.T) { } func TestGetPublicChannelsForTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1736,6 +1750,7 @@ func TestGetPublicChannelsForTeam(t *testing.T) { } func TestGetPublicChannelsByIdsForTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1793,6 +1808,7 @@ func TestGetPublicChannelsByIdsForTeam(t *testing.T) { } func TestGetChannelsForTeamForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1873,6 +1889,7 @@ func TestGetChannelsForTeamForUser(t *testing.T) { } func TestGetChannelsForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1925,6 +1942,7 @@ func TestGetChannelsForUser(t *testing.T) { } func TestGetAllChannels(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() th.LoginSystemManager() defer th.TearDown() @@ -2086,6 +2104,7 @@ func TestGetAllChannels(t *testing.T) { } func TestGetAllChannelsWithCount(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -2118,6 +2137,7 @@ func TestGetAllChannelsWithCount(t *testing.T) { } func TestSearchChannels(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -2251,6 +2271,7 @@ func TestSearchChannels(t *testing.T) { } func TestSearchArchivedChannels(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -2341,6 +2362,7 @@ func TestSearchArchivedChannels(t *testing.T) { } func TestSearchAllChannels(t *testing.T) { + mainHelper.Parallel(t) th := setupForSharedChannels(t).InitBasic() th.LoginSystemManager() defer th.TearDown() @@ -2631,6 +2653,7 @@ func TestSearchAllChannels(t *testing.T) { } func TestSearchAllChannelsPaged(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -2650,6 +2673,7 @@ func TestSearchAllChannelsPaged(t *testing.T) { } func TestSearchGroupChannels(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -2718,6 +2742,7 @@ func TestSearchGroupChannels(t *testing.T) { } func TestDeleteChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() c := th.Client @@ -2806,6 +2831,7 @@ func TestDeleteChannel(t *testing.T) { } func TestDeleteChannel2(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -2885,6 +2911,7 @@ func TestDeleteChannel2(t *testing.T) { } func TestPermanentDeleteChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2923,6 +2950,7 @@ func TestPermanentDeleteChannel(t *testing.T) { } func TestUpdateChannelPrivacy(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3017,6 +3045,7 @@ func TestUpdateChannelPrivacy(t *testing.T) { } func TestRestoreChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3075,6 +3104,7 @@ func TestRestoreChannel(t *testing.T) { } func TestGetChannelByName(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3140,6 +3170,7 @@ func TestGetChannelByName(t *testing.T) { } func TestGetChannelByNameForTeamName(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3201,6 +3232,7 @@ func TestGetChannelByNameForTeamName(t *testing.T) { } func TestGetChannelMembers(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() th.TestForAllClients(t, func(t *testing.T, client *model.Client4) { @@ -3249,6 +3281,7 @@ func TestGetChannelMembers(t *testing.T) { } func TestGetChannelMembersByIds(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3291,6 +3324,7 @@ func TestGetChannelMembersByIds(t *testing.T) { } func TestGetChannelMember(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() c := th.Client @@ -3340,6 +3374,7 @@ func TestGetChannelMember(t *testing.T) { } func TestGetChannelMembersForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3388,6 +3423,7 @@ func TestGetChannelMembersForUser(t *testing.T) { } func TestViewChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3466,6 +3502,7 @@ func TestViewChannel(t *testing.T) { } func TestReadMultipleChannels(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3545,6 +3582,7 @@ func TestReadMultipleChannels(t *testing.T) { } func TestGetChannelUnread(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3593,6 +3631,7 @@ func TestGetChannelUnread(t *testing.T) { } func TestGetChannelStats(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3651,6 +3690,7 @@ func TestGetChannelStats(t *testing.T) { } func TestGetPinnedPosts(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3687,6 +3727,7 @@ func TestGetPinnedPosts(t *testing.T) { } func TestUpdateChannelRoles(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3766,6 +3807,7 @@ func TestUpdateChannelRoles(t *testing.T) { } func TestUpdateChannelMemberSchemeRoles(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3920,6 +3962,7 @@ func TestUpdateChannelMemberSchemeRoles(t *testing.T) { } func TestUpdateChannelNotifyProps(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3965,6 +4008,7 @@ func TestUpdateChannelNotifyProps(t *testing.T) { } func TestAddChannelMember(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -4183,6 +4227,7 @@ func TestAddChannelMember(t *testing.T) { } func TestAddChannelMembers(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -4213,6 +4258,7 @@ func TestAddChannelMembers(t *testing.T) { } func TestAddChannelMemberFromThread(t *testing.T) { + mainHelper.Parallel(t) t.Skip("MM-41285") th := Setup(t).InitBasic() defer th.TearDown() @@ -4334,6 +4380,7 @@ func TestAddChannelMemberGuestAccessControl(t *testing.T) { } func TestAddChannelMemberAddMyself(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -4409,6 +4456,7 @@ func TestAddChannelMemberAddMyself(t *testing.T) { } func TestRemoveChannelMember(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() user1 := th.BasicUser user2 := th.BasicUser2 @@ -4629,6 +4677,7 @@ func TestRemoveChannelMember(t *testing.T) { } func TestAutocompleteChannels(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -4697,6 +4746,7 @@ func TestAutocompleteChannels(t *testing.T) { } func TestAutocompleteChannelsForSearch(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -4810,6 +4860,7 @@ func TestAutocompleteChannelsForSearch(t *testing.T) { } func TestAutocompleteChannelsForSearchGuestUsers(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -4939,6 +4990,7 @@ func TestAutocompleteChannelsForSearchGuestUsers(t *testing.T) { } func TestUpdateChannelScheme(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -5022,6 +5074,7 @@ func TestUpdateChannelScheme(t *testing.T) { } func TestGetChannelMembersTimezones(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -5065,6 +5118,7 @@ func TestGetChannelMembersTimezones(t *testing.T) { } func TestChannelMembersMinusGroupMembers(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5159,6 +5213,7 @@ func TestChannelMembersMinusGroupMembers(t *testing.T) { } func TestGetChannelModerations(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5373,6 +5428,7 @@ func TestGetChannelModerations(t *testing.T) { } func TestPatchChannelModerations(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5557,6 +5613,7 @@ func TestPatchChannelModerations(t *testing.T) { } func TestGetChannelMemberCountsByGroup(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5649,6 +5706,7 @@ func TestGetChannelMemberCountsByGroup(t *testing.T) { } func TestGetChannelsMemberCount(t *testing.T) { + mainHelper.Parallel(t) // Setup th := Setup(t).InitBasic() defer th.TearDown() @@ -5733,6 +5791,7 @@ func TestGetChannelsMemberCount(t *testing.T) { } func TestMoveChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5864,6 +5923,7 @@ func TestMoveChannel(t *testing.T) { } func TestRootMentionsCount(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5905,6 +5965,7 @@ func TestRootMentionsCount(t *testing.T) { } func TestViewChannelWithoutCollapsedThreads(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/api4/cloud_test.go b/server/channels/api4/cloud_test.go index 17b3aafe21..1481bf8278 100644 --- a/server/channels/api4/cloud_test.go +++ b/server/channels/api4/cloud_test.go @@ -17,6 +17,7 @@ import ( ) func Test_GetSubscription(t *testing.T) { + mainHelper.Parallel(t) deliquencySince := int64(2000000000) subscription := &model.Subscription{ @@ -52,6 +53,7 @@ func Test_GetSubscription(t *testing.T) { } t.Run("NON Admin users receive the user facing subscription", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -77,6 +79,7 @@ func Test_GetSubscription(t *testing.T) { }) t.Run("Admin users receive the full subscription information", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -103,7 +106,9 @@ func Test_GetSubscription(t *testing.T) { } func Test_validateBusinessEmail(t *testing.T) { + mainHelper.Parallel(t) t.Run("Returns forbidden for invalid business email", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -129,6 +134,7 @@ func Test_validateBusinessEmail(t *testing.T) { }) t.Run("Validate business email for admin", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -154,6 +160,7 @@ func Test_validateBusinessEmail(t *testing.T) { }) t.Run("Empty body returns bad request", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -169,7 +176,9 @@ func Test_validateBusinessEmail(t *testing.T) { } func Test_validateWorkspaceBusinessEmail(t *testing.T) { + mainHelper.Parallel(t) t.Run("validate the Cloud Customer has used a valid email to create the workspace", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -201,6 +210,7 @@ func Test_validateWorkspaceBusinessEmail(t *testing.T) { }) t.Run("validate the Cloud Customer has used a invalid email to create the workspace and must validate admin email", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -237,6 +247,7 @@ func Test_validateWorkspaceBusinessEmail(t *testing.T) { }) t.Run("Error while grabbing the cloud customer returns bad request", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -271,6 +282,7 @@ func Test_validateWorkspaceBusinessEmail(t *testing.T) { } func TestGetCloudProducts(t *testing.T) { + mainHelper.Parallel(t) cloudProducts := []*model.Product{ { ID: "prod_test1", @@ -337,6 +349,7 @@ func TestGetCloudProducts(t *testing.T) { }, } t.Run("get products for admins", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -359,6 +372,7 @@ func TestGetCloudProducts(t *testing.T) { }) t.Run("get products for non admins", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -418,6 +432,7 @@ func TestGetCloudProducts(t *testing.T) { } func TestGetSelfHostedProducts(t *testing.T) { + mainHelper.Parallel(t) products := []*model.Product{ { ID: "prod_test", @@ -459,6 +474,7 @@ func TestGetSelfHostedProducts(t *testing.T) { } t.Run("get products for admins", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -479,6 +495,7 @@ func TestGetSelfHostedProducts(t *testing.T) { }) t.Run("get products for non admins", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/api4/cluster_test.go b/server/channels/api4/cluster_test.go index 508e20a002..72d4951329 100644 --- a/server/channels/api4/cluster_test.go +++ b/server/channels/api4/cluster_test.go @@ -13,6 +13,7 @@ import ( ) func TestGetClusterStatus(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/api4/command_help_test.go b/server/channels/api4/command_help_test.go index ea0d4a89a7..c35039bbf3 100644 --- a/server/channels/api4/command_help_test.go +++ b/server/channels/api4/command_help_test.go @@ -14,6 +14,7 @@ import ( ) func TestHelpCommand(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/api4/command_test.go b/server/channels/api4/command_test.go index 25e3491ea6..b10d9b4883 100644 --- a/server/channels/api4/command_test.go +++ b/server/channels/api4/command_test.go @@ -20,6 +20,7 @@ import ( ) func TestCreateCommand(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -36,7 +37,8 @@ func TestCreateCommand(t *testing.T) { TeamId: th.BasicTeam.Id, URL: "http://nowhere.com", Method: model.CommandMethodPost, - Trigger: "trigger"} + Trigger: "trigger", + } _, resp, err := client.CreateCommand(context.Background(), newCmd) require.Error(t, err) @@ -82,6 +84,7 @@ func TestCreateCommand(t *testing.T) { } func TestUpdateCommand(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() user := th.SystemAdminUser @@ -161,6 +164,7 @@ func TestUpdateCommand(t *testing.T) { } func TestMoveCommand(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() user := th.SystemAdminUser @@ -219,6 +223,7 @@ func TestMoveCommand(t *testing.T) { } func TestDeleteCommand(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() user := th.SystemAdminUser @@ -277,6 +282,7 @@ func TestDeleteCommand(t *testing.T) { } func TestListCommands(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -292,7 +298,8 @@ func TestListCommands(t *testing.T) { TeamId: th.BasicTeam.Id, URL: "http://nowhere.com", Method: model.CommandMethodPost, - Trigger: "custom_command"} + Trigger: "custom_command", + } _, _, err := th.SystemAdminClient.CreateCommand(context.Background(), newCmd) require.NoError(t, err) @@ -372,6 +379,7 @@ func TestListCommands(t *testing.T) { } func TestListAutocompleteCommands(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -381,7 +389,8 @@ func TestListAutocompleteCommands(t *testing.T) { TeamId: th.BasicTeam.Id, URL: "http://nowhere.com", Method: model.CommandMethodPost, - Trigger: "custom_command"} + Trigger: "custom_command", + } _, _, err := th.SystemAdminClient.CreateCommand(context.Background(), newCmd) require.NoError(t, err) @@ -441,6 +450,7 @@ func TestListAutocompleteCommands(t *testing.T) { } func TestListCommandAutocompleteSuggestions(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -450,7 +460,8 @@ func TestListCommandAutocompleteSuggestions(t *testing.T) { TeamId: th.BasicTeam.Id, URL: "http://nowhere.com", Method: model.CommandMethodPost, - Trigger: "custom_command"} + Trigger: "custom_command", + } _, _, err := th.SystemAdminClient.CreateCommand(context.Background(), newCmd) require.NoError(t, err) @@ -533,6 +544,7 @@ func TestListCommandAutocompleteSuggestions(t *testing.T) { } func TestGetCommand(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -547,7 +559,8 @@ func TestGetCommand(t *testing.T) { TeamId: th.BasicTeam.Id, URL: "http://nowhere.com", Method: model.CommandMethodPost, - Trigger: "roger"} + Trigger: "roger", + } newCmd, _, err := th.SystemAdminClient.CreateCommand(context.Background(), newCmd) require.NoError(t, err) @@ -594,6 +607,7 @@ func TestGetCommand(t *testing.T) { } func TestRegenToken(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -609,7 +623,8 @@ func TestRegenToken(t *testing.T) { TeamId: th.BasicTeam.Id, URL: "http://nowhere.com", Method: model.CommandMethodPost, - Trigger: "trigger"} + Trigger: "trigger", + } createdCmd, resp, err := th.SystemAdminClient.CreateCommand(context.Background(), newCmd) require.NoError(t, err) @@ -626,6 +641,7 @@ func TestRegenToken(t *testing.T) { } func TestExecuteInvalidCommand(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -696,6 +712,7 @@ func TestExecuteInvalidCommand(t *testing.T) { } func TestExecuteGetCommand(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -758,6 +775,7 @@ func TestExecuteGetCommand(t *testing.T) { } func TestExecutePostCommand(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -818,6 +836,7 @@ func TestExecutePostCommand(t *testing.T) { } func TestExecuteCommandAgainstChannelOnAnotherTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -871,6 +890,7 @@ func TestExecuteCommandAgainstChannelOnAnotherTeam(t *testing.T) { } func TestExecuteCommandAgainstChannelUserIsNotIn(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -927,6 +947,7 @@ func TestExecuteCommandAgainstChannelUserIsNotIn(t *testing.T) { } func TestExecuteCommandInDirectMessageChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -991,6 +1012,7 @@ func TestExecuteCommandInDirectMessageChannel(t *testing.T) { } func TestExecuteCommandInTeamUserIsNotOn(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1067,6 +1089,7 @@ func TestExecuteCommandInTeamUserIsNotOn(t *testing.T) { } func TestExecuteCommandReadOnly(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client diff --git a/server/channels/api4/commands_test.go b/server/channels/api4/commands_test.go index fc0ccc7732..7a90cf0dd9 100644 --- a/server/channels/api4/commands_test.go +++ b/server/channels/api4/commands_test.go @@ -17,6 +17,7 @@ import ( ) func TestEchoCommand(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -41,6 +42,7 @@ func TestEchoCommand(t *testing.T) { } func TestGroupmsgCommands(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -89,6 +91,7 @@ func TestGroupmsgCommands(t *testing.T) { } func TestInvitePeopleCommand(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -167,10 +170,12 @@ func testJoinCommands(t *testing.T, alias string) { } func TestJoinCommands(t *testing.T) { + mainHelper.Parallel(t) testJoinCommands(t, "join") } func TestLoadTestHelpCommands(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -190,6 +195,7 @@ func TestLoadTestHelpCommands(t *testing.T) { } func TestLoadTestSetupCommands(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -209,6 +215,7 @@ func TestLoadTestSetupCommands(t *testing.T) { } func TestLoadTestUsersCommands(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -228,6 +235,7 @@ func TestLoadTestUsersCommands(t *testing.T) { } func TestLoadTestChannelsCommands(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -247,6 +255,7 @@ func TestLoadTestChannelsCommands(t *testing.T) { } func TestLoadTestPostsCommands(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -266,6 +275,7 @@ func TestLoadTestPostsCommands(t *testing.T) { } func TestLeaveCommands(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -322,6 +332,7 @@ func TestLeaveCommands(t *testing.T) { } func TestLogoutTestCommand(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -330,6 +341,7 @@ func TestLogoutTestCommand(t *testing.T) { } func TestMeCommand(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -357,6 +369,7 @@ func TestMeCommand(t *testing.T) { } func TestMsgCommands(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -404,10 +417,12 @@ func TestMsgCommands(t *testing.T) { } func TestOpenCommands(t *testing.T) { + mainHelper.Parallel(t) testJoinCommands(t, "open") } func TestSearchCommand(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -416,6 +431,7 @@ func TestSearchCommand(t *testing.T) { } func TestSettingsCommand(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -424,6 +440,7 @@ func TestSettingsCommand(t *testing.T) { } func TestShortcutsCommand(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -432,6 +449,7 @@ func TestShortcutsCommand(t *testing.T) { } func TestShrugCommand(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -452,6 +470,7 @@ func TestShrugCommand(t *testing.T) { } func TestStatusCommands(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/api4/cors_test.go b/server/channels/api4/cors_test.go index 131ca7f4d5..b3d6904132 100644 --- a/server/channels/api4/cors_test.go +++ b/server/channels/api4/cors_test.go @@ -25,6 +25,7 @@ const ( ) func TestCORSRequestHandling(t *testing.T) { + mainHelper.Parallel(t) for name, testcase := range map[string]struct { AllowCorsFrom string CorsExposedHeaders string diff --git a/server/channels/api4/custom_profile_attributes_test.go b/server/channels/api4/custom_profile_attributes_test.go index a8936663ee..7b2b69a27d 100644 --- a/server/channels/api4/custom_profile_attributes_test.go +++ b/server/channels/api4/custom_profile_attributes_test.go @@ -7,7 +7,6 @@ import ( "context" "encoding/json" "fmt" - "os" "strings" "testing" "time" @@ -17,9 +16,10 @@ import ( ) func TestCreateCPAField(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES") - th := Setup(t) + mainHelper.Parallel(t) + th := SetupConfig(t, func(cfg *model.Config) { + cfg.FeatureFlags.CustomProfileAttributes = true + }) defer th.TearDown() th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { @@ -96,9 +96,10 @@ func TestCreateCPAField(t *testing.T) { } func TestListCPAFields(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES") - th := Setup(t) + mainHelper.Parallel(t) + th := SetupConfig(t, func(cfg *model.Config) { + cfg.FeatureFlags.CustomProfileAttributes = true + }) defer th.TearDown() field, err := model.NewCPAFieldFromPropertyField(&model.PropertyField{ @@ -142,9 +143,10 @@ func TestListCPAFields(t *testing.T) { } func TestPatchCPAField(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES") - th := Setup(t) + mainHelper.Parallel(t) + th := SetupConfig(t, func(cfg *model.Config) { + cfg.FeatureFlags.CustomProfileAttributes = true + }) defer th.TearDown() th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { @@ -283,9 +285,10 @@ func TestPatchCPAField(t *testing.T) { } func TestDeleteCPAField(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES") - th := Setup(t) + mainHelper.Parallel(t) + th := SetupConfig(t, func(cfg *model.Config) { + cfg.FeatureFlags.CustomProfileAttributes = true + }) defer th.TearDown() th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { @@ -355,9 +358,11 @@ func TestDeleteCPAField(t *testing.T) { } func TestListCPAValues(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES") - th := Setup(t).InitBasic() + mainHelper.Parallel(t) + + th := SetupConfig(t, func(cfg *model.Config) { + cfg.FeatureFlags.CustomProfileAttributes = true + }).InitBasic() defer th.TearDown() th.RemovePermissionFromRole(model.PermissionViewMembers.Id, model.SystemUserRoleId) @@ -442,9 +447,11 @@ func TestListCPAValues(t *testing.T) { } func TestPatchCPAValues(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES") - th := Setup(t).InitBasic() + mainHelper.Parallel(t) + + th := SetupConfig(t, func(cfg *model.Config) { + cfg.FeatureFlags.CustomProfileAttributes = true + }).InitBasic() defer th.TearDown() field, err := model.NewCPAFieldFromPropertyField(&model.PropertyField{ diff --git a/server/channels/api4/data_retention_test.go b/server/channels/api4/data_retention_test.go index 162506c4b4..8a81368667 100644 --- a/server/channels/api4/data_retention_test.go +++ b/server/channels/api4/data_retention_test.go @@ -17,6 +17,7 @@ import ( ) func TestDataRetentionGetPolicy(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -26,6 +27,7 @@ func TestDataRetentionGetPolicy(t *testing.T) { } func TestGetPolicies(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -112,6 +114,7 @@ func TestGetPolicies(t *testing.T) { } func TestGetDataRetentionPoliciesCount(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -159,6 +162,7 @@ func TestGetDataRetentionPoliciesCount(t *testing.T) { } func TestGetPolicy(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -244,6 +248,7 @@ func TestGetPolicy(t *testing.T) { } func TestCreatePolicy(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -340,6 +345,7 @@ func TestCreatePolicy(t *testing.T) { } func TestPatchPolicy(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -455,6 +461,7 @@ func TestPatchPolicy(t *testing.T) { } func TestDeletePolicy(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -522,6 +529,7 @@ func TestDeletePolicy(t *testing.T) { } func TestGetTeamPoliciesForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -607,6 +615,7 @@ func TestGetTeamPoliciesForUser(t *testing.T) { } func TestGetChannelPoliciesForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -692,6 +701,7 @@ func TestGetChannelPoliciesForUser(t *testing.T) { } func TestGetTeamsForPolicy(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -782,6 +792,7 @@ func TestGetTeamsForPolicy(t *testing.T) { } func TestAddTeamsToPolicy(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -852,6 +863,7 @@ func TestAddTeamsToPolicy(t *testing.T) { } func TestRemoveTeamsFromPolicy(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -922,6 +934,7 @@ func TestRemoveTeamsFromPolicy(t *testing.T) { } func TestGetChannelsForPolicy(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1022,6 +1035,7 @@ func TestGetChannelsForPolicy(t *testing.T) { } func TestAddChannelsToPolicy(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1141,6 +1155,7 @@ func TestAddChannelsToPolicy(t *testing.T) { } func TestRemoveChannelsFromPolicy(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/api4/drafts_test.go b/server/channels/api4/drafts_test.go index 84e1ce993e..35a7b40014 100644 --- a/server/channels/api4/drafts_test.go +++ b/server/channels/api4/drafts_test.go @@ -5,7 +5,6 @@ package api4 import ( "context" - "os" "testing" "time" @@ -17,10 +16,7 @@ import ( ) func TestUpsertDraft(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_GLOBALDRAFTS", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_GLOBALDRAFTS") - os.Setenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS", "true") - defer os.Unsetenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS") + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -76,8 +72,6 @@ func TestUpsertDraft(t *testing.T) { CheckForbiddenStatus(t, resp) // try to upsert draft without config setting set to true - os.Setenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS", "false") - defer os.Unsetenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS") th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowSyncedDrafts = false }) _, resp, err = client.UpsertDraft(context.Background(), draft) @@ -86,10 +80,7 @@ func TestUpsertDraft(t *testing.T) { } func TestGetDrafts(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_GLOBALDRAFTS", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_GLOBALDRAFTS") - os.Setenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS", "true") - defer os.Unsetenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS") + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -149,8 +140,6 @@ func TestGetDrafts(t *testing.T) { CheckForbiddenStatus(t, resp) // try to get drafts when config is turned off - os.Setenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS", "false") - defer os.Unsetenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS") th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowSyncedDrafts = false }) _, resp, err = client.GetDrafts(context.Background(), user.Id, team.Id) require.Error(t, err) @@ -158,10 +147,7 @@ func TestGetDrafts(t *testing.T) { } func TestDeleteDraft(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_GLOBALDRAFTS", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_GLOBALDRAFTS") - os.Setenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS", "true") - defer os.Unsetenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS") + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -201,7 +187,7 @@ func TestDeleteDraft(t *testing.T) { _, _, err = client.UpsertDraft(context.Background(), draft2) require.NoError(t, err) - //get drafts + // get drafts draftResp, _, err := client.GetDrafts(context.Background(), user.Id, team.Id) require.NoError(t, err) @@ -217,7 +203,7 @@ func TestDeleteDraft(t *testing.T) { _, _, err = client.DeleteDraft(context.Background(), user.Id, channel1.Id, draft1.RootId) require.NoError(t, err) - //get drafts + // get drafts draftResp, _, err = client.GetDrafts(context.Background(), user.Id, team.Id) require.NoError(t, err) diff --git a/server/channels/api4/elasticsearch_test.go b/server/channels/api4/elasticsearch_test.go index 0ebb8fa27c..3e08d37c7f 100644 --- a/server/channels/api4/elasticsearch_test.go +++ b/server/channels/api4/elasticsearch_test.go @@ -15,6 +15,7 @@ import ( ) func TestElasticsearchTest(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -56,6 +57,7 @@ func TestElasticsearchTest(t *testing.T) { } func TestElasticsearchPurgeIndexes(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/api4/emoji_test.go b/server/channels/api4/emoji_test.go index 12fd73af68..cb9c56d628 100644 --- a/server/channels/api4/emoji_test.go +++ b/server/channels/api4/emoji_test.go @@ -22,6 +22,7 @@ import ( ) func TestCreateEmoji(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -212,6 +213,7 @@ func TestCreateEmoji(t *testing.T) { } func TestGetEmojiList(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -305,6 +307,7 @@ func TestGetEmojiList(t *testing.T) { } func TestGetEmojisByNames(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -385,6 +388,7 @@ func TestGetEmojisByNames(t *testing.T) { } func TestDeleteEmoji(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -414,7 +418,7 @@ func TestDeleteEmoji(t *testing.T) { _, _, err = client.GetEmoji(context.Background(), newEmoji.Id) require.Error(t, err, "expected error fetching deleted emoji") - //Admin can delete other users emoji + // Admin can delete other users emoji newEmoji, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif") require.NoError(t, err) @@ -429,17 +433,17 @@ func TestDeleteEmoji(t *testing.T) { require.Error(t, err) CheckNotFoundStatus(t, resp) - //Try to delete non-existing emoji + // Try to delete non-existing emoji resp, err = client.DeleteEmoji(context.Background(), model.NewId()) require.Error(t, err) CheckNotFoundStatus(t, resp) - //Try to delete without Id + // Try to delete without Id resp, err = client.DeleteEmoji(context.Background(), "") require.Error(t, err) CheckNotFoundStatus(t, resp) - //Try to delete my custom emoji without permissions + // Try to delete my custom emoji without permissions newEmoji, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif") require.NoError(t, err) @@ -449,7 +453,7 @@ func TestDeleteEmoji(t *testing.T) { CheckForbiddenStatus(t, resp) th.AddPermissionToRole(model.PermissionDeleteEmojis.Id, model.SystemUserRoleId) - //Try to delete other user's custom emoji without DELETE_EMOJIS permissions + // Try to delete other user's custom emoji without DELETE_EMOJIS permissions emoji = &model.Emoji{ CreatorId: th.BasicUser.Id, Name: model.NewId(), @@ -476,7 +480,7 @@ func TestDeleteEmoji(t *testing.T) { require.NoError(t, err) th.LoginBasic() - //Try to delete other user's custom emoji without DELETE_OTHERS_EMOJIS permissions + // Try to delete other user's custom emoji without DELETE_OTHERS_EMOJIS permissions emoji = &model.Emoji{ CreatorId: th.BasicUser.Id, Name: model.NewId(), @@ -497,7 +501,7 @@ func TestDeleteEmoji(t *testing.T) { require.NoError(t, err) th.LoginBasic() - //Try to delete other user's custom emoji with permissions + // Try to delete other user's custom emoji with permissions emoji = &model.Emoji{ CreatorId: th.BasicUser.Id, Name: model.NewId(), @@ -520,7 +524,7 @@ func TestDeleteEmoji(t *testing.T) { require.NoError(t, err) th.LoginBasic() - //Try to delete my custom emoji with permissions at team level + // Try to delete my custom emoji with permissions at team level newEmoji, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif") require.NoError(t, err) @@ -531,7 +535,7 @@ func TestDeleteEmoji(t *testing.T) { th.AddPermissionToRole(model.PermissionDeleteEmojis.Id, model.SystemUserRoleId) th.RemovePermissionFromRole(model.PermissionDeleteEmojis.Id, model.TeamUserRoleId) - //Try to delete other user's custom emoji with permissions at team level + // Try to delete other user's custom emoji with permissions at team level emoji = &model.Emoji{ CreatorId: th.BasicUser.Id, Name: model.NewId(), @@ -555,6 +559,7 @@ func TestDeleteEmoji(t *testing.T) { } func TestGetEmoji(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -583,6 +588,7 @@ func TestGetEmoji(t *testing.T) { } func TestGetEmojiByName(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -613,6 +619,7 @@ func TestGetEmojiByName(t *testing.T) { } func TestGetEmojiImage(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -708,6 +715,7 @@ func TestGetEmojiImage(t *testing.T) { } func TestSearchEmoji(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -810,6 +818,7 @@ func TestSearchEmoji(t *testing.T) { } func TestAutocompleteEmoji(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client diff --git a/server/channels/api4/export_test.go b/server/channels/api4/export_test.go index 9fab2b9b5c..35b9284c53 100644 --- a/server/channels/api4/export_test.go +++ b/server/channels/api4/export_test.go @@ -17,6 +17,7 @@ import ( ) func TestListExports(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -87,6 +88,7 @@ func TestListExports(t *testing.T) { } func TestDeleteExport(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -131,6 +133,7 @@ func TestDeleteExport(t *testing.T) { } func TestDownloadExport(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/api4/file_test.go b/server/channels/api4/file_test.go index 3159e39ae3..920c4dab1b 100644 --- a/server/channels/api4/file_test.go +++ b/server/channels/api4/file_test.go @@ -205,6 +205,7 @@ func testUploadFilesMultipart( } func TestUploadFiles(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() if *th.App.Config().FileSettings.DriverName == "" { @@ -781,6 +782,7 @@ func TestUploadFiles(t *testing.T) { } func TestGetFile(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -822,6 +824,7 @@ func TestGetFile(t *testing.T) { } func TestGetFileAsSystemAdmin(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -907,6 +910,7 @@ func TestGetFileAsSystemAdmin(t *testing.T) { } func TestGetFileHeaders(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -975,6 +979,7 @@ func TestGetFileHeaders(t *testing.T) { } func TestGetFileThumbnail(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1025,6 +1030,7 @@ func TestGetFileThumbnail(t *testing.T) { } func TestGetFileThumbnailAsSystemAdmin(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1112,6 +1118,7 @@ func TestGetFileThumbnailAsSystemAdmin(t *testing.T) { } func TestGetFileLink(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1183,6 +1190,7 @@ func TestGetFileLink(t *testing.T) { } func TestGetFilePreview(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1232,6 +1240,7 @@ func TestGetFilePreview(t *testing.T) { } func TestGetFileInfo(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1289,6 +1298,7 @@ func TestGetFileInfo(t *testing.T) { } func TestGetPublicFile(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1352,6 +1362,7 @@ func TestGetPublicFile(t *testing.T) { } func TestSearchFilesInTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() experimentalViewArchivedChannels := *th.App.Config().TeamSettings.ExperimentalViewArchivedChannels @@ -1502,6 +1513,7 @@ func TestSearchFilesInTeam(t *testing.T) { } func TestSearchFilesAcrossTeams(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() experimentalViewArchivedChannels := *th.App.Config().TeamSettings.ExperimentalViewArchivedChannels diff --git a/server/channels/api4/group_test.go b/server/channels/api4/group_test.go index 0db8365b3d..8ce584d3ee 100644 --- a/server/channels/api4/group_test.go +++ b/server/channels/api4/group_test.go @@ -18,6 +18,7 @@ import ( ) func TestGetGroup(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -69,6 +70,7 @@ func TestGetGroup(t *testing.T) { } func TestCreateGroup(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -179,6 +181,7 @@ func TestCreateGroup(t *testing.T) { } func TestDeleteGroup(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -224,6 +227,7 @@ func TestDeleteGroup(t *testing.T) { } func TestUndeleteGroup(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -256,6 +260,7 @@ func TestUndeleteGroup(t *testing.T) { } func TestPatchGroup(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -359,6 +364,7 @@ func TestPatchGroup(t *testing.T) { } func TestLinkGroupTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -472,6 +478,7 @@ func TestLinkGroupTeam(t *testing.T) { } func TestLinkGroupChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -597,6 +604,7 @@ func TestLinkGroupChannel(t *testing.T) { } func TestUnlinkGroupTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -716,6 +724,7 @@ func TestUnlinkGroupTeam(t *testing.T) { } func TestUnlinkGroupChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -997,6 +1006,7 @@ func TestUnlinkGroupChannel(t *testing.T) { } func TestGetGroupTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1060,6 +1070,7 @@ func TestGetGroupTeam(t *testing.T) { } func TestGetGroupChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1123,6 +1134,7 @@ func TestGetGroupChannel(t *testing.T) { } func TestGetGroupTeams(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1177,6 +1189,7 @@ func TestGetGroupTeams(t *testing.T) { } func TestGetGroupChannels(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1230,6 +1243,7 @@ func TestGetGroupChannels(t *testing.T) { } func TestPatchGroupTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1303,6 +1317,7 @@ func TestPatchGroupTeam(t *testing.T) { } func TestPatchGroupChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1387,6 +1402,7 @@ func TestPatchGroupChannel(t *testing.T) { } func TestGetGroupsByChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1530,6 +1546,7 @@ func TestGetGroupsByChannel(t *testing.T) { } func TestGetGroupsAssociatedToChannelsByTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1682,6 +1699,7 @@ func TestGetGroupsAssociatedToChannelsByTeam(t *testing.T) { } func TestGetGroupsByTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1874,6 +1892,7 @@ func TestGetGroupsByTeam(t *testing.T) { } func TestGetGroups(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2256,6 +2275,7 @@ func TestGetGroups(t *testing.T) { } func TestGetGroupsByUserId(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2327,6 +2347,7 @@ func TestGetGroupsByUserId(t *testing.T) { } func TestGetGroupMembers(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2394,6 +2415,7 @@ func TestGetGroupMembers(t *testing.T) { } func TestGetGroupStats(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2443,6 +2465,7 @@ func TestGetGroupStats(t *testing.T) { } func TestGetGroupsGroupConstrainedParentTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -2526,6 +2549,7 @@ func TestGetGroupsGroupConstrainedParentTeam(t *testing.T) { } func TestAddMembersToGroup(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -2699,6 +2723,7 @@ func TestAddMembersToGroup(t *testing.T) { } func TestDeleteMembersFromGroup(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/api4/handlers_test.go b/server/channels/api4/handlers_test.go index 67b1e2513c..cece1264a2 100644 --- a/server/channels/api4/handlers_test.go +++ b/server/channels/api4/handlers_test.go @@ -69,6 +69,7 @@ func testAPIHandlerNoGzipMode(t *testing.T, name string, h http.Handler, token s } func TestAPIHandlersWithGzip(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/api4/image_test.go b/server/channels/api4/image_test.go index d372e53de3..d21578689c 100644 --- a/server/channels/api4/image_test.go +++ b/server/channels/api4/image_test.go @@ -18,6 +18,7 @@ import ( ) func TestGetImage(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/api4/import_test.go b/server/channels/api4/import_test.go index 7acb7a3377..3ecacbfa8b 100644 --- a/server/channels/api4/import_test.go +++ b/server/channels/api4/import_test.go @@ -20,6 +20,7 @@ import ( ) func TestListImports(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -110,6 +111,7 @@ func TestListImports(t *testing.T) { } func TestImportInLocalMode(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithServerOptions(t, []app.Option{app.RunEssentialJobs}) defer th.TearDown() diff --git a/server/channels/api4/integration_action_test.go b/server/channels/api4/integration_action_test.go index 2d2a3c597c..561584e797 100644 --- a/server/channels/api4/integration_action_test.go +++ b/server/channels/api4/integration_action_test.go @@ -47,6 +47,7 @@ func (th *testHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } func TestPostActionCookies(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -148,6 +149,7 @@ func TestPostActionCookies(t *testing.T) { } func TestOpenDialog(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -285,6 +287,7 @@ func TestOpenDialog(t *testing.T) { } func TestSubmitDialog(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client diff --git a/server/channels/api4/job_test.go b/server/channels/api4/job_test.go index d3ec4b9a5c..19013278ca 100644 --- a/server/channels/api4/job_test.go +++ b/server/channels/api4/job_test.go @@ -16,6 +16,7 @@ import ( ) func TestCreateJob(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) th.LoginSystemManager() defer th.TearDown() @@ -50,6 +51,7 @@ func TestCreateJob(t *testing.T) { } func TestGetJob(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -86,6 +88,7 @@ func TestGetJob(t *testing.T) { } func TestGetJobs(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -170,6 +173,7 @@ func TestGetJobs(t *testing.T) { } func TestGetJobsByType(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) th.LoginSystemManager() defer th.TearDown() @@ -239,6 +243,7 @@ func TestGetJobsByType(t *testing.T) { } func TestDownloadJob(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() th.LoginSystemManager() defer th.TearDown() @@ -280,7 +285,7 @@ func TestDownloadJob(t *testing.T) { require.NoError(t, delErr, "Failed to delete job %s", job.Id) }() - filePath := filepath.Join(*th.App.Config().FileSettings.Directory, "export", job.Id+"/testdat.txt") + filePath := filepath.Join(*th.App.Config().FileSettings.Directory, "export/"+job.Id+"/testdat.txt") err = os.MkdirAll(filepath.Dir(filePath), 0770) require.NoError(t, err) @@ -314,7 +319,7 @@ func TestDownloadJob(t *testing.T) { // Now we stub the results of the job into the same directory and try to download it again // This time we should successfully retrieve the results without any error - filePath = filepath.Join(*th.App.Config().FileSettings.Directory, "export", job.Id+".zip") + filePath = filepath.Join(*th.App.Config().FileSettings.Directory, "export/"+job.Id+".zip") err = os.MkdirAll(filepath.Dir(filePath), 0770) require.NoError(t, err) @@ -372,6 +377,7 @@ func TestDownloadJob(t *testing.T) { } func TestCancelJob(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -422,6 +428,7 @@ func TestCancelJob(t *testing.T) { } func TestUpdateJobStatus(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/api4/ldap_test.go b/server/channels/api4/ldap_test.go index 415082ffb9..22572a13ba 100644 --- a/server/channels/api4/ldap_test.go +++ b/server/channels/api4/ldap_test.go @@ -101,6 +101,7 @@ MCOV5SHi05kD42JSSbmw190VAa4QRGikaeWRhDsj -----END CERTIFICATE-----` func TestTestLdap(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -127,6 +128,7 @@ func TestTestLdap(t *testing.T) { } func TestSyncLdap(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -175,6 +177,7 @@ func TestSyncLdap(t *testing.T) { } func TestGetLdapGroups(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -190,6 +193,7 @@ func TestGetLdapGroups(t *testing.T) { } func TestLinkLdapGroup(t *testing.T) { + mainHelper.Parallel(t) const entryUUID string = "foo" th := Setup(t) @@ -205,6 +209,7 @@ func TestLinkLdapGroup(t *testing.T) { } func TestUnlinkLdapGroup(t *testing.T) { + mainHelper.Parallel(t) const entryUUID string = "foo" th := Setup(t) @@ -220,6 +225,7 @@ func TestUnlinkLdapGroup(t *testing.T) { } func TestMigrateIdLdap(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -239,6 +245,7 @@ func TestMigrateIdLdap(t *testing.T) { } func TestUploadPublicCertificate(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -260,6 +267,7 @@ func TestUploadPublicCertificate(t *testing.T) { } func TestUploadPrivateCertificate(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -281,6 +289,7 @@ func TestUploadPrivateCertificate(t *testing.T) { } func TestAddUserToGroupSyncables(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/api4/license_test.go b/server/channels/api4/license_test.go index a8d9bbf5d8..1ae13a06aa 100644 --- a/server/channels/api4/license_test.go +++ b/server/channels/api4/license_test.go @@ -22,6 +22,7 @@ import ( ) func TestGetOldClientLicense(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -193,6 +194,7 @@ func TestUploadLicenseFile(t *testing.T) { } func TestRemoveLicenseFile(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -407,6 +409,7 @@ func TestRequestTrialLicenseWithExtraFields(t *testing.T) { } func TestRequestTrialLicense(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/api4/main_test.go b/server/channels/api4/main_test.go index 1f6220dc32..f1b9aba5fe 100644 --- a/server/channels/api4/main_test.go +++ b/server/channels/api4/main_test.go @@ -5,8 +5,11 @@ package api4 import ( "flag" + "os" + "strconv" "testing" + "github.com/mattermost/mattermost/server/public/shared/mlog" "github.com/mattermost/mattermost/server/v8/channels/testlib" ) @@ -18,10 +21,21 @@ func TestMain(m *testing.M) { flag.Parse() } - var options = testlib.HelperOptions{ + var parallelism int + if f := flag.Lookup("test.parallel"); f != nil { + parallelism, _ = strconv.Atoi(f.Value.String()) + } + runParallel := os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" && parallelism > 1 + if runParallel { + mlog.Info("Fully parallel tests enabled", mlog.Int("parallelism", parallelism)) + } + + options := testlib.HelperOptions{ EnableStore: true, EnableResources: true, WithReadReplica: replicaFlag, + RunParallel: runParallel, + Parallelism: parallelism, } mainHelper = testlib.NewMainHelperWithOptions(&options) diff --git a/server/channels/api4/metrics_test.go b/server/channels/api4/metrics_test.go index c22560fe44..7a8dccda54 100644 --- a/server/channels/api4/metrics_test.go +++ b/server/channels/api4/metrics_test.go @@ -35,6 +35,7 @@ func setupMetricsMock() *mocks.MetricsInterface { return metricsMock } + func TestSubmitMetrics(t *testing.T) { t.Run("unauthenticated user should not submit metrics", func(t *testing.T) { th := Setup(t) diff --git a/server/channels/api4/notify_admin_test.go b/server/channels/api4/notify_admin_test.go index 085bd317cb..b2e83bf6ca 100644 --- a/server/channels/api4/notify_admin_test.go +++ b/server/channels/api4/notify_admin_test.go @@ -13,7 +13,9 @@ import ( ) func TestNotifyAdmin(t *testing.T) { + mainHelper.Parallel(t) t.Run("error when notifying with empty data", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -24,6 +26,7 @@ func TestNotifyAdmin(t *testing.T) { }) t.Run("error when plan is unknown when notifying on upgrade", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -38,6 +41,7 @@ func TestNotifyAdmin(t *testing.T) { }) t.Run("error when plan is unknown when notifying to trial", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -53,6 +57,7 @@ func TestNotifyAdmin(t *testing.T) { }) t.Run("error when feature is unknown when notifying on upgrade", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -67,6 +72,7 @@ func TestNotifyAdmin(t *testing.T) { }) t.Run("error when feature is unknown when notifying to trial", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -82,6 +88,7 @@ func TestNotifyAdmin(t *testing.T) { }) t.Run("error when user tries to notify again on same feature within the cool off period", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -104,6 +111,7 @@ func TestNotifyAdmin(t *testing.T) { }) t.Run("successfully save upgrade notification", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -118,7 +126,9 @@ func TestNotifyAdmin(t *testing.T) { } func TestTriggerNotifyAdmin(t *testing.T) { + mainHelper.Parallel(t) t.Run("error when EnableAPITriggerAdminNotifications is not true", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -132,6 +142,7 @@ func TestTriggerNotifyAdmin(t *testing.T) { }) t.Run("error when non admins try to trigger notifications", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -145,6 +156,7 @@ func TestTriggerNotifyAdmin(t *testing.T) { }) t.Run("happy path", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/api4/oauth_test.go b/server/channels/api4/oauth_test.go index 21d6d61b63..0d71161044 100644 --- a/server/channels/api4/oauth_test.go +++ b/server/channels/api4/oauth_test.go @@ -15,6 +15,7 @@ import ( ) func TestCreateOAuthApp(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -80,6 +81,8 @@ func TestCreateOAuthApp(t *testing.T) { func TestUpdateOAuthApp(t *testing.T) { t.Skip("https://mattermost.atlassian.net/browse/MM-62895") + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -203,6 +206,7 @@ func TestUpdateOAuthApp(t *testing.T) { } func TestGetOAuthApps(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -273,6 +277,7 @@ func TestGetOAuthApps(t *testing.T) { } func TestGetOAuthApp(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -344,6 +349,7 @@ func TestGetOAuthApp(t *testing.T) { } func TestGetOAuthAppInfo(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -413,6 +419,7 @@ func TestGetOAuthAppInfo(t *testing.T) { } func TestDeleteOAuthApp(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -486,6 +493,7 @@ func TestDeleteOAuthApp(t *testing.T) { } func TestRegenerateOAuthAppSecret(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -561,6 +569,7 @@ func TestRegenerateOAuthAppSecret(t *testing.T) { } func TestGetAuthorizedOAuthAppsForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -619,6 +628,7 @@ func TestGetAuthorizedOAuthAppsForUser(t *testing.T) { } func TestNilAuthorizeOAuthApp(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client diff --git a/server/channels/api4/permissions_test.go b/server/channels/api4/permissions_test.go index ca1f9c22bb..8f84202510 100644 --- a/server/channels/api4/permissions_test.go +++ b/server/channels/api4/permissions_test.go @@ -14,6 +14,7 @@ import ( ) func TestGetAncillaryPermissions(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/api4/plugin_test.go b/server/channels/api4/plugin_test.go index 0d6fe574ca..b179368708 100644 --- a/server/channels/api4/plugin_test.go +++ b/server/channels/api4/plugin_test.go @@ -32,6 +32,7 @@ import ( ) func TestPlugin(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -286,6 +287,7 @@ func TestPlugin(t *testing.T) { } func TestNotifyClusterPluginEvent(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -378,6 +380,7 @@ func TestNotifyClusterPluginEvent(t *testing.T) { } func TestDisableOnRemove(t *testing.T) { + mainHelper.Parallel(t) path, _ := fileutils.FindDir("tests") tarData, err := os.ReadFile(filepath.Join(path, "testplugin.tar.gz")) require.NoError(t, err) @@ -1139,6 +1142,7 @@ func TestGetLocalPluginInMarketplace(t *testing.T) { } func TestGetRemotePluginInMarketplace(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1328,6 +1332,7 @@ func TestGetPrepackagedPluginInMarketplace(t *testing.T) { } func TestGetPrepackagedPlaybooksPluginIn(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1756,6 +1761,7 @@ func TestInstallMarketplacePlugin(t *testing.T) { } func TestInstallMarketplacePluginPrepackagedDisabled(t *testing.T) { + mainHelper.Parallel(t) path, _ := fileutils.FindDir("tests") signatureFilename := "testplugin2.tar.gz.sig" @@ -2093,6 +2099,7 @@ func findClusterMessages(event model.ClusterEvent, msgs []*model.ClusterMessage) } func TestPluginWebSocketSession(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2145,6 +2152,7 @@ func TestPluginWebSocketSession(t *testing.T) { } func TestPluginWebSocketRemoteAddress(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/api4/post_test.go b/server/channels/api4/post_test.go index 8825a92ae9..29eb787d53 100644 --- a/server/channels/api4/post_test.go +++ b/server/channels/api4/post_test.go @@ -34,6 +34,8 @@ import ( ) func TestCreatePost(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -304,6 +306,8 @@ func TestCreatePost(t *testing.T) { } func TestCreatePostForPriority(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -477,6 +481,7 @@ func TestCreatePostForPriority(t *testing.T) { } func TestCreatePostWithOAuthClient(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -545,6 +550,8 @@ func TestCreatePostWithOAuthClient(t *testing.T) { } func TestCreatePostEphemeral(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.SystemAdminClient @@ -583,6 +590,8 @@ func testCreatePostWithOutgoingHook( triggerWhen int, commentPostType bool, ) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() user := th.SystemAdminUser @@ -1089,6 +1098,8 @@ func TestMoveThread(t *testing.T) { } func TestCreatePostPublic(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1146,6 +1157,8 @@ func TestCreatePostPublic(t *testing.T) { } func TestCreatePostAll(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1212,6 +1225,8 @@ func TestCreatePostAll(t *testing.T) { } func TestCreatePostSendOutOfChannelMentions(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1274,6 +1289,8 @@ func TestCreatePostSendOutOfChannelMentions(t *testing.T) { } func TestCreatePostCheckOnlineStatus(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() @@ -1340,6 +1357,8 @@ func TestCreatePostCheckOnlineStatus(t *testing.T) { } func TestUpdatePost(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1690,6 +1709,8 @@ func TestUpdatePost(t *testing.T) { } func TestUpdateOthersPostInDirectMessageChannel(t *testing.T) { + mainHelper.Parallel(t) + // This test checks that a sysadmin with the "EDIT_OTHERS_POSTS" permission can edit someone else's post in a // channel without a team (DM/GM). This indirectly checks for the proper cascading all the way to system-wide roles // on the user object of permissions based on a post in a channel with no team ID. @@ -1715,6 +1736,8 @@ func TestUpdateOthersPostInDirectMessageChannel(t *testing.T) { } func TestPatchPost(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -2041,6 +2064,8 @@ func TestPatchPost(t *testing.T) { } func TestPinPost(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -2072,6 +2097,8 @@ func TestPinPost(t *testing.T) { } func TestUnpinPost(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -2103,6 +2130,8 @@ func TestUnpinPost(t *testing.T) { } func TestGetPostsForChannel(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -2346,6 +2375,8 @@ func TestGetPostsForChannel(t *testing.T) { } func TestGetFlaggedPostsForUser(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -2552,6 +2583,8 @@ func TestGetFlaggedPostsForUser(t *testing.T) { } func TestGetPostsBefore(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -2719,6 +2752,8 @@ func TestGetPostsBefore(t *testing.T) { } func TestGetPostsAfter(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -2867,6 +2902,8 @@ func TestGetPostsAfter(t *testing.T) { } func TestGetPostsForChannelAroundLastUnread(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3120,6 +3157,8 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) { } func TestGetPost(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() // TODO: migrate this entirely to the subtest's client @@ -3219,6 +3258,8 @@ func TestGetPost(t *testing.T) { } func TestDeletePost(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3275,6 +3316,8 @@ func TestDeletePost(t *testing.T) { } func TestPermanentDeletePost(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3352,7 +3395,11 @@ func TestPermanentDeletePost(t *testing.T) { } func TestWebHubMembership(t *testing.T) { + mainHelper.Parallel(t) + t.Run("WithChannelIteration", func(t *testing.T) { + mainHelper.Parallel(t) + th := SetupConfig(t, func(cfg *model.Config) { *cfg.ServiceSettings.EnableWebHubChannelIteration = true }).InitBasic() @@ -3362,6 +3409,8 @@ func TestWebHubMembership(t *testing.T) { }) t.Run("WithoutChannelIteration", func(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() @@ -3490,6 +3539,8 @@ func _testWebHubMembership(th *TestHelper, t *testing.T) { } func TestWebHubCloseConnOnDBFail(t *testing.T) { + mainHelper.Parallel(t) + th := SetupConfig(t, func(cfg *model.Config) { *cfg.ServiceSettings.EnableWebHubChannelIteration = true }).InitBasic() @@ -3510,12 +3561,21 @@ func TestWebHubCloseConnOnDBFail(t *testing.T) { wsClient, err := th.CreateWebSocketClientWithClient(cli) require.NoError(t, err) + + wsClient.Listen() + select { + case <-wsClient.EventChannel: // event channel should be closed on failure + case <-time.After(5 * time.Second): + require.FailNow(t, "timed out waiting for event") + } wsClient.Close() require.NoError(t, th.TestLogger.Flush()) } func TestDeletePostEvent(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() @@ -3543,6 +3603,8 @@ func TestDeletePostEvent(t *testing.T) { } func TestDeletePostMessage(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() th.LinkUserToTeam(th.SystemAdminUser, th.BasicTeam) _, appErr := th.App.AddUserToChannel(th.Context, th.SystemAdminUser, th.BasicChannel, false) @@ -3589,6 +3651,8 @@ func TestDeletePostMessage(t *testing.T) { } func TestGetPostThread(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3718,6 +3782,8 @@ func TestGetPostThread(t *testing.T) { } func TestSearchPosts(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() experimentalViewArchivedChannels := *th.App.Config().TeamSettings.ExperimentalViewArchivedChannels @@ -3870,6 +3936,8 @@ func TestSearchPosts(t *testing.T) { } func TestSearchHashtagPosts(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() th.LoginBasic() @@ -3896,6 +3964,8 @@ func TestSearchHashtagPosts(t *testing.T) { } func TestSearchPostsInChannel(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() th.LoginBasic() @@ -3950,6 +4020,8 @@ func TestSearchPostsInChannel(t *testing.T) { } func TestSearchPostsFromUser(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -4018,6 +4090,8 @@ func TestSearchPostsFromUser(t *testing.T) { } func TestSearchPostsWithDateFlags(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() th.LoginBasic() @@ -4161,6 +4235,8 @@ func TestGetFileInfosForPost(t *testing.T) { } func TestSetChannelUnread(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() @@ -4335,6 +4411,8 @@ func TestSetChannelUnread(t *testing.T) { } func TestSetPostUnreadWithoutCollapsedThreads(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() th.App.UpdateConfig(func(cfg *model.Config) { @@ -4430,6 +4508,8 @@ func TestSetPostUnreadWithoutCollapsedThreads(t *testing.T) { } func TestGetPostsByIds(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -4454,6 +4534,8 @@ func TestGetPostsByIds(t *testing.T) { } func TestGetEditHistoryForPost(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -4574,6 +4656,8 @@ func TestGetEditHistoryForPost(t *testing.T) { } func TestCreatePostNotificationsWithCRT(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() rpost := th.CreatePost() @@ -4727,6 +4811,8 @@ func TestCreatePostNotificationsWithCRT(t *testing.T) { } func TestGetPostStripActionIntegrations(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -4838,6 +4924,8 @@ func TestPostReminder(t *testing.T) { } func TestPostGetInfo(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() @@ -5107,6 +5195,8 @@ func TestPostGetInfo(t *testing.T) { } func TestAcknowledgePost(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional)) @@ -5148,6 +5238,8 @@ func TestAcknowledgePost(t *testing.T) { } func TestUnacknowledgePost(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional)) @@ -5193,6 +5285,8 @@ func TestUnacknowledgePost(t *testing.T) { } func TestRestorePostVersion(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() client := th.Client diff --git a/server/channels/api4/preference_test.go b/server/channels/api4/preference_test.go index dabd9649aa..4fe523d534 100644 --- a/server/channels/api4/preference_test.go +++ b/server/channels/api4/preference_test.go @@ -16,6 +16,7 @@ import ( ) func TestGetPreferences(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -87,6 +88,7 @@ func TestGetPreferences(t *testing.T) { } func TestGetPreferencesByCategory(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -157,6 +159,7 @@ func TestGetPreferencesByCategory(t *testing.T) { } func TestGetPreferenceByCategoryAndName(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -226,6 +229,7 @@ func TestGetPreferenceByCategoryAndName(t *testing.T) { } func TestUpdatePreferences(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -305,6 +309,7 @@ func TestUpdatePreferences(t *testing.T) { } func TestUpdatePreferencesOverload(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -341,6 +346,7 @@ func TestUpdatePreferencesOverload(t *testing.T) { } func TestUpdatePreferencesWebsocket(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -392,6 +398,7 @@ func TestUpdatePreferencesWebsocket(t *testing.T) { } func TestUpdateSidebarPreferences(t *testing.T) { + mainHelper.Parallel(t) t.Run("when favoriting a channel, should add it to the Favorites sidebar category", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -619,6 +626,7 @@ func TestUpdateSidebarPreferences(t *testing.T) { } func TestDeletePreferences(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -689,6 +697,7 @@ func TestDeletePreferences(t *testing.T) { } func TestDeletePreferencesOverload(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -725,6 +734,7 @@ func TestDeletePreferencesOverload(t *testing.T) { } func TestDeletePreferencesWebsocket(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -778,6 +788,7 @@ func TestDeletePreferencesWebsocket(t *testing.T) { } func TestDeleteSidebarPreferences(t *testing.T) { + mainHelper.Parallel(t) t.Run("when removing a favorited channel preference, should remove it from the Favorites sidebar category", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -993,6 +1004,7 @@ func TestDeleteSidebarPreferences(t *testing.T) { } func TestUpdateLimitVisibleDMsGMs(t *testing.T) { + mainHelper.Parallel(t) t.Run("Update limit_visible_dms_gms to a valid value", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/api4/reaction_test.go b/server/channels/api4/reaction_test.go index cd9da41e3b..99921900b5 100644 --- a/server/channels/api4/reaction_test.go +++ b/server/channels/api4/reaction_test.go @@ -15,6 +15,7 @@ import ( ) func TestSaveReaction(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -195,6 +196,7 @@ func TestSaveReaction(t *testing.T) { } func TestGetReactions(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -278,6 +280,7 @@ func TestGetReactions(t *testing.T) { } func TestDeleteReaction(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -519,6 +522,7 @@ func TestDeleteReaction(t *testing.T) { } func TestGetBulkReactions(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client diff --git a/server/channels/api4/remote_cluster_test.go b/server/channels/api4/remote_cluster_test.go index e9a455def3..fcaa1f2c39 100644 --- a/server/channels/api4/remote_cluster_test.go +++ b/server/channels/api4/remote_cluster_test.go @@ -13,6 +13,7 @@ import ( ) func TestGetRemoteClusters(t *testing.T) { + mainHelper.Parallel(t) t.Run("Should not work if the remote cluster service is not enabled", func(t *testing.T) { th := Setup(t) defer th.TearDown() @@ -182,6 +183,7 @@ func TestGetRemoteClusters(t *testing.T) { } func TestCreateRemoteCluster(t *testing.T) { + mainHelper.Parallel(t) rcWithTeamAndPassword := &model.RemoteClusterWithPassword{ RemoteCluster: &model.RemoteCluster{ Name: "remotecluster", @@ -294,6 +296,7 @@ func TestCreateRemoteCluster(t *testing.T) { } func TestRemoteClusterAcceptinvite(t *testing.T) { + mainHelper.Parallel(t) rcAcceptInvite := &model.RemoteClusterAcceptInvite{ Name: "remotecluster", Invite: "myinvitecode", @@ -392,6 +395,7 @@ func TestRemoteClusterAcceptinvite(t *testing.T) { } func TestGenerateRemoteClusterInvite(t *testing.T) { + mainHelper.Parallel(t) password := "mysupersecret" newRC := &model.RemoteCluster{ @@ -482,6 +486,7 @@ func TestGenerateRemoteClusterInvite(t *testing.T) { } func TestGetRemoteCluster(t *testing.T) { + mainHelper.Parallel(t) newRC := &model.RemoteCluster{ Name: "remotecluster", SiteURL: "http://example.com", @@ -540,6 +545,7 @@ func TestGetRemoteCluster(t *testing.T) { } func TestPatchRemoteCluster(t *testing.T) { + mainHelper.Parallel(t) newRC := &model.RemoteCluster{ Name: "remotecluster", DisplayName: "initialvalue", @@ -604,6 +610,7 @@ func TestPatchRemoteCluster(t *testing.T) { } func TestDeleteRemoteCluster(t *testing.T) { + mainHelper.Parallel(t) newRC := &model.RemoteCluster{ Name: "remotecluster", DisplayName: "initialvalue", diff --git a/server/channels/api4/report_test.go b/server/channels/api4/report_test.go index 88e0a22d7a..6e38f060e5 100644 --- a/server/channels/api4/report_test.go +++ b/server/channels/api4/report_test.go @@ -14,6 +14,7 @@ import ( ) func TestGetUsersForReporting(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -59,6 +60,7 @@ func TestGetUsersForReporting(t *testing.T) { } func TestFillReportingBaseOptions(t *testing.T) { + mainHelper.Parallel(t) t.Run("default values", func(t *testing.T) { values := url.Values{} @@ -114,6 +116,7 @@ func TestFillReportingBaseOptions(t *testing.T) { } func TestFillUserReportOptions(t *testing.T) { + mainHelper.Parallel(t) validTeamID := model.NewId() t.Run("default values", func(t *testing.T) { diff --git a/server/channels/api4/role_test.go b/server/channels/api4/role_test.go index 3abdda262c..95c2e26c71 100644 --- a/server/channels/api4/role_test.go +++ b/server/channels/api4/role_test.go @@ -17,6 +17,7 @@ import ( ) func TestGetAllRoles(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -39,6 +40,7 @@ func TestGetAllRoles(t *testing.T) { } func TestGetRole(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -81,6 +83,7 @@ func TestGetRole(t *testing.T) { } func TestGetRoleByName(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -123,6 +126,7 @@ func TestGetRoleByName(t *testing.T) { } func TestGetRolesByNames(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -215,6 +219,7 @@ func TestGetRolesByNames(t *testing.T) { } func TestPatchRole(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/api4/saml_test.go b/server/channels/api4/saml_test.go index fcdfe1ce99..9d9671e99a 100644 --- a/server/channels/api4/saml_test.go +++ b/server/channels/api4/saml_test.go @@ -15,6 +15,7 @@ import ( ) func TestGetSamlMetadata(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -27,6 +28,7 @@ func TestGetSamlMetadata(t *testing.T) { } func TestSamlCompleteCSRFPass(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -55,6 +57,7 @@ func TestSamlCompleteCSRFPass(t *testing.T) { } func TestSamlResetId(t *testing.T) { + mainHelper.Parallel(t) th := SetupEnterprise(t).InitBasic() defer th.TearDown() th.App.Channels().Saml = &mocks.SamlInterface{} diff --git a/server/channels/api4/scheduled_post_test.go b/server/channels/api4/scheduled_post_test.go index 34d34b859c..638aa758c7 100644 --- a/server/channels/api4/scheduled_post_test.go +++ b/server/channels/api4/scheduled_post_test.go @@ -12,6 +12,7 @@ import ( ) func TestCreateScheduledPost(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/api4/scheme_test.go b/server/channels/api4/scheme_test.go index c5fc7333ca..d9f48a9703 100644 --- a/server/channels/api4/scheme_test.go +++ b/server/channels/api4/scheme_test.go @@ -15,6 +15,7 @@ import ( ) func TestCreateScheme(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -193,6 +194,7 @@ func TestCreateScheme(t *testing.T) { } func TestGetScheme(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -260,6 +262,7 @@ func TestGetScheme(t *testing.T) { } func TestGetSchemes(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -328,6 +331,7 @@ func TestGetSchemes(t *testing.T) { } func TestGetTeamsForScheme(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -425,6 +429,7 @@ func TestGetTeamsForScheme(t *testing.T) { } func TestGetChannelsForScheme(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -524,6 +529,7 @@ func TestGetChannelsForScheme(t *testing.T) { } func TestPatchScheme(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -652,6 +658,7 @@ func TestPatchScheme(t *testing.T) { } func TestDeleteScheme(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -871,6 +878,7 @@ func TestDeleteScheme(t *testing.T) { } func TestUpdateTeamSchemeWithTeamMembers(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/api4/shared_channel_test.go b/server/channels/api4/shared_channel_test.go index 729af1f42b..2cfb8498d3 100644 --- a/server/channels/api4/shared_channel_test.go +++ b/server/channels/api4/shared_channel_test.go @@ -18,9 +18,7 @@ import ( "github.com/mattermost/mattermost/server/public/model" ) -var ( - rnd = rand.New(rand.NewSource(time.Now().UnixNano())) -) +var rnd = rand.New(rand.NewSource(time.Now().UnixNano())) func setupForSharedChannels(tb testing.TB) *TestHelper { th := SetupConfig(tb, func(cfg *model.Config) { @@ -36,6 +34,7 @@ func setupForSharedChannels(tb testing.TB) *TestHelper { } func TestGetAllSharedChannels(t *testing.T) { + mainHelper.Parallel(t) th := setupForSharedChannels(t).InitBasic() defer th.TearDown() @@ -107,6 +106,7 @@ func randomBool() bool { } func TestGetRemoteClusterById(t *testing.T) { + mainHelper.Parallel(t) th := setupForSharedChannels(t).InitBasic() defer th.TearDown() @@ -161,6 +161,7 @@ func TestGetRemoteClusterById(t *testing.T) { } func TestCreateDirectChannelWithRemoteUser(t *testing.T) { + mainHelper.Parallel(t) t.Run("should not create a local DM channel that is shared", func(t *testing.T) { th := setupForSharedChannels(t).InitBasic() defer th.TearDown() @@ -276,6 +277,7 @@ func TestCreateDirectChannelWithRemoteUser(t *testing.T) { } func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) { + mainHelper.Parallel(t) t.Run("Should not work if the remote cluster service is not enabled", func(t *testing.T) { th := Setup(t) defer th.TearDown() @@ -534,6 +536,7 @@ func TestGetSharedChannelRemotesByRemoteCluster(t *testing.T) { } func TestInviteRemoteClusterToChannel(t *testing.T) { + mainHelper.Parallel(t) t.Run("Should not work if the remote cluster service is not enabled", func(t *testing.T) { th := Setup(t) defer th.TearDown() @@ -579,6 +582,7 @@ func TestInviteRemoteClusterToChannel(t *testing.T) { } func TestUninviteRemoteClusterToChannel(t *testing.T) { + mainHelper.Parallel(t) t.Run("Should not work if the remote cluster service is not enabled", func(t *testing.T) { th := Setup(t) defer th.TearDown() diff --git a/server/channels/api4/status_test.go b/server/channels/api4/status_test.go index 6e0f73c8d7..65329ae841 100644 --- a/server/channels/api4/status_test.go +++ b/server/channels/api4/status_test.go @@ -15,6 +15,7 @@ import ( ) func TestGetUserStatus(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -79,7 +80,7 @@ func TestGetUserStatus(t *testing.T) { }) t.Run("get other user status", func(t *testing.T) { - //Get user2 status logged as user1 + // Get user2 status logged as user1 userStatus, _, err := client.GetUserStatus(context.Background(), th.BasicUser2.Id, "") require.NoError(t, err) assert.Equal(t, "offline", userStatus.Status) @@ -102,6 +103,7 @@ func TestGetUserStatus(t *testing.T) { } func TestGetUsersStatusesByIds(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -185,6 +187,7 @@ func TestGetUsersStatusesByIds(t *testing.T) { } func TestUpdateUserStatus(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -249,6 +252,7 @@ func TestUpdateUserStatus(t *testing.T) { } func TestUpdateUserCustomStatus(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -351,6 +355,7 @@ func TestUpdateUserCustomStatus(t *testing.T) { } func TestRemoveUserCustomStatus(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client diff --git a/server/channels/api4/system_test.go b/server/channels/api4/system_test.go index 3d32a84fa6..9eff6c9507 100644 --- a/server/channels/api4/system_test.go +++ b/server/channels/api4/system_test.go @@ -111,6 +111,7 @@ func TestGetPing(t *testing.T) { } func TestGetAudits(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -143,6 +144,7 @@ func TestGetAudits(t *testing.T) { } func TestEmailTest(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -224,6 +226,7 @@ func TestEmailTest(t *testing.T) { } func TestGenerateSupportPacket(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) th.LoginSystemManager() defer th.TearDown() @@ -283,6 +286,7 @@ func TestGenerateSupportPacket(t *testing.T) { } func TestSupportPacketFileName(t *testing.T) { + mainHelper.Parallel(t) tests := map[string]struct { now time.Time customerName string @@ -314,6 +318,7 @@ func TestSupportPacketFileName(t *testing.T) { } func TestSiteURLTest(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -360,6 +365,7 @@ func TestSiteURLTest(t *testing.T) { } func TestDatabaseRecycle(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -385,6 +391,7 @@ func TestDatabaseRecycle(t *testing.T) { } func TestInvalidateCaches(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -410,6 +417,7 @@ func TestInvalidateCaches(t *testing.T) { } func TestGetLogs(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -458,6 +466,7 @@ func TestGetLogs(t *testing.T) { } func TestDownloadLogs(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -500,6 +509,7 @@ func TestDownloadLogs(t *testing.T) { } func TestPostLog(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -542,6 +552,7 @@ func TestPostLog(t *testing.T) { } func TestGetAnalyticsOld(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -595,9 +606,12 @@ func TestGetAnalyticsOld(t *testing.T) { require.NoError(t, err) assert.Equal(t, "total_websocket_connections", rows2[5].Name) assert.Equal(t, float64(1), rows2[5].Value) - WebSocketClient.Close() + // Give it a second for internal webhub counters to be updated after the client disconnects. + // Test can be flaky otherwise. + time.Sleep(time.Second) + rows2, _, err = th.SystemAdminClient.GetAnalyticsOld(context.Background(), "standard", "") require.NoError(t, err) assert.Equal(t, "total_websocket_connections", rows2[5].Name) @@ -612,6 +626,7 @@ func TestGetAnalyticsOld(t *testing.T) { } func TestS3TestConnection(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -697,6 +712,7 @@ func TestS3TestConnection(t *testing.T) { } func TestSupportedTimezones(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -709,6 +725,7 @@ func TestSupportedTimezones(t *testing.T) { } func TestRedirectLocation(t *testing.T) { + mainHelper.Parallel(t) expected := "https://mattermost.com/wp-content/themes/mattermostv2/img/logo-light.svg" testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { @@ -799,6 +816,7 @@ func TestRedirectLocation(t *testing.T) { } func TestSetServerBusy(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -819,6 +837,7 @@ func TestSetServerBusy(t *testing.T) { } func TestSetServerBusyInvalidParam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -834,6 +853,7 @@ func TestSetServerBusyInvalidParam(t *testing.T) { } func TestClearServerBusy(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -854,6 +874,7 @@ func TestClearServerBusy(t *testing.T) { } func TestGetServerBusy(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -874,6 +895,7 @@ func TestGetServerBusy(t *testing.T) { } func TestServerBusy503(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -917,6 +939,7 @@ func TestServerBusy503(t *testing.T) { } func TestPushNotificationAck(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() api, err := Init(th.Server) require.NoError(t, err) @@ -1010,6 +1033,7 @@ func TestPushNotificationAck(t *testing.T) { } func TestCompleteOnboarding(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1143,6 +1167,7 @@ func TestCompleteOnboarding(t *testing.T) { } func TestGetAppliedSchemaMigrations(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1170,6 +1195,7 @@ func TestGetAppliedSchemaMigrations(t *testing.T) { } func TestCheckHasNilFields(t *testing.T) { + mainHelper.Parallel(t) t.Run("check if the empty struct has nil fields", func(t *testing.T) { var s model.FileSettings res := checkHasNilFields(&s) diff --git a/server/channels/api4/team_test.go b/server/channels/api4/team_test.go index 4667b82643..303a58c8d8 100644 --- a/server/channels/api4/team_test.go +++ b/server/channels/api4/team_test.go @@ -28,6 +28,7 @@ import ( ) func TestCreateTeam(t *testing.T) { + // Test cannot easily run in parallel because it relies on (and mutates) i18n package translations. th := Setup(t) defer th.TearDown() @@ -198,6 +199,7 @@ func TestCreateTeam(t *testing.T) { } func TestCreateTeamSanitization(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -235,6 +237,7 @@ func TestCreateTeamSanitization(t *testing.T) { } func TestGetTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -291,6 +294,7 @@ func TestGetTeam(t *testing.T) { } func TestGetTeamSanitization(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -360,6 +364,7 @@ func TestGetTeamSanitization(t *testing.T) { } func TestGetTeamUnread(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -396,6 +401,7 @@ func TestGetTeamUnread(t *testing.T) { } func TestUpdateTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -580,6 +586,7 @@ func TestUpdateTeamPrivacyInvitePermissions(t *testing.T) { } func TestUpdateTeamSanitization(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -612,6 +619,7 @@ func TestUpdateTeamSanitization(t *testing.T) { } func TestPatchTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -880,6 +888,7 @@ func TestPatchTeam(t *testing.T) { } func TestRestoreTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -1007,6 +1016,7 @@ func TestRestoreTeam(t *testing.T) { } func TestPatchTeamSanitization(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1039,6 +1049,7 @@ func TestPatchTeamSanitization(t *testing.T) { } func TestUpdateTeamPrivacy(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -1131,6 +1142,7 @@ func TestUpdateTeamPrivacy(t *testing.T) { } func TestTeamUnicodeNames(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -1201,6 +1213,7 @@ func TestTeamUnicodeNames(t *testing.T) { } func TestRegenerateTeamInviteId(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -1225,6 +1238,7 @@ func TestRegenerateTeamInviteId(t *testing.T) { } func TestSoftDeleteTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1262,6 +1276,7 @@ func TestSoftDeleteTeam(t *testing.T) { } func TestPermanentDeleteTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1313,6 +1328,7 @@ func TestPermanentDeleteTeam(t *testing.T) { } func TestGetAllTeams(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() th.LoginSystemManager() defer th.TearDown() @@ -1579,6 +1595,7 @@ func TestGetAllTeams(t *testing.T) { } func TestGetAllTeamsSanitization(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1640,6 +1657,7 @@ func TestGetAllTeamsSanitization(t *testing.T) { } func TestGetTeamByName(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() team := th.BasicTeam @@ -1694,6 +1712,7 @@ func TestGetTeamByName(t *testing.T) { } func TestGetTeamByNameSanitization(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1764,6 +1783,7 @@ func TestGetTeamByNameSanitization(t *testing.T) { } func TestSearchAllTeams(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() th.LoginSystemManager() defer th.TearDown() @@ -1871,6 +1891,7 @@ func TestSearchAllTeams(t *testing.T) { } func TestSearchAllTeamsPaged(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() commonRandom := model.NewId() @@ -2000,6 +2021,7 @@ func TestSearchAllTeamsPaged(t *testing.T) { } func TestSearchAllTeamsSanitization(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2070,6 +2092,7 @@ func TestSearchAllTeamsSanitization(t *testing.T) { } func TestGetTeamsForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -2112,6 +2135,7 @@ func TestGetTeamsForUser(t *testing.T) { } func TestGetTeamsForUserSanitization(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2211,6 +2235,7 @@ func TestGetTeamsForUserSanitization(t *testing.T) { } func TestGetTeamMember(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -2249,6 +2274,7 @@ func TestGetTeamMember(t *testing.T) { } func TestGetTeamMembers(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -2321,6 +2347,7 @@ func TestGetTeamMembers(t *testing.T) { } func TestGetTeamMembersForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -2363,6 +2390,7 @@ func TestGetTeamMembersForUser(t *testing.T) { } func TestGetTeamMembersByIds(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -2400,6 +2428,7 @@ func TestGetTeamMembersByIds(t *testing.T) { } func TestAddTeamMember(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -2688,6 +2717,7 @@ func TestAddTeamMemberGuestPermissions(t *testing.T) { } func TestAddTeamMemberMyself(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -2778,6 +2808,7 @@ func TestAddTeamMemberMyself(t *testing.T) { } func TestAddTeamMembersDomainConstrained(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.SystemAdminClient @@ -2838,6 +2869,7 @@ func TestAddTeamMembersDomainConstrained(t *testing.T) { } func TestAddTeamMembers(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3037,6 +3069,7 @@ func TestAddTeamMembersGuestPermissions(t *testing.T) { } func TestRemoveTeamMember(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3104,6 +3137,7 @@ func TestRemoveTeamMember(t *testing.T) { } func TestRemoveTeamMemberEvents(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3138,6 +3172,7 @@ func TestRemoveTeamMemberEvents(t *testing.T) { } func TestGetTeamStats(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3189,6 +3224,7 @@ func TestGetTeamStats(t *testing.T) { } func TestUpdateTeamMemberRoles(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3268,6 +3304,7 @@ func TestUpdateTeamMemberRoles(t *testing.T) { } func TestUpdateTeamMemberSchemeRoles(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() enableGuestAccounts := *th.App.Config().GuestAccountsSettings.Enable @@ -3410,6 +3447,7 @@ func TestUpdateTeamMemberSchemeRoles(t *testing.T) { } func TestGetMyTeamsUnread(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3442,6 +3480,7 @@ func TestGetMyTeamsUnread(t *testing.T) { } func TestTeamExists(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3538,6 +3577,7 @@ func TestTeamExists(t *testing.T) { } func TestImportTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3629,6 +3669,7 @@ func TestImportTeam(t *testing.T) { } func TestValidateUserPermissionsOnChannels(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3657,6 +3698,7 @@ func TestValidateUserPermissionsOnChannels(t *testing.T) { } func TestInviteUsersToTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3826,6 +3868,7 @@ func TestInviteUsersToTeam(t *testing.T) { } func TestInviteGuestsToTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3971,6 +4014,7 @@ func TestInviteGuestsToTeam(t *testing.T) { } func TestInviteGuest(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() guest1 := th.GenerateTestEmail() @@ -4017,6 +4061,7 @@ func TestInviteGuest(t *testing.T) { } func TestGetTeamInviteInfo(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -4042,6 +4087,7 @@ func TestGetTeamInviteInfo(t *testing.T) { } func TestSetTeamIcon(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -4100,6 +4146,7 @@ func TestSetTeamIcon(t *testing.T) { } func TestGetTeamIcon(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -4119,6 +4166,7 @@ func TestGetTeamIcon(t *testing.T) { } func TestRemoveTeamIcon(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -4158,6 +4206,7 @@ func TestRemoveTeamIcon(t *testing.T) { } func TestUpdateTeamScheme(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -4238,6 +4287,7 @@ func TestUpdateTeamScheme(t *testing.T) { } func TestTeamMembersMinusGroupMembers(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -4331,6 +4381,7 @@ func TestTeamMembersMinusGroupMembers(t *testing.T) { } func TestInvalidateAllEmailInvites(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/api4/terms_of_service_test.go b/server/channels/api4/terms_of_service_test.go index 252082dcb3..f5ea422d7e 100644 --- a/server/channels/api4/terms_of_service_test.go +++ b/server/channels/api4/terms_of_service_test.go @@ -14,6 +14,7 @@ import ( ) func TestGetTermsOfService(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -31,6 +32,7 @@ func TestGetTermsOfService(t *testing.T) { } func TestCreateTermsOfService(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -40,6 +42,7 @@ func TestCreateTermsOfService(t *testing.T) { } func TestCreateTermsOfServiceAdminUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.SystemAdminClient diff --git a/server/channels/api4/upload_test.go b/server/channels/api4/upload_test.go index 0c334818f1..dc5aa9e9ef 100644 --- a/server/channels/api4/upload_test.go +++ b/server/channels/api4/upload_test.go @@ -20,6 +20,7 @@ import ( ) func TestCreateUpload(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -119,6 +120,7 @@ func TestCreateUpload(t *testing.T) { } func TestGetUpload(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -163,6 +165,7 @@ func TestGetUpload(t *testing.T) { } func TestGetUploadsForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -210,6 +213,7 @@ func TestGetUploadsForUser(t *testing.T) { } func TestUploadData(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() if *th.App.Config().FileSettings.DriverName == "" { @@ -335,6 +339,7 @@ func TestUploadData(t *testing.T) { } func TestUploadDataMultipart(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() if *th.App.Config().FileSettings.DriverName == "" { diff --git a/server/channels/api4/usage_test.go b/server/channels/api4/usage_test.go index 6f5c764778..c2ecc5b904 100644 --- a/server/channels/api4/usage_test.go +++ b/server/channels/api4/usage_test.go @@ -15,6 +15,7 @@ import ( ) func TestGetPostsUsage(t *testing.T) { + mainHelper.Parallel(t) t.Run("unauthenticated users can not access", func(t *testing.T) { th := Setup(t) defer th.TearDown() @@ -54,6 +55,7 @@ func TestGetPostsUsage(t *testing.T) { } func TestGetStorageUsage(t *testing.T) { + mainHelper.Parallel(t) t.Run("unauthenticated users cannot access", func(t *testing.T) { th := Setup(t) defer th.TearDown() @@ -69,6 +71,7 @@ func TestGetStorageUsage(t *testing.T) { } func TestGetTeamsUsage(t *testing.T) { + mainHelper.Parallel(t) t.Run("unauthenticated users can not access", func(t *testing.T) { th := Setup(t) defer th.TearDown() diff --git a/server/channels/api4/user_test.go b/server/channels/api4/user_test.go index e531311c42..0b866b2972 100644 --- a/server/channels/api4/user_test.go +++ b/server/channels/api4/user_test.go @@ -35,6 +35,7 @@ import ( ) func TestCreateUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -167,6 +168,7 @@ func TestCreateUser(t *testing.T) { } func TestCreateUserPasswordValidation(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -378,6 +380,7 @@ func TestUserLoginAudit(t *testing.T) { } func TestCreateUserInputFilter(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -479,6 +482,7 @@ func TestCreateUserInputFilter(t *testing.T) { } func TestCreateUserWithToken(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -739,6 +743,7 @@ func TestCreateUserWithToken(t *testing.T) { } func TestCreateUserWebSocketEvent(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -808,6 +813,7 @@ func TestCreateUserWebSocketEvent(t *testing.T) { } func TestCreateUserWithInviteId(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -972,6 +978,7 @@ func TestCreateUserWithInviteId(t *testing.T) { } func TestGetMe(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -988,6 +995,7 @@ func TestGetMe(t *testing.T) { } func TestGetUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1045,6 +1053,7 @@ func TestGetUser(t *testing.T) { } func TestGetUserWithAcceptedTermsOfServiceForOtherUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1077,6 +1086,7 @@ func TestGetUserWithAcceptedTermsOfServiceForOtherUser(t *testing.T) { } func TestGetUserWithAcceptedTermsOfService(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1106,6 +1116,7 @@ func TestGetUserWithAcceptedTermsOfService(t *testing.T) { } func TestGetUserWithAcceptedTermsOfServiceWithAdminUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() th.LoginSystemAdmin() defer th.TearDown() @@ -1136,6 +1147,7 @@ func TestGetUserWithAcceptedTermsOfServiceWithAdminUser(t *testing.T) { } func TestGetBotUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1171,6 +1183,7 @@ func TestGetBotUser(t *testing.T) { } func TestGetUserByUsername(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1222,6 +1235,7 @@ func TestGetUserByUsername(t *testing.T) { } func TestGetUserByUsernameWithAcceptedTermsOfService(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1248,6 +1262,7 @@ func TestGetUserByUsernameWithAcceptedTermsOfService(t *testing.T) { } func TestSaveUserTermsOfService(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1259,6 +1274,7 @@ func TestSaveUserTermsOfService(t *testing.T) { } func TestGetUserByEmail(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1395,6 +1411,7 @@ func TestGetUserByEmail(t *testing.T) { // This test can flake if two calls to model.NewId can return the same value. // Not much can be done about it. func TestSearchUsers(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1633,6 +1650,7 @@ func findUserInList(id string, users []*model.User) bool { //nolint:unused } func TestAutocompleteUsersInChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() teamId := th.BasicTeam.Id @@ -1781,6 +1799,7 @@ func TestAutocompleteUsersInChannel(t *testing.T) { } func TestAutocompleteUsersInTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() teamId := th.BasicTeam.Id @@ -1854,6 +1873,7 @@ func TestAutocompleteUsersInTeam(t *testing.T) { } func TestAutocompleteUsers(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() username := th.BasicUser.Username @@ -1922,6 +1942,7 @@ func TestAutocompleteUsers(t *testing.T) { } func TestGetProfileImage(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1960,6 +1981,7 @@ func TestGetProfileImage(t *testing.T) { } func TestGetUsersByIds(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2010,6 +2032,7 @@ func TestGetUsersByIds(t *testing.T) { } func TestGetUsersByIdsWithOptions(t *testing.T) { + mainHelper.Parallel(t) t.Run("should only return specified users that have been updated since the given time", func(t *testing.T) { th := Setup(t) defer th.TearDown() @@ -2036,6 +2059,7 @@ func TestGetUsersByIdsWithOptions(t *testing.T) { } func TestGetUsersByGroupChannelIds(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2069,6 +2093,7 @@ func TestGetUsersByGroupChannelIds(t *testing.T) { } func TestGetUsersByUsernames(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2098,6 +2123,7 @@ func TestGetUsersByUsernames(t *testing.T) { } func TestGetTotalUsersStat(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -2113,6 +2139,7 @@ func TestGetTotalUsersStat(t *testing.T) { } func TestUpdateUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -2190,6 +2217,7 @@ func TestUpdateUser(t *testing.T) { } func TestUpdateAdminUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2212,6 +2240,7 @@ func TestUpdateAdminUser(t *testing.T) { } func TestUpdateBotUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2233,6 +2262,7 @@ func TestUpdateBotUser(t *testing.T) { } func TestPatchUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2348,6 +2378,7 @@ func TestPatchUser(t *testing.T) { } func TestPatchBotUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2369,6 +2400,7 @@ func TestPatchBotUser(t *testing.T) { } func TestPatchAdminUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2392,6 +2424,7 @@ func TestPatchAdminUser(t *testing.T) { } func TestUserUnicodeNames(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() client := th.Client @@ -2459,6 +2492,7 @@ func TestUserUnicodeNames(t *testing.T) { } func TestUpdateUserAuth(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -2509,6 +2543,7 @@ func TestUpdateUserAuth(t *testing.T) { } func TestDeleteUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2560,6 +2595,7 @@ func TestDeleteUser(t *testing.T) { } func TestDeleteBotUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2575,6 +2611,7 @@ func TestDeleteBotUser(t *testing.T) { } func TestPermanentDeleteUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2614,6 +2651,7 @@ func TestPermanentDeleteUser(t *testing.T) { } func TestPermanentDeleteAllUsers(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2681,6 +2719,7 @@ func TestPermanentDeleteAllUsers(t *testing.T) { } func TestUpdateUserRoles(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2733,7 +2772,9 @@ func assertWebsocketEventUserUpdatedWithEmail(t *testing.T, client *model.WebSoc } func TestUpdateUserActive(t *testing.T) { + mainHelper.Parallel(t) t.Run("basic tests", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2791,6 +2832,7 @@ func TestUpdateUserActive(t *testing.T) { }) t.Run("websocket events", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2829,6 +2871,7 @@ func TestUpdateUserActive(t *testing.T) { }) t.Run("activate guest should fail when guests feature is disable", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2856,6 +2899,7 @@ func TestUpdateUserActive(t *testing.T) { }) t.Run("activate guest should work when guests feature is enabled", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2880,6 +2924,7 @@ func TestUpdateUserActive(t *testing.T) { }) t.Run("update active status of LDAP user should fail", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2906,6 +2951,7 @@ func TestUpdateUserActive(t *testing.T) { } func TestGetUsers(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -2955,6 +3001,7 @@ func TestGetUsers(t *testing.T) { } func TestGetNewUsersInTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() teamId := th.BasicTeam.Id @@ -2981,6 +3028,7 @@ func TestGetNewUsersInTeam(t *testing.T) { } func TestGetRecentlyActiveUsersInTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() teamId := th.BasicTeam.Id @@ -3007,6 +3055,7 @@ func TestGetRecentlyActiveUsersInTeam(t *testing.T) { } func TestGetActiveUsersInTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() teamId := th.BasicTeam.Id @@ -3039,6 +3088,7 @@ func TestGetActiveUsersInTeam(t *testing.T) { } func TestGetUsersWithoutTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3089,6 +3139,7 @@ func TestGetUsersWithoutTeam(t *testing.T) { } func TestGetUsersInTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() teamId := th.BasicTeam.Id @@ -3132,6 +3183,7 @@ func TestGetUsersInTeam(t *testing.T) { } func TestGetUsersNotInTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic().DeleteBots() defer th.TearDown() teamId := th.BasicTeam.Id @@ -3176,6 +3228,7 @@ func TestGetUsersNotInTeam(t *testing.T) { } func TestGetUsersInChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() channelId := th.BasicChannel.Id @@ -3262,6 +3315,7 @@ func TestGetUsersInChannel(t *testing.T) { } func TestGetUsersNotInChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() teamId := th.BasicTeam.Id @@ -3301,6 +3355,7 @@ func TestGetUsersNotInChannel(t *testing.T) { } func TestGetUsersInGroup(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3383,6 +3438,7 @@ func TestGetUsersInGroup(t *testing.T) { } func TestGetUsersInGroupByDisplayName(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3440,6 +3496,7 @@ func TestGetUsersInGroupByDisplayName(t *testing.T) { } func TestUpdateUserMfa(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3485,6 +3542,7 @@ func TestUpdateUserMfa(t *testing.T) { } func TestUserLoginMFAFlow(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3550,6 +3608,7 @@ func TestUserLoginMFAFlow(t *testing.T) { } func TestGenerateMfaSecret(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3591,6 +3650,7 @@ func TestGenerateMfaSecret(t *testing.T) { } func TestUpdateUserPassword(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3660,6 +3720,7 @@ func TestUpdateUserPassword(t *testing.T) { } func TestUpdateUserHashedPassword(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -3765,6 +3826,7 @@ func TestResetPassword(t *testing.T) { } func TestGetSessions(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3808,6 +3870,7 @@ func TestGetSessions(t *testing.T) { } func TestRevokeSessions(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3867,6 +3930,7 @@ func TestRevokeSessions(t *testing.T) { } func TestRevokeAllSessions(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3909,6 +3973,8 @@ func TestRevokeAllSessions(t *testing.T) { } func TestRevokeSessionsFromAllUsers(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() @@ -3955,6 +4021,7 @@ func TestRevokeSessionsFromAllUsers(t *testing.T) { } func TestAttachDeviceId(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -4076,6 +4143,7 @@ func TestAttachDeviceId(t *testing.T) { } func TestGetUserAudits(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() user := th.BasicUser @@ -4101,6 +4169,7 @@ func TestGetUserAudits(t *testing.T) { } func TestVerifyUserEmail(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -4125,6 +4194,7 @@ func TestVerifyUserEmail(t *testing.T) { } func TestSendVerificationEmail(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -4146,6 +4216,7 @@ func TestSendVerificationEmail(t *testing.T) { } func TestSetProfileImage(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() user := th.BasicUser @@ -4201,6 +4272,7 @@ func TestSetProfileImage(t *testing.T) { } func TestSetDefaultProfileImage(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() user := th.BasicUser @@ -4256,6 +4328,7 @@ func TestSetDefaultProfileImage(t *testing.T) { } func TestLogin(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() _, err := th.Client.Logout(context.Background()) @@ -4373,6 +4446,7 @@ func TestLoginWithLag(t *testing.T) { } func TestLoginCookies(t *testing.T) { + mainHelper.Parallel(t) t.Run("should return cookies with X-Requested-With header", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -4550,6 +4624,7 @@ func TestLoginCookies(t *testing.T) { } func TestCBALogin(t *testing.T) { + mainHelper.Parallel(t) t.Run("primary", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -4666,6 +4741,7 @@ func TestCBALogin(t *testing.T) { } func TestSwitchAccount(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -4925,7 +5001,10 @@ func assertInvalidToken(t *testing.T, th *TestHelper, token *model.UserAccessTok } func TestCreateUserAccessToken(t *testing.T) { + mainHelper.Parallel(t) + t.Run("create token without permission", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -4937,6 +5016,7 @@ func TestCreateUserAccessToken(t *testing.T) { }) t.Run("system admin and local mode can create access token", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -4956,6 +5036,7 @@ func TestCreateUserAccessToken(t *testing.T) { }) t.Run("create token for invalid user id", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -4969,6 +5050,7 @@ func TestCreateUserAccessToken(t *testing.T) { }) t.Run("create token with invalid value", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -4982,6 +5064,7 @@ func TestCreateUserAccessToken(t *testing.T) { }) t.Run("create token with user access tokens disabled", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -4997,6 +5080,7 @@ func TestCreateUserAccessToken(t *testing.T) { }) t.Run("create user access token", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5017,6 +5101,7 @@ func TestCreateUserAccessToken(t *testing.T) { }) t.Run("create user access token as second user, without permission", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5028,6 +5113,7 @@ func TestCreateUserAccessToken(t *testing.T) { }) t.Run("create user access token for another user, with permission", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5047,6 +5133,7 @@ func TestCreateUserAccessToken(t *testing.T) { }) t.Run("create user access token for system admin, as system user manager", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5061,6 +5148,7 @@ func TestCreateUserAccessToken(t *testing.T) { }) t.Run("create user access token for basic user as a system admin", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5077,6 +5165,7 @@ func TestCreateUserAccessToken(t *testing.T) { }) t.Run("create user access token for remote user as a system admin", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5097,6 +5186,7 @@ func TestCreateUserAccessToken(t *testing.T) { }) t.Run("create access token as oauth session", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5112,6 +5202,7 @@ func TestCreateUserAccessToken(t *testing.T) { }) t.Run("create access token for bot created by user", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5158,6 +5249,7 @@ func TestCreateUserAccessToken(t *testing.T) { }) t.Run("create access token for bot created by another user, only having MANAGE_BOTS permission", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5205,7 +5297,10 @@ func TestCreateUserAccessToken(t *testing.T) { } func TestGetUserAccessToken(t *testing.T) { + mainHelper.Parallel(t) + t.Run("get for invalid user id", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5217,6 +5312,7 @@ func TestGetUserAccessToken(t *testing.T) { }) t.Run("get for unknown user id", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5228,6 +5324,7 @@ func TestGetUserAccessToken(t *testing.T) { }) t.Run("get my token", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5248,6 +5345,7 @@ func TestGetUserAccessToken(t *testing.T) { }) t.Run("get user token as system admin", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5269,6 +5367,7 @@ func TestGetUserAccessToken(t *testing.T) { }) t.Run("get token for bot created by user", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5322,6 +5421,7 @@ func TestGetUserAccessToken(t *testing.T) { }) t.Run("get token for bot created by another user", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5374,7 +5474,10 @@ func TestGetUserAccessToken(t *testing.T) { } func TestGetUserAccessTokensForUser(t *testing.T) { + mainHelper.Parallel(t) + t.Run("multiple tokens, offset 0, limit 100", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5401,6 +5504,7 @@ func TestGetUserAccessTokensForUser(t *testing.T) { }) t.Run("multiple tokens, offset 1, limit 1", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5428,7 +5532,10 @@ func TestGetUserAccessTokensForUser(t *testing.T) { } func TestGetUserAccessTokens(t *testing.T) { + mainHelper.Parallel(t) + t.Run("GetUserAccessTokens, not a system admin", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5443,6 +5550,7 @@ func TestGetUserAccessTokens(t *testing.T) { }) t.Run("GetUserAccessTokens, as a system admin, page 1, perPage 1", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5464,6 +5572,7 @@ func TestGetUserAccessTokens(t *testing.T) { }) t.Run("GetUserAccessTokens, as a system admin, page 0, perPage 2", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5486,6 +5595,8 @@ func TestGetUserAccessTokens(t *testing.T) { } func TestSearchUserAccessToken(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() @@ -5524,7 +5635,10 @@ func TestSearchUserAccessToken(t *testing.T) { } func TestRevokeUserAccessToken(t *testing.T) { + mainHelper.Parallel(t) + t.Run("revoke user token", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5545,6 +5659,7 @@ func TestRevokeUserAccessToken(t *testing.T) { }) t.Run("revoke token belonging to another user", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5559,6 +5674,7 @@ func TestRevokeUserAccessToken(t *testing.T) { }) t.Run("revoke token for bot created by user", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5608,6 +5724,7 @@ func TestRevokeUserAccessToken(t *testing.T) { }) t.Run("revoke token for bot created by another user", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5656,7 +5773,10 @@ func TestRevokeUserAccessToken(t *testing.T) { } func TestDisableUserAccessToken(t *testing.T) { + mainHelper.Parallel(t) + t.Run("disable user token", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5675,6 +5795,7 @@ func TestDisableUserAccessToken(t *testing.T) { }) t.Run("disable token belonging to another user", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5689,6 +5810,7 @@ func TestDisableUserAccessToken(t *testing.T) { }) t.Run("disable token for bot created by user", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5786,7 +5908,9 @@ func TestDisableUserAccessToken(t *testing.T) { } func TestEnableUserAccessToken(t *testing.T) { + mainHelper.Parallel(t) t.Run("enable user token", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5810,6 +5934,7 @@ func TestEnableUserAccessToken(t *testing.T) { }) t.Run("enable token belonging to another user", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5827,6 +5952,7 @@ func TestEnableUserAccessToken(t *testing.T) { }) t.Run("enable token for bot created by user", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5879,6 +6005,7 @@ func TestEnableUserAccessToken(t *testing.T) { }) t.Run("enable token for bot created by another user", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5930,6 +6057,8 @@ func TestEnableUserAccessToken(t *testing.T) { } func TestUserAccessTokenInactiveUser(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() @@ -5955,6 +6084,8 @@ func TestUserAccessTokenInactiveUser(t *testing.T) { } func TestUserAccessTokenDisableConfig(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() @@ -5984,6 +6115,8 @@ func TestUserAccessTokenDisableConfig(t *testing.T) { } func TestUserAccessTokenDisableConfigBotsExcluded(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t) defer th.TearDown() @@ -6009,6 +6142,8 @@ func TestUserAccessTokenDisableConfigBotsExcluded(t *testing.T) { } func TestGetUsersByStatus(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t) defer th.TearDown() @@ -6116,6 +6251,8 @@ func TestGetUsersByStatus(t *testing.T) { } func TestRegisterTermsOfServiceAction(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() @@ -6133,6 +6270,8 @@ func TestRegisterTermsOfServiceAction(t *testing.T) { } func TestGetUserTermsOfService(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() @@ -6154,6 +6293,8 @@ func TestGetUserTermsOfService(t *testing.T) { } func TestLoginErrorMessage(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() @@ -6210,6 +6351,8 @@ func TestLoginErrorMessage(t *testing.T) { } func TestLoginLockout(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() @@ -6258,6 +6401,8 @@ func TestLoginLockout(t *testing.T) { } func TestDemoteUserToGuest(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() @@ -6332,6 +6477,8 @@ func TestDemoteUserToGuest(t *testing.T) { } func TestPromoteGuestToUser(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() @@ -6387,6 +6534,8 @@ func TestPromoteGuestToUser(t *testing.T) { } func TestVerifyUserEmailWithoutToken(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t) defer th.TearDown() @@ -6417,6 +6566,7 @@ func TestVerifyUserEmailWithoutToken(t *testing.T) { } func TestGetKnownUsers(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -6534,6 +6684,7 @@ func TestGetKnownUsers(t *testing.T) { } func TestPublishUserTyping(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -6608,6 +6759,7 @@ func TestPublishUserTyping(t *testing.T) { } func TestConvertUserToBot(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -6654,6 +6806,7 @@ func TestConvertUserToBot(t *testing.T) { } func TestGetChannelMembersWithTeamData(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -6685,6 +6838,7 @@ func TestGetChannelMembersWithTeamData(t *testing.T) { } func TestMigrateAuthToLDAP(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -6700,6 +6854,7 @@ func TestMigrateAuthToLDAP(t *testing.T) { } func TestMigrateAuthToSAML(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -6715,6 +6870,7 @@ func TestMigrateAuthToSAML(t *testing.T) { } func TestUpdatePassword(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -6777,6 +6933,7 @@ func TestUpdatePasswordAudit(t *testing.T) { } func TestGetThreadsForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -7246,6 +7403,7 @@ func TestGetThreadsForUser(t *testing.T) { } func TestThreadSocketEvents(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -7518,6 +7676,7 @@ func TestThreadSocketEvents(t *testing.T) { } func TestFollowThreads(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -7629,6 +7788,8 @@ func postAndCheck(t *testing.T, client *model.Client4, post *model.Post) (*model } func TestMaintainUnreadRepliesInThread(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() th.LinkUserToTeam(th.SystemAdminUser, th.BasicTeam) @@ -7691,6 +7852,7 @@ func TestMaintainUnreadRepliesInThread(t *testing.T) { } func TestThreadCounts(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -7738,6 +7900,7 @@ func TestThreadCounts(t *testing.T) { } func TestSingleThreadGet(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -7814,6 +7977,7 @@ func TestSingleThreadGet(t *testing.T) { } func TestMaintainUnreadMentionsInThread(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() th.LinkUserToTeam(th.SystemAdminUser, th.BasicTeam) @@ -7886,6 +8050,7 @@ func TestMaintainUnreadMentionsInThread(t *testing.T) { } func TestReadThreads(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -8016,6 +8181,7 @@ func TestReadThreads(t *testing.T) { } func TestMarkThreadUnreadMentionCount(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -8063,6 +8229,7 @@ func TestMarkThreadUnreadMentionCount(t *testing.T) { } func TestPatchAndUpdateWithProviderAttributes(t *testing.T) { + mainHelper.Parallel(t) t.Run("LDAP user", func(t *testing.T) { th := SetupEnterprise(t).InitBasic() defer th.TearDown() @@ -8156,6 +8323,7 @@ func TestPatchAndUpdateWithProviderAttributes(t *testing.T) { } func TestSetProfileImageWithProviderAttributes(t *testing.T) { + mainHelper.Parallel(t) data, err := testutils.ReadTestFile("test.png") require.NoError(t, err) @@ -8241,6 +8409,7 @@ func TestSetProfileImageWithProviderAttributes(t *testing.T) { } func TestGetUsersWithInvalidEmails(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.SystemAdminClient @@ -8289,6 +8458,7 @@ func TestGetUsersWithInvalidEmails(t *testing.T) { } func TestUserUpdateEvents(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -8333,6 +8503,7 @@ func TestUserUpdateEvents(t *testing.T) { } func TestLoginWithDesktopToken(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -8405,6 +8576,7 @@ func TestLoginWithDesktopToken(t *testing.T) { } func TestGetUsersByNames(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -8463,6 +8635,7 @@ func TestGetUsersByNames(t *testing.T) { } func TestGetFilteredUsersStats(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -8566,6 +8739,7 @@ func TestGetFilteredUsersStats(t *testing.T) { } func TestGetDefaultProfileImage(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -8635,6 +8809,7 @@ func TestGetDefaultProfileImage(t *testing.T) { } func TestGetUserThread(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -8755,6 +8930,7 @@ func TestGetUserThread(t *testing.T) { } func TestUpdateReadStateThreadByUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -8832,6 +9008,7 @@ func TestUpdateReadStateThreadByUser(t *testing.T) { } func TestSetUnreadThreadByPostId(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -8945,6 +9122,7 @@ func TestSetUnreadThreadByPostId(t *testing.T) { } func TestRevokeAllSessionsForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/api4/user_viewmembers_test.go b/server/channels/api4/user_viewmembers_test.go index ac292cf053..79b912898c 100644 --- a/server/channels/api4/user_viewmembers_test.go +++ b/server/channels/api4/user_viewmembers_test.go @@ -13,6 +13,7 @@ import ( ) func TestAPIRestrictedViewMembers(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/api4/webhook_test.go b/server/channels/api4/webhook_test.go index cd0247fa19..f98c037e26 100644 --- a/server/channels/api4/webhook_test.go +++ b/server/channels/api4/webhook_test.go @@ -14,6 +14,7 @@ import ( ) func TestCreateIncomingWebhook(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -108,6 +109,7 @@ func TestCreateIncomingWebhook(t *testing.T) { } func TestCreateIncomingWebhook_BypassTeamPermissions(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -145,6 +147,7 @@ func TestCreateIncomingWebhook_BypassTeamPermissions(t *testing.T) { } func TestGetIncomingWebhooks(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -223,6 +226,7 @@ func TestGetIncomingWebhooks(t *testing.T) { } func TestGetIncomingWebhooksListByUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() BasicClient := th.Client @@ -258,7 +262,7 @@ func TestGetIncomingWebhooksListByUser(t *testing.T) { assert.Equal(t, 2, len(adminHooks)) }) - //Re-check basic user that has no MANAGE_OTHERS permission + // Re-check basic user that has no MANAGE_OTHERS permission filteredHooks, _, err := BasicClient.GetIncomingWebhooks(context.Background(), 0, 1000, "") require.NoError(t, err) assert.Equal(t, 1, len(filteredHooks)) @@ -266,6 +270,7 @@ func TestGetIncomingWebhooksListByUser(t *testing.T) { } func TestGetIncomingWebhooksByTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() BasicClient := th.Client @@ -300,7 +305,7 @@ func TestGetIncomingWebhooksByTeam(t *testing.T) { assert.Equal(t, 2, len(adminHooks)) }) - //Re-check basic user that has no MANAGE_OTHERS permission + // Re-check basic user that has no MANAGE_OTHERS permission filteredHooks, _, err := BasicClient.GetIncomingWebhooksForTeam(context.Background(), th.BasicTeam.Id, 0, 1000, "") require.NoError(t, err) assert.Equal(t, 1, len(filteredHooks)) @@ -308,6 +313,7 @@ func TestGetIncomingWebhooksByTeam(t *testing.T) { } func TestGetIncomingWebhooksWithCount(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() BasicClient := th.Client @@ -362,6 +368,7 @@ func TestGetIncomingWebhooksWithCount(t *testing.T) { } func TestGetIncomingWebhook(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -398,13 +405,14 @@ func TestGetIncomingWebhook(t *testing.T) { } func TestDeleteIncomingWebhook(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = true }) - //var rhook *model.IncomingWebhook - //var hook *model.IncomingWebhook + // var rhook *model.IncomingWebhook + // var hook *model.IncomingWebhook th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { resp, err := client.DeleteIncomingWebhook(context.Background(), "abc") @@ -449,6 +457,7 @@ func TestDeleteIncomingWebhook(t *testing.T) { } func TestCreateOutgoingWebhook(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -533,6 +542,7 @@ func TestCreateOutgoingWebhook(t *testing.T) { } func TestGetOutgoingWebhooks(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -632,6 +642,7 @@ func TestGetOutgoingWebhooks(t *testing.T) { } func TestGetOutgoingWebhooksByTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -665,7 +676,7 @@ func TestGetOutgoingWebhooksByTeam(t *testing.T) { assert.Equal(t, 2, len(adminHooks)) }) - //Re-check basic user that has no MANAGE_OTHERS permission + // Re-check basic user that has no MANAGE_OTHERS permission filteredHooks, _, err := th.Client.GetOutgoingWebhooksForTeam(context.Background(), th.BasicTeam.Id, 0, 1000, "") require.NoError(t, err) assert.Equal(t, 1, len(filteredHooks)) @@ -673,6 +684,7 @@ func TestGetOutgoingWebhooksByTeam(t *testing.T) { } func TestGetOutgoingWebhooksByChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -706,7 +718,7 @@ func TestGetOutgoingWebhooksByChannel(t *testing.T) { assert.Equal(t, 2, len(adminHooks)) }) - //Re-check basic user that has no MANAGE_OTHERS permission + // Re-check basic user that has no MANAGE_OTHERS permission filteredHooks, _, err := th.Client.GetOutgoingWebhooksForChannel(context.Background(), th.BasicChannel.Id, 0, 1000, "") require.NoError(t, err) assert.Equal(t, 1, len(filteredHooks)) @@ -714,6 +726,7 @@ func TestGetOutgoingWebhooksByChannel(t *testing.T) { } func TestGetOutgoingWebhooksListByUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() th.LoginBasic() @@ -748,7 +761,7 @@ func TestGetOutgoingWebhooksListByUser(t *testing.T) { assert.Equal(t, 2, len(adminHooks)) }) - //Re-check basic user that has no MANAGE_OTHERS permission + // Re-check basic user that has no MANAGE_OTHERS permission filteredHooks, _, err := th.Client.GetOutgoingWebhooks(context.Background(), 0, 1000, "") require.NoError(t, err) assert.Equal(t, 1, len(filteredHooks)) @@ -756,6 +769,7 @@ func TestGetOutgoingWebhooksListByUser(t *testing.T) { } func TestGetOutgoingWebhook(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -791,6 +805,7 @@ func TestGetOutgoingWebhook(t *testing.T) { } func TestUpdateIncomingHook(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -834,7 +849,7 @@ func TestUpdateIncomingHook(t *testing.T) { require.Empty(t, updatedHook.Username, "Hook username was incorrectly updated") require.Empty(t, updatedHook.IconURL, "Hook icon was incorrectly updated") - //updatedHook, _ = th.App.GetIncomingWebhook(createdHook.Id) + // updatedHook, _ = th.App.GetIncomingWebhook(createdHook.Id) assert.Equal(t, updatedHook.ChannelId, createdHook.ChannelId) }, "UpdateIncomingHook, overrides disabled") @@ -862,7 +877,7 @@ func TestUpdateIncomingHook(t *testing.T) { require.Exactly(t, "username", updatedHook.Username, "Hook username is not updated") require.Exactly(t, "icon", updatedHook.IconURL, "Hook icon is not updated") - //updatedHook, _ = th.App.GetIncomingWebhook(createdHook.Id) + // updatedHook, _ = th.App.GetIncomingWebhook(createdHook.Id) assert.Equal(t, updatedHook.ChannelId, createdHook.ChannelId) }, "UpdateIncomingHook") @@ -993,6 +1008,7 @@ func TestUpdateIncomingHook(t *testing.T) { } func TestUpdateIncomingWebhook_BypassTeamPermissions(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1030,6 +1046,7 @@ func TestUpdateIncomingWebhook_BypassTeamPermissions(t *testing.T) { } func TestRegenOutgoingHookToken(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() client := th.Client @@ -1044,7 +1061,7 @@ func TestRegenOutgoingHookToken(t *testing.T) { require.Error(t, err) CheckBadRequestStatus(t, resp) - //investigate why is act weird on jenkins + // investigate why is act weird on jenkins // _, resp,_ = th.SystemAdminClient.RegenOutgoingHookToken(context.Background(), "") // CheckNotFoundStatus(t, resp) @@ -1063,6 +1080,7 @@ func TestRegenOutgoingHookToken(t *testing.T) { } func TestUpdateOutgoingHook(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1074,8 +1092,10 @@ func TestUpdateOutgoingHook(t *testing.T) { th.AddPermissionToRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamAdminRoleId) th.RemovePermissionFromRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamUserRoleId) - createdHook := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, - CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"cats"}} + createdHook := &model.OutgoingWebhook{ + ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, + CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"cats"}, + } th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { rcreatedHook, _, err := th.SystemAdminClient.CreateOutgoingWebhook(context.Background(), createdHook) @@ -1112,8 +1132,10 @@ func TestUpdateOutgoingHook(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOutgoingWebhooks = true }) th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { - hook2 := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, - CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"rats"}} + hook2 := &model.OutgoingWebhook{ + ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, + CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"rats"}, + } createdHook2, _, err := th.SystemAdminClient.CreateOutgoingWebhook(context.Background(), hook2) require.NoError(t, err) @@ -1145,8 +1167,10 @@ func TestUpdateOutgoingHook(t *testing.T) { }, "ModifyUpdateAt") th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { - nonExistentHook := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, - CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"rats"}} + nonExistentHook := &model.OutgoingWebhook{ + ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, + CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"rats"}, + } _, resp, err := client.UpdateOutgoingWebhook(context.Background(), nonExistentHook) require.Error(t, err) @@ -1168,8 +1192,10 @@ func TestUpdateOutgoingHook(t *testing.T) { }) th.AddPermissionToRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamUserRoleId) - hook2 := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, - CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"rats2"}} + hook2 := &model.OutgoingWebhook{ + ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, + CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"rats2"}, + } createdHook2, _, err := th.SystemAdminClient.CreateOutgoingWebhook(context.Background(), hook2) require.NoError(t, err) @@ -1195,13 +1221,17 @@ func TestUpdateOutgoingHook(t *testing.T) { }) th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { - firstHook := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, - CallbackURLs: []string{"http://someurl"}, TriggerWords: []string{"first"}} + firstHook := &model.OutgoingWebhook{ + ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, + CallbackURLs: []string{"http://someurl"}, TriggerWords: []string{"first"}, + } firstHook, _, err = th.SystemAdminClient.CreateOutgoingWebhook(context.Background(), firstHook) require.NoError(t, err) - baseHook := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, - CallbackURLs: []string{"http://someurl"}, TriggerWords: []string{"base"}} + baseHook := &model.OutgoingWebhook{ + ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, + CallbackURLs: []string{"http://someurl"}, TriggerWords: []string{"base"}, + } baseHook, _, err = th.SystemAdminClient.CreateOutgoingWebhook(context.Background(), baseHook) require.NoError(t, err) @@ -1273,6 +1303,7 @@ func TestUpdateOutgoingHook(t *testing.T) { } func TestUpdateOutgoingWebhook_BypassTeamPermissions(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1284,8 +1315,10 @@ func TestUpdateOutgoingWebhook_BypassTeamPermissions(t *testing.T) { th.AddPermissionToRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamAdminRoleId) th.AddPermissionToRole(model.PermissionManageOutgoingWebhooks.Id, model.TeamUserRoleId) - hook := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, - CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"rats2"}} + hook := &model.OutgoingWebhook{ + ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, + CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"rats2"}, + } rhook, _, err := th.Client.CreateOutgoingWebhook(context.Background(), hook) require.NoError(t, err) @@ -1308,6 +1341,7 @@ func TestUpdateOutgoingWebhook_BypassTeamPermissions(t *testing.T) { } func TestDeleteOutgoingHook(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1326,8 +1360,10 @@ func TestDeleteOutgoingHook(t *testing.T) { }, "WhenHookDoesNotExist") th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { - hook := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, - CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"cats"}} + hook := &model.OutgoingWebhook{ + ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, + CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"cats"}, + } rhook, _, err := th.SystemAdminClient.CreateOutgoingWebhook(context.Background(), hook) require.NoError(t, err) @@ -1342,8 +1378,10 @@ func TestDeleteOutgoingHook(t *testing.T) { }, "WhenHookExists") t.Run("WhenUserDoesNotHavePermissions", func(t *testing.T) { - hook := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, - CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"dogs"}} + hook := &model.OutgoingWebhook{ + ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, + CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"dogs"}, + } rhook, _, err := th.SystemAdminClient.CreateOutgoingWebhook(context.Background(), hook) require.NoError(t, err) diff --git a/server/channels/api4/websocket_norace_test.go b/server/channels/api4/websocket_norace_test.go index 399903a9c4..08a74adce7 100644 --- a/server/channels/api4/websocket_norace_test.go +++ b/server/channels/api4/websocket_norace_test.go @@ -19,6 +19,7 @@ import ( // because the websocket client is known to be racy and needs a big overhaul // to fix everything. func TestWebSocket(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() WebSocketClient, err := th.CreateWebSocketClient() diff --git a/server/channels/api4/websocket_test.go b/server/channels/api4/websocket_test.go index f9aab1051e..81ba4d06b2 100644 --- a/server/channels/api4/websocket_test.go +++ b/server/channels/api4/websocket_test.go @@ -21,6 +21,7 @@ import ( ) func TestWebSocketTrailingSlash(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -30,6 +31,7 @@ func TestWebSocketTrailingSlash(t *testing.T) { } func TestWebSocketEvent(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -95,6 +97,7 @@ func TestWebSocketEvent(t *testing.T) { } func TestCreateDirectChannelWithSocket(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -150,6 +153,7 @@ func TestCreateDirectChannelWithSocket(t *testing.T) { } func TestWebsocketOriginSecurity(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -200,6 +204,7 @@ func TestWebsocketOriginSecurity(t *testing.T) { } func TestWebSocketReconnectRace(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -234,6 +239,7 @@ func TestWebSocketReconnectRace(t *testing.T) { } func TestWebSocketSendBinary(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -273,6 +279,7 @@ func TestWebSocketSendBinary(t *testing.T) { } func TestWebSocketStatuses(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -412,6 +419,7 @@ func TestWebSocketStatuses(t *testing.T) { } func TestWebSocketPresence(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -442,6 +450,7 @@ func TestWebSocketPresence(t *testing.T) { } func TestWebSocketUpgrade(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/admin_test.go b/server/channels/app/admin_test.go index f77bda5ee6..ddd96c01f9 100644 --- a/server/channels/app/admin_test.go +++ b/server/channels/app/admin_test.go @@ -15,6 +15,7 @@ import ( ) func TestGetLatestVersion(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/app_test.go b/server/channels/app/app_test.go index 8e20c34c04..80f8284d44 100644 --- a/server/channels/app/app_test.go +++ b/server/channels/app/app_test.go @@ -40,6 +40,7 @@ func init() { } func TestUnitUpdateConfig(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -290,6 +291,7 @@ func TestDoEmojisPermissionsMigration(t *testing.T) { } func TestDBHealthCheckWriteAndDelete(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/authentication_test.go b/server/channels/app/authentication_test.go index a91d63473d..05b506af41 100644 --- a/server/channels/app/authentication_test.go +++ b/server/channels/app/authentication_test.go @@ -21,6 +21,7 @@ import ( ) func TestParseAuthTokenFromRequest(t *testing.T) { + mainHelper.Parallel(t) cases := []struct { header string cookie string @@ -63,6 +64,7 @@ func TestParseAuthTokenFromRequest(t *testing.T) { } func TestCheckPasswordAndAllCriteria(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/authorization_test.go b/server/channels/app/authorization_test.go index ac3228ec31..86ddd218bf 100644 --- a/server/channels/app/authorization_test.go +++ b/server/channels/app/authorization_test.go @@ -118,6 +118,7 @@ func TestSessionHasPermissionToAndNotRestrictedAdmin(t *testing.T) { } func TestCheckIfRolesGrantPermission(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -144,12 +145,14 @@ func TestCheckIfRolesGrantPermission(t *testing.T) { } func TestChannelRolesGrantPermission(t *testing.T) { + mainHelper.Parallel(t) testPermissionInheritance(t, func(t *testing.T, th *TestHelper, testData permissionInheritanceTestData) { require.Equal(t, testData.shouldHavePermission, th.App.RolesGrantPermission([]string{testData.channelRole.Name}, testData.permission.Id), "row: %+v\n", testData.truthTableRow) }) } func TestHasPermissionToTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -167,6 +170,7 @@ func TestHasPermissionToTeam(t *testing.T) { } func TestSessionHasPermissionToTeams(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -225,6 +229,7 @@ func TestSessionHasPermissionToTeams(t *testing.T) { } func TestSessionHasPermissionToChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -296,6 +301,7 @@ func TestSessionHasPermissionToChannel(t *testing.T) { } func TestSessionHasPermissionToChannels(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -444,6 +450,7 @@ func TestSessionHasPermissionToChannels(t *testing.T) { } func TestHasPermissionToUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -453,6 +460,7 @@ func TestHasPermissionToUser(t *testing.T) { } func TestSessionHasPermissionToManageBot(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -564,6 +572,7 @@ func TestSessionHasPermissionToManageBot(t *testing.T) { } func TestSessionHasPermissionToUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -614,6 +623,7 @@ func TestSessionHasPermissionToUser(t *testing.T) { } func TestSessionHasPermissionToManageUserOrBot(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -669,6 +679,7 @@ func TestSessionHasPermissionToManageUserOrBot(t *testing.T) { } func TestHasPermissionToCategory(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() session, err := th.App.CreateSession(th.Context, &model.Session{UserId: th.BasicUser.Id, Props: model.StringMap{}}) @@ -687,6 +698,7 @@ func TestHasPermissionToCategory(t *testing.T) { } func TestSessionHasPermissionToGroup(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -771,6 +783,7 @@ func TestSessionHasPermissionToGroup(t *testing.T) { } func TestHasPermissionToReadChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -885,6 +898,7 @@ func TestHasPermissionToReadChannel(t *testing.T) { } func TestSessionHasPermissionToChannelByPost(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -948,6 +962,7 @@ func TestSessionHasPermissionToChannelByPost(t *testing.T) { } func TestHasPermissionToChannelByPost(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/auto_responder_test.go b/server/channels/app/auto_responder_test.go index 7cc93541af..5834987e8e 100644 --- a/server/channels/app/auto_responder_test.go +++ b/server/channels/app/auto_responder_test.go @@ -14,6 +14,7 @@ import ( ) func TestSetAutoResponderStatus(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -55,6 +56,7 @@ func TestSetAutoResponderStatus(t *testing.T) { } func TestDisableAutoResponder(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -90,6 +92,7 @@ func TestDisableAutoResponder(t *testing.T) { } func TestSendAutoResponseIfNecessary(t *testing.T) { + mainHelper.Parallel(t) t.Run("should send auto response when enabled", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -110,7 +113,8 @@ func TestSendAutoResponseIfNecessary(t *testing.T) { savedPost, _ := th.App.CreatePost(th.Context, &model.Post{ ChannelId: channel.Id, Message: NewTestId(), - UserId: th.BasicUser.Id}, + UserId: th.BasicUser.Id, + }, th.BasicChannel, model.CreatePostFlags{SetOnline: true}) @@ -140,7 +144,8 @@ func TestSendAutoResponseIfNecessary(t *testing.T) { savedPost, _ := th.App.CreatePost(th.Context, &model.Post{ ChannelId: channel.Id, Message: NewTestId(), - UserId: th.BasicUser.Id}, + UserId: th.BasicUser.Id, + }, th.BasicChannel, model.CreatePostFlags{SetOnline: true}) @@ -157,7 +162,8 @@ func TestSendAutoResponseIfNecessary(t *testing.T) { savedPost, _ := th.App.CreatePost(th.Context, &model.Post{ ChannelId: th.BasicChannel.Id, Message: NewTestId(), - UserId: th.BasicUser.Id}, + UserId: th.BasicUser.Id, + }, th.BasicChannel, model.CreatePostFlags{SetOnline: true}) @@ -197,7 +203,8 @@ func TestSendAutoResponseIfNecessary(t *testing.T) { savedPost, _ := th.App.CreatePost(th.Context, &model.Post{ ChannelId: channel.Id, Message: NewTestId(), - UserId: botUser.Id}, + UserId: botUser.Id, + }, th.BasicChannel, model.CreatePostFlags{SetOnline: true}) @@ -249,6 +256,7 @@ func TestSendAutoResponseIfNecessary(t *testing.T) { } func TestSendAutoResponseSuccess(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -269,7 +277,8 @@ func TestSendAutoResponseSuccess(t *testing.T) { savedPost, _ := th.App.CreatePost(th.Context, &model.Post{ ChannelId: th.BasicChannel.Id, Message: "zz" + model.NewId() + "a", - UserId: th.BasicUser.Id}, + UserId: th.BasicUser.Id, + }, th.BasicChannel, model.CreatePostFlags{SetOnline: true}) @@ -292,6 +301,7 @@ func TestSendAutoResponseSuccess(t *testing.T) { } func TestSendAutoResponseSuccessOnThread(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -312,7 +322,8 @@ func TestSendAutoResponseSuccessOnThread(t *testing.T) { parentPost, _ := th.App.CreatePost(th.Context, &model.Post{ ChannelId: th.BasicChannel.Id, Message: "zz" + model.NewId() + "a", - UserId: th.BasicUser.Id}, + UserId: th.BasicUser.Id, + }, th.BasicChannel, model.CreatePostFlags{SetOnline: true}) @@ -344,6 +355,7 @@ func TestSendAutoResponseSuccessOnThread(t *testing.T) { } func TestSendAutoResponseFailure(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -364,7 +376,8 @@ func TestSendAutoResponseFailure(t *testing.T) { savedPost, _ := th.App.CreatePost(th.Context, &model.Post{ ChannelId: th.BasicChannel.Id, Message: "zz" + model.NewId() + "a", - UserId: th.BasicUser.Id}, + UserId: th.BasicUser.Id, + }, th.BasicChannel, model.CreatePostFlags{SetOnline: true}) diff --git a/server/channels/app/bot_test.go b/server/channels/app/bot_test.go index e011c7a795..9dd4cf8156 100644 --- a/server/channels/app/bot_test.go +++ b/server/channels/app/bot_test.go @@ -15,6 +15,7 @@ import ( ) func TestCreateBot(t *testing.T) { + mainHelper.Parallel(t) t.Run("invalid bot", func(t *testing.T) { t.Run("relative to user", func(t *testing.T) { th := Setup(t).InitBasic() @@ -116,6 +117,7 @@ func TestCreateBot(t *testing.T) { } func TestEnsureBot(t *testing.T) { + mainHelper.Parallel(t) t.Run("ensure bot should pass if already exist bot user", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -190,6 +192,7 @@ func TestEnsureBot(t *testing.T) { } func TestPatchBot(t *testing.T) { + mainHelper.Parallel(t) t.Run("invalid patch for user", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -306,6 +309,7 @@ func TestPatchBot(t *testing.T) { } func TestGetBot(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -376,6 +380,7 @@ func TestGetBot(t *testing.T) { } func TestGetBots(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).DeleteBots() defer th.TearDown() @@ -586,6 +591,7 @@ func TestGetBots(t *testing.T) { } func TestUpdateBotActive(t *testing.T) { + mainHelper.Parallel(t) t.Run("unknown bot", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -631,6 +637,7 @@ func TestUpdateBotActive(t *testing.T) { } func TestPermanentDeleteBot(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -649,6 +656,7 @@ func TestPermanentDeleteBot(t *testing.T) { } func TestDisableUserBots(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -710,6 +718,7 @@ func TestDisableUserBots(t *testing.T) { } func TestNotifySysadminsBotOwnerDisabled(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -727,7 +736,8 @@ func TestNotifySysadminsBotOwnerDisabled(t *testing.T) { Nickname: "nn_sysadmin1", Password: "hello1", Username: "un_sysadmin1", - Roles: model.SystemAdminRoleId + " " + model.SystemUserRoleId} + Roles: model.SystemAdminRoleId + " " + model.SystemUserRoleId, + } _, err := th.App.CreateUser(th.Context, &sysadmin1) require.Nil(t, err, "failed to create user") _, err = th.App.UpdateUserRoles(th.Context, sysadmin1.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false) @@ -738,7 +748,8 @@ func TestNotifySysadminsBotOwnerDisabled(t *testing.T) { Nickname: "nn_sysadmin2", Password: "hello1", Username: "un_sysadmin2", - Roles: model.SystemAdminRoleId + " " + model.SystemUserRoleId} + Roles: model.SystemAdminRoleId + " " + model.SystemUserRoleId, + } _, err = th.App.CreateUser(th.Context, &sysadmin2) require.Nil(t, err, "failed to create user") _, err = th.App.UpdateUserRoles(th.Context, sysadmin2.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false) @@ -846,6 +857,7 @@ func TestNotifySysadminsBotOwnerDisabled(t *testing.T) { } func TestConvertUserToBot(t *testing.T) { + mainHelper.Parallel(t) t.Run("invalid user", func(t *testing.T) { t.Run("invalid user id", func(t *testing.T) { th := Setup(t).InitBasic() @@ -952,6 +964,7 @@ func TestConvertUserToBot(t *testing.T) { } func TestGetSystemBot(t *testing.T) { + mainHelper.Parallel(t) t.Run("An error should be returned if there are no sysadmins in the instance", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/busy_test.go b/server/channels/app/busy_test.go index 980b32b445..feefc09652 100644 --- a/server/channels/app/busy_test.go +++ b/server/channels/app/busy_test.go @@ -16,6 +16,8 @@ import ( ) func TestBusySet(t *testing.T) { + mainHelper.Parallel(t) + cluster := &ClusterMock{Busy: &Busy{}, t: t} busy := NewBusy(cluster) @@ -54,6 +56,7 @@ func TestBusySet(t *testing.T) { } func TestBusyExpires(t *testing.T) { + mainHelper.Parallel(t) cluster := &ClusterMock{Busy: &Busy{}, t: t} busy := NewBusy(cluster) @@ -90,6 +93,7 @@ func TestBusyExpires(t *testing.T) { } func TestBusyRace(t *testing.T) { + mainHelper.Parallel(t) cluster := &ClusterMock{Busy: &Busy{}, t: t} busy := NewBusy(cluster) @@ -148,12 +152,15 @@ func (c *ClusterMock) NotifyMsg(buf []byte) {} func (c *ClusterMock) GetClusterStats(rctx request.CTX) ([]*model.ClusterStats, *model.AppError) { return nil, nil } + func (c *ClusterMock) GetLogs(rctx request.CTX, page, perPage int) ([]string, *model.AppError) { return nil, nil } + func (c *ClusterMock) QueryLogs(rctx request.CTX, page, perPage int) (map[string][]string, *model.AppError) { return nil, nil } + func (c *ClusterMock) GenerateSupportPacket(rctx request.CTX, options *model.SupportPacketOptions) (map[string][]model.FileData, error) { return nil, nil } @@ -165,6 +172,7 @@ func (c *ClusterMock) HealthScore() int { return 0 } func (c *ClusterMock) WebConnCountForUser(userID string) (int, *model.AppError) { return 0, nil } + func (c *ClusterMock) GetWSQueues(userID, connectionID string, seqNum int64) (map[string]*model.WSQueues, error) { return nil, nil } diff --git a/server/channels/app/channel_bookmark_test.go b/server/channels/app/channel_bookmark_test.go index af8ff3867b..7cb634d504 100644 --- a/server/channels/app/channel_bookmark_test.go +++ b/server/channels/app/channel_bookmark_test.go @@ -40,6 +40,7 @@ func createBookmark(name string, bookmarkType model.ChannelBookmarkType, channel } func TestCreateBookmark(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -81,12 +82,13 @@ func TestCreateBookmark(t *testing.T) { } func TestUpdateBookmark(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() var updateBookmark *model.ChannelBookmarkWithFileInfo - var testUpdateAnotherFile = func(th *TestHelper, t *testing.T) { + testUpdateAnotherFile := func(th *TestHelper, t *testing.T) { file := &model.FileInfo{ Id: model.NewId(), ChannelId: th.BasicChannel.Id, @@ -328,6 +330,7 @@ func TestUpdateBookmark(t *testing.T) { } func TestDeleteBookmark(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -353,6 +356,7 @@ func TestDeleteBookmark(t *testing.T) { } func TestGetChannelBookmarks(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -437,6 +441,7 @@ func TestGetChannelBookmarks(t *testing.T) { } func TestUpdateChannelBookmarkSortOrder(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/channel_category_test.go b/server/channels/app/channel_category_test.go index 4fc8174037..decaadd67f 100644 --- a/server/channels/app/channel_category_test.go +++ b/server/channels/app/channel_category_test.go @@ -13,6 +13,7 @@ import ( ) func TestSidebarCategory(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -86,6 +87,7 @@ func TestSidebarCategory(t *testing.T) { } func TestGetSidebarCategories(t *testing.T) { + mainHelper.Parallel(t) t.Run("should return the sidebar categories for the given user/team", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -128,11 +130,10 @@ func TestGetSidebarCategories(t *testing.T) { defer th.TearDown() // Temporarily renaming a table to force a DB error. - sqlStore := mainHelper.GetSQLStore() - _, err := sqlStore.GetMaster().Exec("ALTER TABLE SidebarCategories RENAME TO SidebarCategoriesTest") + _, err := th.SQLStore.GetMaster().Exec("ALTER TABLE SidebarCategories RENAME TO SidebarCategoriesTest") require.NoError(t, err) defer func() { - _, err := sqlStore.GetMaster().Exec("ALTER TABLE SidebarCategoriesTest RENAME TO SidebarCategories") + _, err := th.SQLStore.GetMaster().Exec("ALTER TABLE SidebarCategoriesTest RENAME TO SidebarCategories") require.NoError(t, err) }() @@ -144,6 +145,7 @@ func TestGetSidebarCategories(t *testing.T) { } func TestUpdateSidebarCategories(t *testing.T) { + mainHelper.Parallel(t) t.Run("should mute and unmute all channels in a category when it is muted or unmuted", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -487,6 +489,7 @@ func TestUpdateSidebarCategories(t *testing.T) { } func TestDiffChannelsBetweenCategories(t *testing.T) { + mainHelper.Parallel(t) t.Run("should return nothing when the categories contain identical channels", func(t *testing.T) { originalCategories := []*model.SidebarCategoryWithChannels{ { diff --git a/server/channels/app/channel_test.go b/server/channels/app/channel_test.go index 9bc7100a2c..4f096bbac1 100644 --- a/server/channels/app/channel_test.go +++ b/server/channels/app/channel_test.go @@ -29,6 +29,7 @@ import ( ) func TestPermanentDeleteChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -86,6 +87,7 @@ func TestPermanentDeleteChannel(t *testing.T) { } func TestRemoveAllDeactivatedMembersFromChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() var appErr *model.AppError @@ -122,6 +124,7 @@ func TestRemoveAllDeactivatedMembersFromChannel(t *testing.T) { } func TestMoveChannel(t *testing.T) { + mainHelper.Parallel(t) t.Run("should move channels between teams", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -304,6 +307,7 @@ func TestMoveChannel(t *testing.T) { } func TestRemoveUsersFromChannelNotMemberOfTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -345,6 +349,7 @@ func TestRemoveUsersFromChannelNotMemberOfTeam(t *testing.T) { } func TestJoinDefaultChannelsCreatesChannelMemberHistoryRecordTownSquare(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -377,6 +382,7 @@ func TestJoinDefaultChannelsCreatesChannelMemberHistoryRecordTownSquare(t *testi } func TestJoinDefaultChannelsCreatesChannelMemberHistoryRecordOffTopic(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -409,6 +415,7 @@ func TestJoinDefaultChannelsCreatesChannelMemberHistoryRecordOffTopic(t *testing } func TestJoinDefaultChannelsExperimentalDefaultChannels(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -435,6 +442,7 @@ func TestJoinDefaultChannelsExperimentalDefaultChannels(t *testing.T) { } func TestJoinDefaultChannelsExperimentalDefaultChannelsMissing(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -465,6 +473,7 @@ func TestJoinDefaultChannelsExperimentalDefaultChannelsMissing(t *testing.T) { } func TestCreateChannelPublicCreatesChannelMemberHistoryRecord(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -480,6 +489,7 @@ func TestCreateChannelPublicCreatesChannelMemberHistoryRecord(t *testing.T) { } func TestCreateChannelPrivateCreatesChannelMemberHistoryRecord(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -493,7 +503,9 @@ func TestCreateChannelPrivateCreatesChannelMemberHistoryRecord(t *testing.T) { assert.Equal(t, th.BasicUser.Id, histories[0].UserId) assert.Equal(t, privateChannel.Id, histories[0].ChannelId) } + func TestCreateChannelDisplayNameTrimsWhitespace(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -507,6 +519,7 @@ func TestCreateChannelDisplayNameTrimsWhitespace(t *testing.T) { } func TestUpdateChannelPrivacy(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -520,6 +533,7 @@ func TestUpdateChannelPrivacy(t *testing.T) { } func TestGetOrCreateDirectChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -574,6 +588,7 @@ func TestGetOrCreateDirectChannel(t *testing.T) { } func TestCreateGroupChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -597,6 +612,7 @@ func TestCreateGroupChannel(t *testing.T) { } func TestCreateGroupChannelCreatesChannelMemberHistoryRecord(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -627,6 +643,7 @@ func TestCreateGroupChannelCreatesChannelMemberHistoryRecord(t *testing.T) { } func TestCreateDirectChannelCreatesChannelMemberHistoryRecord(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -653,6 +670,7 @@ func TestCreateDirectChannelCreatesChannelMemberHistoryRecord(t *testing.T) { } func TestGetDirectChannelCreatesChannelMemberHistoryRecord(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -681,6 +699,7 @@ func TestGetDirectChannelCreatesChannelMemberHistoryRecord(t *testing.T) { } func TestAddUserToChannelCreatesChannelMemberHistoryRecord(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic().DeleteBots() defer th.TearDown() @@ -711,6 +730,7 @@ func TestAddUserToChannelCreatesChannelMemberHistoryRecord(t *testing.T) { } func TestUsersAndPostsCreateActivityInChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic().DeleteBots() defer th.TearDown() @@ -793,6 +813,7 @@ func TestUsersAndPostsCreateActivityInChannel(t *testing.T) { } func TestLeaveDefaultChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -852,6 +873,7 @@ func TestLeaveDefaultChannel(t *testing.T) { } func TestLeaveChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -911,6 +933,7 @@ func TestLeaveChannel(t *testing.T) { } func TestLeaveLastChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -940,6 +963,7 @@ func TestLeaveLastChannel(t *testing.T) { } func TestAddChannelMemberNoUserRequestor(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -981,6 +1005,7 @@ func TestAddChannelMemberNoUserRequestor(t *testing.T) { } func TestAddChannelMemberDeletedUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -997,6 +1022,7 @@ func TestAddChannelMemberDeletedUser(t *testing.T) { } func TestAppUpdateChannelScheme(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1013,6 +1039,7 @@ func TestAppUpdateChannelScheme(t *testing.T) { } func TestSetChannelsMuted(t *testing.T) { + mainHelper.Parallel(t) t.Run("should mute and unmute the given channels", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -1064,6 +1091,7 @@ func TestSetChannelsMuted(t *testing.T) { } func TestFillInChannelProps(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1284,6 +1312,7 @@ func TestFillInChannelProps(t *testing.T) { } func TestRenameChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1351,6 +1380,7 @@ func TestRenameChannel(t *testing.T) { } func TestGetChannelMembersTimezones(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1394,6 +1424,7 @@ func TestGetChannelMembersTimezones(t *testing.T) { } func TestGetChannelsForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() channel := &model.Channel{ DisplayName: "Public", @@ -1438,6 +1469,7 @@ func TestGetChannelsForUser(t *testing.T) { } func TestGetPublicChannelsForTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) team := th.CreateTeam() defer th.TearDown() @@ -1485,6 +1517,7 @@ func TestGetPublicChannelsForTeam(t *testing.T) { } func TestGetPrivateChannelsForTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) team := th.CreateTeam() defer th.TearDown() @@ -1521,6 +1554,7 @@ func TestGetPrivateChannelsForTeam(t *testing.T) { } func TestUpdateChannelMemberRolesChangingGuest(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1599,6 +1633,7 @@ func TestUpdateChannelMemberRolesChangingGuest(t *testing.T) { } func TestDefaultChannelNames(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1616,6 +1651,7 @@ func TestDefaultChannelNames(t *testing.T) { } func TestSearchChannelsForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1673,6 +1709,7 @@ func TestSearchChannelsForUser(t *testing.T) { } func TestMarkChannelAsUnreadFromPost(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1829,6 +1866,7 @@ func TestMarkChannelAsUnreadFromPost(t *testing.T) { } func TestAddUserToChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1923,6 +1961,7 @@ func TestAddUserToChannel(t *testing.T) { } func TestRemoveUserFromChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1982,6 +2021,7 @@ func TestRemoveUserFromChannel(t *testing.T) { } func TestPatchChannelModerationsForChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2461,6 +2501,7 @@ func TestPatchChannelModerationsForChannel(t *testing.T) { } func TestClearChannelMembersCache(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -2476,7 +2517,8 @@ func TestClearChannelMembersCache(t *testing.T) { mockChannelStore.On("GetMembers", "channelID", 100, 100).Return(model.ChannelMembers{ model.ChannelMember{ ChannelId: "1", - }}, nil) + }, + }, nil) mockStore.On("Channel").Return(&mockChannelStore) mockStore.On("GetDBSchemaVersion").Return(1, nil) @@ -2484,6 +2526,7 @@ func TestClearChannelMembersCache(t *testing.T) { } func TestGetMemberCountsByGroup(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -2506,6 +2549,7 @@ func TestGetMemberCountsByGroup(t *testing.T) { } func TestGetChannelsMemberCount(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -2524,6 +2568,7 @@ func TestGetChannelsMemberCount(t *testing.T) { } func TestViewChannelCollapsedThreadsTurnedOff(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2602,6 +2647,7 @@ func TestViewChannelCollapsedThreadsTurnedOff(t *testing.T) { } func TestMarkChannelAsUnreadFromPostCollapsedThreadsTurnedOff(t *testing.T) { + mainHelper.Parallel(t) // Enable CRT th := Setup(t).InitBasic() @@ -2689,6 +2735,7 @@ func TestMarkChannelAsUnreadFromPostCollapsedThreadsTurnedOff(t *testing.T) { } func TestMarkUnreadCRTOffUpdatesThreads(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() th.App.UpdateConfig(func(cfg *model.Config) { @@ -2729,6 +2776,7 @@ func TestMarkUnreadCRTOffUpdatesThreads(t *testing.T) { } func TestIsCRTEnabledForUser(t *testing.T) { + mainHelper.Parallel(t) type preference struct { val string err error @@ -2808,6 +2856,7 @@ func TestIsCRTEnabledForUser(t *testing.T) { } func TestGetGroupMessageMembersCommonTeams(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -2874,6 +2923,7 @@ func TestGetGroupMessageMembersCommonTeams(t *testing.T) { } func TestConvertGroupMessageToChannel(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -3022,6 +3072,7 @@ func TestConvertGroupMessageToChannel(t *testing.T) { } func TestPatchChannelMembersNotifyProps(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/command_autocomplete_test.go b/server/channels/app/command_autocomplete_test.go index 768f3d1f76..a3ba975598 100644 --- a/server/channels/app/command_autocomplete_test.go +++ b/server/channels/app/command_autocomplete_test.go @@ -15,6 +15,7 @@ import ( ) func TestParseStaticListArgument(t *testing.T) { + mainHelper.Parallel(t) items := []model.AutocompleteListItem{ { Hint: "[hint]", @@ -25,12 +26,12 @@ func TestParseStaticListArgument(t *testing.T) { fixedArgs := &model.AutocompleteStaticListArg{PossibleArguments: items} argument := &model.AutocompleteArg{ - Name: "", //positional + Name: "", // positional HelpText: "some_help", Type: model.AutocompleteArgTypeStaticList, Data: fixedArgs, } - found, _, _, suggestions := parseStaticListArgument(argument, "", "") //TODO understand this! + found, _, _, suggestions := parseStaticListArgument(argument, "", "") // TODO understand this! assert.True(t, found) assert.Equal(t, []model.AutocompleteSuggestion{{Complete: "on", Suggestion: "on", Hint: "[hint]", Description: "help"}}, suggestions) @@ -91,8 +92,9 @@ func TestParseStaticListArgument(t *testing.T) { } func TestParseInputTextArgument(t *testing.T) { + mainHelper.Parallel(t) argument := &model.AutocompleteArg{ - Name: "", //positional + Name: "", // positional HelpText: "some_help", Type: model.AutocompleteArgTypeText, Data: &model.AutocompleteTextArg{Hint: "hint", Pattern: "pat"}, @@ -136,8 +138,9 @@ func TestParseInputTextArgument(t *testing.T) { } func TestParseNamedArguments(t *testing.T) { + mainHelper.Parallel(t) argument := &model.AutocompleteArg{ - Name: "name", //named + Name: "name", // named HelpText: "some_help", Type: model.AutocompleteArgTypeText, Data: &model.AutocompleteTextArg{Hint: "hint", Pattern: "pat"}, @@ -201,6 +204,7 @@ func TestParseNamedArguments(t *testing.T) { } func TestSuggestions(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -327,6 +331,7 @@ func TestSuggestions(t *testing.T) { } func TestCommandWithOptionalArgs(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -614,6 +619,7 @@ func createJiraAutocompleteData() *model.AutocompleteData { } func TestDynamicListArgsForBuiltin(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -637,8 +643,7 @@ func TestDynamicListArgsForBuiltin(t *testing.T) { }) } -type testCommandProvider struct { -} +type testCommandProvider struct{} func (p *testCommandProvider) GetTrigger() string { return "bogus" diff --git a/server/channels/app/command_test.go b/server/channels/app/command_test.go index f4734aee71..5c8988a89e 100644 --- a/server/channels/app/command_test.go +++ b/server/channels/app/command_test.go @@ -10,6 +10,7 @@ import ( ) func TestPossibleAtMentions(t *testing.T) { + mainHelper.Parallel(t) fixture := []struct { message string expected []string @@ -55,6 +56,7 @@ func TestPossibleAtMentions(t *testing.T) { } func TestTrimUsernameSpecialChar(t *testing.T) { + mainHelper.Parallel(t) fixture := []struct { word string expectedString string diff --git a/server/channels/app/config_test.go b/server/channels/app/config_test.go index 34e6174baf..f46b06257a 100644 --- a/server/channels/app/config_test.go +++ b/server/channels/app/config_test.go @@ -18,6 +18,7 @@ import ( ) func TestAsymmetricSigningKey(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() assert.NotNil(t, th.App.AsymmetricSigningKey()) @@ -25,12 +26,14 @@ func TestAsymmetricSigningKey(t *testing.T) { } func TestPostActionCookieSecret(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() assert.Equal(t, 32, len(th.App.PostActionCookieSecret())) } func TestClientConfigWithComputed(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -58,6 +61,7 @@ func TestClientConfigWithComputed(t *testing.T) { } func TestEnsureInstallationDate(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/custom_profile_attributes_test.go b/server/channels/app/custom_profile_attributes_test.go index f43024130e..4995e36fd8 100644 --- a/server/channels/app/custom_profile_attributes_test.go +++ b/server/channels/app/custom_profile_attributes_test.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "net/http" - "os" "testing" "time" @@ -16,8 +15,7 @@ import ( ) func TestGetCPAField(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES") + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -122,8 +120,7 @@ func TestGetCPAField(t *testing.T) { } func TestListCPAFields(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES") + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -167,8 +164,7 @@ func TestListCPAFields(t *testing.T) { } func TestCreateCPAField(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES") + mainHelper.Parallel(t) th := Setup(t).InitBasic() cpaGroupID, cErr := th.App.CpaGroupID() @@ -276,8 +272,7 @@ func TestCreateCPAField(t *testing.T) { } func TestPatchCPAField(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES") + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -540,8 +535,7 @@ func TestPatchCPAField(t *testing.T) { } func TestDeleteCPAField(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES") + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -622,8 +616,7 @@ func TestDeleteCPAField(t *testing.T) { } func TestGetCPAValue(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES") + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -699,9 +692,10 @@ func TestGetCPAValue(t *testing.T) { } func TestListCPAValues(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES") - th := Setup(t).InitBasic() + mainHelper.Parallel(t) + th := SetupConfig(t, func(cfg *model.Config) { + cfg.FeatureFlags.CustomProfileAttributes = true + }).InitBasic() defer th.TearDown() cpaGroupID, cErr := th.App.CpaGroupID() @@ -756,8 +750,7 @@ func TestListCPAValues(t *testing.T) { } func TestPatchCPAValue(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES") + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -882,9 +875,10 @@ func TestPatchCPAValue(t *testing.T) { } func TestDeleteCPAValues(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_CUSTOMPROFILEATTRIBUTES") - th := Setup(t).InitBasic() + mainHelper.Parallel(t) + th := SetupConfig(t, func(cfg *model.Config) { + cfg.FeatureFlags.CustomProfileAttributes = true + }).InitBasic() defer th.TearDown() cpaGroupID, cErr := th.App.CpaGroupID() diff --git a/server/channels/app/desktop_login_test.go b/server/channels/app/desktop_login_test.go index b4726fe103..596de5a173 100644 --- a/server/channels/app/desktop_login_test.go +++ b/server/channels/app/desktop_login_test.go @@ -18,6 +18,7 @@ const ( ) func TestGenerateAndSaveDesktopToken(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -29,6 +30,7 @@ func TestGenerateAndSaveDesktopToken(t *testing.T) { } func TestValidateDesktopToken(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/download_test.go b/server/channels/app/download_test.go index fb746611ff..bf477f2fff 100644 --- a/server/channels/app/download_test.go +++ b/server/channels/app/download_test.go @@ -15,6 +15,7 @@ import ( ) func TestDownloadFromURL(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/draft_test.go b/server/channels/app/draft_test.go index 9f52a024eb..349591c650 100644 --- a/server/channels/app/draft_test.go +++ b/server/channels/app/draft_test.go @@ -4,7 +4,6 @@ package app import ( - "os" "testing" "time" @@ -16,11 +15,7 @@ import ( ) func TestGetDraft(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_GLOBALDRAFTS", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_GLOBALDRAFTS") - os.Setenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS", "true") - defer os.Unsetenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS") - + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -52,11 +47,6 @@ func TestGetDraft(t *testing.T) { }) t.Run("get draft feature flag", func(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_GLOBALDRAFTS", "false") - defer os.Unsetenv("MM_FEATUREFLAGS_GLOBALDRAFTS") - os.Setenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS", "false") - defer os.Unsetenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS") - th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowSyncedDrafts = false }) defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowSyncedDrafts = true }) @@ -66,6 +56,7 @@ func TestGetDraft(t *testing.T) { } func TestUpsertDraft(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -115,11 +106,6 @@ func TestUpsertDraft(t *testing.T) { }) t.Run("upsert draft feature flag", func(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_GLOBALDRAFTS", "false") - defer os.Unsetenv("MM_FEATUREFLAGS_GLOBALDRAFTS") - os.Setenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS", "false") - defer os.Unsetenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS") - th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowSyncedDrafts = false }) defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowSyncedDrafts = true }) @@ -129,6 +115,7 @@ func TestUpsertDraft(t *testing.T) { } func TestCreateDraft(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -187,6 +174,7 @@ func TestCreateDraft(t *testing.T) { } func TestUpdateDraft(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -232,6 +220,7 @@ func TestUpdateDraft(t *testing.T) { } func TestGetDraftsForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -346,11 +335,6 @@ func TestGetDraftsForUser(t *testing.T) { }) t.Run("get drafts feature flag", func(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_GLOBALDRAFTS", "false") - defer os.Unsetenv("MM_FEATUREFLAGS_GLOBALDRAFTS") - os.Setenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS", "false") - defer os.Unsetenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS") - th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowSyncedDrafts = false }) defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowSyncedDrafts = true }) @@ -360,6 +344,7 @@ func TestGetDraftsForUser(t *testing.T) { } func TestDeleteDraft(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -388,11 +373,6 @@ func TestDeleteDraft(t *testing.T) { }) t.Run("delete drafts feature flag", func(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_GLOBALDRAFTS", "false") - defer os.Unsetenv("MM_FEATUREFLAGS_GLOBALDRAFTS") - os.Setenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS", "false") - defer os.Unsetenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS") - th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowSyncedDrafts = false }) defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowSyncedDrafts = true }) diff --git a/server/channels/app/email/email_batching_test.go b/server/channels/app/email/email_batching_test.go index 40ee2b06e7..9ff6d74acc 100644 --- a/server/channels/app/email/email_batching_test.go +++ b/server/channels/app/email/email_batching_test.go @@ -16,6 +16,8 @@ import ( ) func TestHandleNewNotifications(t *testing.T) { + mainHelper.Parallel(t) + th := SetupWithStoreMock(t) defer th.TearDown() @@ -75,6 +77,7 @@ func TestHandleNewNotifications(t *testing.T) { } func TestCheckPendingNotifications(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -194,6 +197,7 @@ func TestCheckPendingNotifications(t *testing.T) { * Ensures that email batch interval defaults to 15 minutes for users that haven't explicitly set this preference */ func TestCheckPendingNotificationsDefaultInterval(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -237,6 +241,7 @@ func TestCheckPendingNotificationsDefaultInterval(t *testing.T) { * Ensures that email batch interval defaults to 15 minutes if user preference is invalid */ func TestCheckPendingNotificationsCantParseInterval(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/email/email_test.go b/server/channels/app/email/email_test.go index 9c531f8f40..c4913b9044 100644 --- a/server/channels/app/email/email_test.go +++ b/server/channels/app/email/email_test.go @@ -4,7 +4,6 @@ package email import ( - "os" "testing" "github.com/stretchr/testify/require" @@ -14,6 +13,8 @@ import ( ) func TestCondenseSiteURL(t *testing.T) { + mainHelper.Parallel(t) + require.Equal(t, "", condenseSiteURL("")) require.Equal(t, "mattermost.com", condenseSiteURL("mattermost.com")) require.Equal(t, "mattermost.com", condenseSiteURL("mattermost.com/")) @@ -35,6 +36,7 @@ func TestCondenseSiteURL(t *testing.T) { } func TestSendInviteEmails(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() th.ConfigureInbucketMail() @@ -84,13 +86,14 @@ func TestSendInviteEmails(t *testing.T) { t.Run("SendInviteEmails can return error when SMTP connection fails", func(t *testing.T) { originalPort := *th.service.config().EmailSettings.SMTPPort + originalTimeout := *th.service.config().EmailSettings.SMTPServerTimeout th.UpdateConfig(func(cfg *model.Config) { - os.Setenv("MM_EMAILSETTINGS_SMTPPORT", "5432") *cfg.EmailSettings.SMTPPort = "5432" + *cfg.EmailSettings.SMTPServerTimeout = 4 }) defer th.UpdateConfig(func(cfg *model.Config) { - os.Setenv("MM_EMAILSETTINGS_SMTPPORT", originalPort) *cfg.EmailSettings.SMTPPort = originalPort + *cfg.EmailSettings.SMTPServerTimeout = originalTimeout }) err := th.service.SendInviteEmails(th.BasicTeam, "test-user", th.BasicUser.Id, []string{emailTo}, "http://testserver", nil, true, false, false) @@ -123,14 +126,15 @@ func TestSendInviteEmails(t *testing.T) { }) t.Run("SendGuestInviteEmail can return error when SMTP connection fails", func(t *testing.T) { + originalTimeout := *th.service.config().EmailSettings.SMTPServerTimeout originalPort := *th.service.config().EmailSettings.SMTPPort th.UpdateConfig(func(cfg *model.Config) { - os.Setenv("MM_EMAILSETTINGS_SMTPPORT", "5432") *cfg.EmailSettings.SMTPPort = "5432" + *cfg.EmailSettings.SMTPServerTimeout = 4 }) defer th.UpdateConfig(func(cfg *model.Config) { - os.Setenv("MM_EMAILSETTINGS_SMTPPORT", originalPort) *cfg.EmailSettings.SMTPPort = originalPort + *cfg.EmailSettings.SMTPServerTimeout = originalTimeout }) err := th.service.SendGuestInviteEmails( @@ -255,6 +259,7 @@ func TestSendInviteEmails(t *testing.T) { } func TestSendCloudWelcomeEmail(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() th.ConfigureInbucketMail() @@ -294,6 +299,7 @@ func TestSendCloudWelcomeEmail(t *testing.T) { } func TestMailServiceConfig(t *testing.T) { + mainHelper.Parallel(t) configuredReplyTo := "feedbackexample@test.com" customReplyTo := "customreplyto@test.com" diff --git a/server/channels/app/email/helper_test.go b/server/channels/app/email/helper_test.go index b4a10b8820..bde36ba9b9 100644 --- a/server/channels/app/email/helper_test.go +++ b/server/channels/app/email/helper_test.go @@ -41,10 +41,19 @@ func Setup(tb testing.TB) *TestHelper { if testing.Short() { tb.SkipNow() } - dbStore := mainHelper.GetStore() - dbStore.DropAllTables() - dbStore.MarkSystemRanUnitTests() - mainHelper.PreloadMigrations() + + var dbStore store.Store + if mainHelper.Options.RunParallel { + dbStore, _, _, _ = mainHelper.GetNewStores(tb) + tb.Cleanup(func() { + dbStore.Close() + }) + } else { + dbStore = mainHelper.GetStore() + dbStore.DropAllTables() + dbStore.MarkSystemRanUnitTests() + mainHelper.PreloadMigrations() + } return setupTestHelper(dbStore, tb) } diff --git a/server/channels/app/email/main_test.go b/server/channels/app/email/main_test.go index f70407f19d..6bd4473ab2 100644 --- a/server/channels/app/email/main_test.go +++ b/server/channels/app/email/main_test.go @@ -5,13 +5,18 @@ package email import ( "flag" + "os" + "strconv" "testing" + "github.com/mattermost/mattermost/server/public/shared/mlog" "github.com/mattermost/mattermost/server/v8/channels/testlib" ) -var mainHelper *testlib.MainHelper -var replicaFlag bool +var ( + mainHelper *testlib.MainHelper + replicaFlag bool +) func TestMain(m *testing.M) { if f := flag.Lookup("mysql-replica"); f == nil { @@ -19,10 +24,21 @@ func TestMain(m *testing.M) { flag.Parse() } - var options = testlib.HelperOptions{ + var parallelism int + if f := flag.Lookup("test.parallel"); f != nil { + parallelism, _ = strconv.Atoi(f.Value.String()) + } + runParallel := os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" && parallelism > 1 + if runParallel { + mlog.Info("Fully parallel tests enabled", mlog.Int("parallelism", parallelism)) + } + + options := testlib.HelperOptions{ EnableStore: true, EnableResources: true, WithReadReplica: replicaFlag, + RunParallel: runParallel, + Parallelism: parallelism, } mainHelper = testlib.NewMainHelperWithOptions(&options) diff --git a/server/channels/app/email/notification_email_test.go b/server/channels/app/email/notification_email_test.go index cc8eeed074..072de1f658 100644 --- a/server/channels/app/email/notification_email_test.go +++ b/server/channels/app/email/notification_email_test.go @@ -12,6 +12,7 @@ import ( ) func TestProcessMessageAttachments(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/email_test.go b/server/channels/app/email_test.go index 7b529cdd91..3d21c7052c 100644 --- a/server/channels/app/email_test.go +++ b/server/channels/app/email_test.go @@ -15,6 +15,7 @@ import ( ) func TestSendInviteEmailRateLimits(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/emoji_test.go b/server/channels/app/emoji_test.go index dfaacc123c..cc6e6a5136 100644 --- a/server/channels/app/emoji_test.go +++ b/server/channels/app/emoji_test.go @@ -12,6 +12,7 @@ import ( ) func TestGetMultipleEmojiByName(t *testing.T) { + mainHelper.Parallel(t) // The fact that we use mock store ensures that // the call to the DB does not happen. If it did, we would have needed // to provide the mock explicitly. diff --git a/server/channels/app/enterprise_test.go b/server/channels/app/enterprise_test.go index 35c508fb05..7a522600a1 100644 --- a/server/channels/app/enterprise_test.go +++ b/server/channels/app/enterprise_test.go @@ -17,6 +17,7 @@ import ( ) func TestSAMLSettings(t *testing.T) { + mainHelper.Parallel(t) tt := []struct { name string setInterface bool diff --git a/server/channels/app/expirynotify_test.go b/server/channels/app/expirynotify_test.go index 3843917b5b..864040224d 100644 --- a/server/channels/app/expirynotify_test.go +++ b/server/channels/app/expirynotify_test.go @@ -14,6 +14,7 @@ import ( ) func TestNotifySessionsExpired(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/export_test.go b/server/channels/app/export_test.go index 241d166a83..ccc71db7e5 100644 --- a/server/channels/app/export_test.go +++ b/server/channels/app/export_test.go @@ -28,6 +28,7 @@ import ( ) func TestReactionsOfPost(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -58,6 +59,7 @@ func TestReactionsOfPost(t *testing.T) { } func TestExportUserNotifyProps(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -85,6 +87,7 @@ func TestExportUserNotifyProps(t *testing.T) { } func TestExportUserChannels(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -136,6 +139,7 @@ func TestExportUserChannels(t *testing.T) { } func TestCopyEmojiImages(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -172,6 +176,7 @@ func TestCopyEmojiImages(t *testing.T) { } func TestExportCustomEmoji(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -192,6 +197,7 @@ func TestExportCustomEmoji(t *testing.T) { } func TestExportAllUsers(t *testing.T) { + mainHelper.Parallel(t) th1 := Setup(t) defer th1.TearDown() @@ -204,8 +210,15 @@ func TestExportAllUsers(t *testing.T) { err = th1.App.BulkExport(th1.Context, &b, "somePath", nil, model.BulkExportOpts{}) require.Nil(t, err) - th2 := Setup(t) - defer th2.TearDown() + var th2 *TestHelper + if mainHelper.Options.RunParallel { + th1.Store.DropAllTables() + th2 = th1 + } else { + th2 = Setup(t) + defer th2.TearDown() + } + i, err := th2.App.BulkImport(th2.Context, &b, nil, false, 5) assert.Nil(t, err) assert.EqualValues(t, 0, i) @@ -241,6 +254,7 @@ func TestExportAllUsers(t *testing.T) { } func TestExportAllBots(t *testing.T) { + mainHelper.Parallel(t) th1 := Setup(t) defer th1.TearDown() @@ -276,6 +290,7 @@ func TestExportAllBots(t *testing.T) { } func TestExportDMChannel(t *testing.T) { + mainHelper.Parallel(t) t.Run("Export a DM channel to another server", func(t *testing.T) { th1 := Setup(t).InitBasic() defer th1.TearDown() @@ -406,6 +421,7 @@ func TestExportDMChannel(t *testing.T) { } func TestExportDMChannelToSelf(t *testing.T) { + mainHelper.Parallel(t) th1 := Setup(t).InitBasic() defer th1.TearDown() @@ -440,6 +456,7 @@ func TestExportDMChannelToSelf(t *testing.T) { } func TestExportGMChannel(t *testing.T) { + mainHelper.Parallel(t) th1 := Setup(t).InitBasic() user1 := th1.CreateUser() @@ -469,6 +486,7 @@ func TestExportGMChannel(t *testing.T) { } func TestExportGMandDMChannels(t *testing.T) { + mainHelper.Parallel(t) th1 := Setup(t).InitBasic() // DM Channel @@ -516,6 +534,7 @@ func TestExportGMandDMChannels(t *testing.T) { } func TestExportDMandGMPost(t *testing.T) { + mainHelper.Parallel(t) th1 := Setup(t).InitBasic() // DM Channel @@ -600,6 +619,7 @@ func TestExportDMandGMPost(t *testing.T) { } func TestExportPostWithProps(t *testing.T) { + mainHelper.Parallel(t) th1 := Setup(t).InitBasic() attachments := []*model.SlackAttachment{{Footer: "footer"}} @@ -677,6 +697,7 @@ func TestExportPostWithProps(t *testing.T) { } func TestExportUserCustomStatus(t *testing.T) { + mainHelper.Parallel(t) th1 := Setup(t).InitBasic() cs := &model.CustomStatus{ @@ -711,6 +732,7 @@ func TestExportUserCustomStatus(t *testing.T) { } func TestExportDMPostWithSelf(t *testing.T) { + mainHelper.Parallel(t) th1 := Setup(t).InitBasic() // DM Channel with self (me channel) @@ -748,6 +770,7 @@ func TestExportDMPostWithSelf(t *testing.T) { } func TestExportPostsWithThread(t *testing.T) { + mainHelper.Parallel(t) th1 := Setup(t).InitBasic() defer th1.TearDown() @@ -985,6 +1008,7 @@ func TestExportFileWarnings(t *testing.T) { } func TestBulkExport(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) testsDir, _ := fileutils.FindDir("tests") @@ -1039,6 +1063,7 @@ func TestBulkExport(t *testing.T) { } func TestBuildPostReplies(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1103,6 +1128,7 @@ func TestBuildPostReplies(t *testing.T) { } func TestExportDeletedTeams(t *testing.T) { + mainHelper.Parallel(t) th1 := Setup(t).InitBasic() defer th1.TearDown() @@ -1118,8 +1144,15 @@ func TestExportDeletedTeams(t *testing.T) { err = th1.App.BulkExport(th1.Context, &b, "somePath", nil, model.BulkExportOpts{}) require.Nil(t, err) - th2 := Setup(t) - defer th2.TearDown() + var th2 *TestHelper + if mainHelper.Options.RunParallel { + th1.Store.DropAllTables() + th2 = th1 + } else { + th2 = Setup(t) + defer th2.TearDown() + } + i, err := th2.App.BulkImport(th2.Context, &b, nil, false, 5) assert.Nil(t, err) assert.Equal(t, 0, i) @@ -1144,6 +1177,7 @@ func TestExportDeletedTeams(t *testing.T) { } func TestExportArchivedChannels(t *testing.T) { + mainHelper.Parallel(t) th1 := Setup(t).InitBasic() defer th1.TearDown() @@ -1179,6 +1213,7 @@ func TestExportArchivedChannels(t *testing.T) { } func TestExportRoles(t *testing.T) { + mainHelper.Parallel(t) t.Run("defaults", func(t *testing.T) { th1 := Setup(t).InitBasic() defer th1.TearDown() @@ -1277,6 +1312,7 @@ func TestExportRoles(t *testing.T) { } func TestExportSchemes(t *testing.T) { + mainHelper.Parallel(t) t.Run("no schemes", func(t *testing.T) { th1 := Setup(t).InitBasic() defer th1.TearDown() diff --git a/server/channels/app/extract_plugin_tar_test.go b/server/channels/app/extract_plugin_tar_test.go index f1662fafa0..aa31ed4efb 100644 --- a/server/channels/app/extract_plugin_tar_test.go +++ b/server/channels/app/extract_plugin_tar_test.go @@ -35,6 +35,7 @@ func assertDirectoryContents(t *testing.T, dir string, expectedFiles []string) { } func TestExtractTarGz(t *testing.T) { + mainHelper.Parallel(t) makeArchive := func(t *testing.T, files []*tar.Header) bytes.Buffer { // Build an in-memory archive with the specified files, writing the path as each // file's contents when applicable. diff --git a/server/channels/app/file_helper_test.go b/server/channels/app/file_helper_test.go index 06625ab9a9..fa11897e29 100644 --- a/server/channels/app/file_helper_test.go +++ b/server/channels/app/file_helper_test.go @@ -13,6 +13,7 @@ import ( ) func TestFilterInaccessibleFiles(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) th.App.Srv().SetLicense(model.NewTestLicense("cloud")) err := th.App.Srv().Store().System().Save(&model.System{ @@ -23,7 +24,7 @@ func TestFilterInaccessibleFiles(t *testing.T) { defer th.TearDown() - var getFileWithCreateAt = func(at int64) *model.FileInfo { + getFileWithCreateAt := func(at int64) *model.FileInfo { return &model.FileInfo{CreateAt: at} } @@ -116,6 +117,7 @@ func TestFilterInaccessibleFiles(t *testing.T) { } func TestGetFilteredAccessibleFiles(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) th.App.Srv().SetLicense(model.NewTestLicense("cloud")) err := th.App.Srv().Store().System().Save(&model.System{ @@ -126,7 +128,7 @@ func TestGetFilteredAccessibleFiles(t *testing.T) { defer th.TearDown() - var getFileWithCreateAt = func(at int64) *model.FileInfo { + getFileWithCreateAt := func(at int64) *model.FileInfo { return &model.FileInfo{CreateAt: at} } @@ -158,6 +160,7 @@ func TestGetFilteredAccessibleFiles(t *testing.T) { } func TestIsInaccessibleFile(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) th.App.Srv().SetLicense(model.NewTestLicense("cloud")) err := th.App.Srv().Store().System().Save(&model.System{ @@ -180,6 +183,7 @@ func TestIsInaccessibleFile(t *testing.T) { } func TestRemoveInaccessibleContentFromFilesSlice(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) th.App.Srv().SetLicense(model.NewTestLicense("cloud")) err := th.App.Srv().Store().System().Save(&model.System{ @@ -190,7 +194,7 @@ func TestRemoveInaccessibleContentFromFilesSlice(t *testing.T) { defer th.TearDown() - var getFileWithCreateAt = func(at int64) *model.FileInfo { + getFileWithCreateAt := func(at int64) *model.FileInfo { return &model.FileInfo{CreateAt: at} } diff --git a/server/channels/app/file_info_test.go b/server/channels/app/file_info_test.go index f024d822a1..78a0f0ebda 100644 --- a/server/channels/app/file_info_test.go +++ b/server/channels/app/file_info_test.go @@ -15,6 +15,7 @@ import ( ) func TestGetInfoForFile(t *testing.T) { + mainHelper.Parallel(t) fakeFile := make([]byte, 1000) pngFile, err := os.ReadFile("tests/test.png") @@ -26,7 +27,7 @@ func TestGetInfoForFile(t *testing.T) { animatedGifFile, err := os.ReadFile("tests/testgif.gif") require.NoError(t, err, "Failed to load testgif.gif") - var ttc = []struct { + ttc := []struct { testName string filename string file []byte diff --git a/server/channels/app/file_test.go b/server/channels/app/file_test.go index a70af7fd6f..da83fdb314 100644 --- a/server/channels/app/file_test.go +++ b/server/channels/app/file_test.go @@ -30,6 +30,7 @@ import ( ) func TestGeneratePublicLinkHash(t *testing.T) { + mainHelper.Parallel(t) filename1 := model.NewId() + "/" + model.NewRandomString(16) + ".txt" filename2 := model.NewId() + "/" + model.NewRandomString(16) + ".txt" salt1 := model.NewRandomString(32) @@ -48,6 +49,7 @@ func TestGeneratePublicLinkHash(t *testing.T) { } func TestDoUploadFile(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -109,6 +111,7 @@ func TestDoUploadFile(t *testing.T) { } func TestUploadFile(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -137,6 +140,7 @@ func TestUploadFile(t *testing.T) { } func TestParseOldFilenames(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -234,6 +238,7 @@ func TestParseOldFilenames(t *testing.T) { } func TestGetInfoForFilename(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -245,6 +250,7 @@ func TestGetInfoForFilename(t *testing.T) { } func TestFindTeamIdForFilename(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -259,6 +265,7 @@ func TestFindTeamIdForFilename(t *testing.T) { } func TestMigrateFilenamesToFileInfos(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -293,6 +300,7 @@ func TestMigrateFilenamesToFileInfos(t *testing.T) { } func TestCreateZipFileAndAddFiles(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -349,6 +357,7 @@ func TestCreateZipFileAndAddFiles(t *testing.T) { } func TestCopyFileInfos(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -380,6 +389,7 @@ func TestCopyFileInfos(t *testing.T) { } func TestGenerateThumbnailImage(t *testing.T) { + mainHelper.Parallel(t) t.Run("test generating thumbnail image", func(t *testing.T) { // given th := Setup(t) @@ -409,6 +419,7 @@ func createDummyImage() *image.RGBA { } func TestSearchFilesInTeamForUser(t *testing.T) { + mainHelper.Parallel(t) perPage := 5 searchTerm := "searchTerm" @@ -602,6 +613,7 @@ func TestSearchFilesInTeamForUser(t *testing.T) { } func TestExtractContentFromFileInfo(t *testing.T) { + mainHelper.Parallel(t) app := &App{} fi := &model.FileInfo{ MimeType: "image/jpeg", @@ -612,6 +624,7 @@ func TestExtractContentFromFileInfo(t *testing.T) { } func TestGetLastAccessibleFileTime(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -645,6 +658,7 @@ func TestGetLastAccessibleFileTime(t *testing.T) { } func TestComputeLastAccessibleFileTime(t *testing.T) { + mainHelper.Parallel(t) t.Run("Updates the time, if cloud limit is applicable", func(t *testing.T) { th := SetupWithStoreMock(t) defer th.TearDown() @@ -704,6 +718,7 @@ func TestComputeLastAccessibleFileTime(t *testing.T) { } func TestSetFileSearchableContent(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -732,6 +747,7 @@ func TestSetFileSearchableContent(t *testing.T) { } func TestPermanentDeleteFilesByPost(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/group_test.go b/server/channels/app/group_test.go index 8a7c1c1575..121e76ccbd 100644 --- a/server/channels/app/group_test.go +++ b/server/channels/app/group_test.go @@ -13,6 +13,7 @@ import ( ) func TestGetGroup(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() group := th.CreateGroup() @@ -35,6 +36,7 @@ func TestGetGroup(t *testing.T) { } func TestGetGroupByRemoteID(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() group := th.CreateGroup() @@ -49,6 +51,7 @@ func TestGetGroupByRemoteID(t *testing.T) { } func TestGetGroupsByType(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() th.CreateGroup() @@ -65,6 +68,7 @@ func TestGetGroupsByType(t *testing.T) { } func TestCreateGroup(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -100,6 +104,7 @@ func TestCreateGroup(t *testing.T) { } func TestUpdateGroup(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() group := th.CreateGroup() @@ -117,6 +122,7 @@ func TestUpdateGroup(t *testing.T) { } func TestDeleteGroup(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() group := th.CreateGroup() @@ -131,6 +137,7 @@ func TestDeleteGroup(t *testing.T) { } func TestUndeleteGroup(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() group := th.CreateGroup() @@ -149,6 +156,7 @@ func TestUndeleteGroup(t *testing.T) { } func TestCreateOrRestoreGroupMember(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() group := th.CreateGroup() @@ -163,6 +171,7 @@ func TestCreateOrRestoreGroupMember(t *testing.T) { } func TestDeleteGroupMember(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() group := th.CreateGroup() @@ -180,6 +189,7 @@ func TestDeleteGroupMember(t *testing.T) { } func TestUpsertGroupSyncable(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() group := th.CreateGroup() @@ -206,6 +216,7 @@ func TestUpsertGroupSyncable(t *testing.T) { } func TestUpsertGroupSyncableTeamGroupConstrained(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -234,6 +245,7 @@ func TestUpsertGroupSyncableTeamGroupConstrained(t *testing.T) { } func TestGetGroupSyncable(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() group := th.CreateGroup() @@ -249,6 +261,7 @@ func TestGetGroupSyncable(t *testing.T) { } func TestGetGroupSyncables(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() group := th.CreateGroup() @@ -267,6 +280,7 @@ func TestGetGroupSyncables(t *testing.T) { } func TestDeleteGroupSyncable(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() group := th.CreateGroup() @@ -286,6 +300,7 @@ func TestDeleteGroupSyncable(t *testing.T) { } func TestGetGroupsByChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() group := th.CreateGroup() @@ -320,6 +335,7 @@ func TestGetGroupsByChannel(t *testing.T) { } func TestGetGroupsAssociatedToChannelsByTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() group := th.CreateGroup() @@ -359,6 +375,7 @@ func TestGetGroupsAssociatedToChannelsByTeam(t *testing.T) { } func TestGetGroupsByTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() group := th.CreateGroup() @@ -386,6 +403,7 @@ func TestGetGroupsByTeam(t *testing.T) { } func TestGetGroups(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() group := th.CreateGroup() @@ -396,6 +414,7 @@ func TestGetGroups(t *testing.T) { } func TestUserIsInAdminRoleGroup(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() group1 := th.CreateGroup() diff --git a/server/channels/app/helper_test.go b/server/channels/app/helper_test.go index 5f8da90249..8d43816e6f 100644 --- a/server/channels/app/helper_test.go +++ b/server/channels/app/helper_test.go @@ -29,12 +29,15 @@ import ( "github.com/mattermost/mattermost/server/v8/channels/testlib" "github.com/mattermost/mattermost/server/v8/config" "github.com/mattermost/mattermost/server/v8/einterfaces" + "github.com/mattermost/mattermost/server/v8/platform/services/searchengine" ) type TestHelper struct { App *App Context *request.Context Server *Server + Store store.Store + SQLStore *sqlstore.SqlStore BasicTeam *model.Team BasicUser *model.User BasicUser2 *model.User @@ -54,8 +57,9 @@ type PostOptions func(*model.Post) type PostPatchOptions func(patch *model.PostPatch) -func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer bool, - updateConfig func(*model.Config), options []Option, tb testing.TB) *TestHelper { +func setupTestHelper(dbStore store.Store, sqlStore *sqlstore.SqlStore, sqlSettings *model.SqlSettings, searchEngine *searchengine.Broker, enterprise bool, includeCacheLayer bool, + updateConfig func(*model.Config), options []Option, tb testing.TB, +) *TestHelper { tempWorkspace, err := os.MkdirTemp("", "apptest") if err != nil { panic(err) @@ -63,7 +67,10 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo configStore := config.NewTestMemoryStore() memoryConfig := configStore.Get() - memoryConfig.SqlSettings = *mainHelper.GetSQLSettings() + + memoryConfig.SqlSettings = model.SafeDereference(sqlSettings) + *memoryConfig.ServiceSettings.LicenseFileLocation = filepath.Join(tempWorkspace, "license.json") + *memoryConfig.FileSettings.Directory = filepath.Join(tempWorkspace, "data") *memoryConfig.PluginSettings.Directory = filepath.Join(tempWorkspace, "plugins") *memoryConfig.PluginSettings.ClientDirectory = filepath.Join(tempWorkspace, "webapp") *memoryConfig.PluginSettings.AutomaticPrepackagedPlugins = false @@ -71,6 +78,7 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo *memoryConfig.LogSettings.ConsoleLevel = mlog.LvlStdLog.Name *memoryConfig.AnnouncementSettings.AdminNoticesEnabled = false *memoryConfig.AnnouncementSettings.UserNoticesEnabled = false + *memoryConfig.LogSettings.FileLocation = filepath.Join(tempWorkspace, "logs", "mattermost.log") if updateConfig != nil { updateConfig(memoryConfig) } @@ -111,6 +119,8 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo TestLogger: testLogger, IncludeCacheLayer: includeCacheLayer, ConfigStore: configStore, + Store: dbStore, + SQLStore: sqlStore, } th.App.Srv().SetLicense(getLicense(enterprise, memoryConfig)) @@ -119,6 +129,14 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo th.App.UpdateConfig(func(cfg *model.Config) { *cfg.RateLimitSettings.Enable = false }) prevListenAddress := *th.App.Config().ServiceSettings.ListenAddress th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = "localhost:0" }) + + // Support updating feature flags without resorting to os.Setenv which + // isn't concurrently safe. + if updateConfig != nil { + configStore.SetReadOnlyFF(false) + th.App.UpdateConfig(updateConfig) + } + serverErr := th.Server.Start() if serverErr != nil { panic(serverErr) @@ -126,7 +144,7 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = prevListenAddress }) - th.App.Srv().Platform().SearchEngine = mainHelper.SearchEngine + th.App.Srv().Platform().SearchEngine = searchEngine th.App.Srv().Store().MarkSystemRanUnitTests() @@ -158,40 +176,57 @@ func getLicense(enterprise bool, cfg *model.Config) *model.License { return nil } +func setupStores(tb testing.TB) (store.Store, *sqlstore.SqlStore, *model.SqlSettings, *searchengine.Broker) { + var dbStore store.Store + var sqlStore *sqlstore.SqlStore + var dbSettings *model.SqlSettings + var searchEngine *searchengine.Broker + if mainHelper.Options.RunParallel { + dbStore, sqlStore, dbSettings, searchEngine = mainHelper.GetNewStores(tb) + tb.Cleanup(func() { + dbStore.Close() + }) + } else { + dbStore = mainHelper.GetStore() + dbStore.DropAllTables() + dbStore.MarkSystemRanUnitTests() + mainHelper.PreloadMigrations() + searchEngine = mainHelper.GetSearchEngine() + dbSettings = mainHelper.GetSQLSettings() + sqlStore = mainHelper.GetSQLStore() + } + + return dbStore, sqlStore, dbSettings, searchEngine +} + func Setup(tb testing.TB, options ...Option) *TestHelper { if testing.Short() { tb.SkipNow() } - dbStore := mainHelper.GetStore() - dbStore.DropAllTables() - dbStore.MarkSystemRanUnitTests() - mainHelper.PreloadMigrations() - return setupTestHelper(dbStore, false, true, nil, options, tb) + dbStore, sqlStore, dbSettings, searchEngine := setupStores(tb) + + return setupTestHelper(dbStore, sqlStore, dbSettings, searchEngine, false, true, nil, options, tb) } func SetupEnterprise(tb testing.TB, options ...Option) *TestHelper { if testing.Short() { tb.SkipNow() } - dbStore := mainHelper.GetStore() - dbStore.DropAllTables() - dbStore.MarkSystemRanUnitTests() - mainHelper.PreloadMigrations() - return setupTestHelper(dbStore, true, true, nil, options, tb) + dbStore, sqlStore, dbSettings, searchEngine := setupStores(tb) + + return setupTestHelper(dbStore, sqlStore, dbSettings, searchEngine, true, true, nil, options, tb) } func SetupConfig(tb testing.TB, updateConfig func(cfg *model.Config)) *TestHelper { if testing.Short() { tb.SkipNow() } - dbStore := mainHelper.GetStore() - dbStore.DropAllTables() - dbStore.MarkSystemRanUnitTests() - mainHelper.PreloadMigrations() - return setupTestHelper(dbStore, false, true, updateConfig, nil, tb) + dbStore, sqlStore, dbSettings, searchEngine := setupStores(tb) + + return setupTestHelper(dbStore, sqlStore, dbSettings, searchEngine, false, true, updateConfig, nil, tb) } func SetupWithoutPreloadMigrations(tb testing.TB) *TestHelper { @@ -202,12 +237,12 @@ func SetupWithoutPreloadMigrations(tb testing.TB) *TestHelper { dbStore.DropAllTables() dbStore.MarkSystemRanUnitTests() - return setupTestHelper(dbStore, false, true, nil, nil, tb) + return setupTestHelper(dbStore, mainHelper.GetSQLStore(), mainHelper.GetSQLSettings(), mainHelper.GetSearchEngine(), false, true, nil, nil, tb) } func SetupWithStoreMock(tb testing.TB) *TestHelper { mockStore := testlib.GetMockStoreForSetupFunctions() - th := setupTestHelper(mockStore, false, false, nil, nil, tb) + th := setupTestHelper(mockStore, mainHelper.GetSQLStore(), mainHelper.GetSQLSettings(), mainHelper.GetSearchEngine(), false, false, nil, nil, tb) statusMock := mocks.StatusStore{} statusMock.On("UpdateExpiredDNDStatuses").Return([]*model.Status{}, nil) statusMock.On("Get", "user1").Return(&model.Status{UserId: "user1", Status: model.StatusOnline}, nil) @@ -228,7 +263,7 @@ func SetupWithStoreMock(tb testing.TB) *TestHelper { func SetupEnterpriseWithStoreMock(tb testing.TB) *TestHelper { mockStore := testlib.GetMockStoreForSetupFunctions() - th := setupTestHelper(mockStore, true, false, nil, nil, tb) + th := setupTestHelper(mockStore, mainHelper.GetSQLStore(), mainHelper.GetSQLSettings(), mainHelper.GetSearchEngine(), true, false, nil, nil, tb) statusMock := mocks.StatusStore{} statusMock.On("UpdateExpiredDNDStatuses").Return([]*model.Status{}, nil) statusMock.On("Get", "user1").Return(&model.Status{UserId: "user1", Status: model.StatusOnline}, nil) @@ -245,44 +280,56 @@ func SetupWithClusterMock(tb testing.TB, cluster einterfaces.ClusterInterface) * if testing.Short() { tb.SkipNow() } - dbStore := mainHelper.GetStore() - dbStore.DropAllTables() - dbStore.MarkSystemRanUnitTests() - mainHelper.PreloadMigrations() - return setupTestHelper(dbStore, true, true, nil, []Option{SetCluster(cluster)}, tb) + dbStore, sqlStore, dbSettings, searchEngine := setupStores(tb) + + return setupTestHelper(dbStore, sqlStore, dbSettings, searchEngine, true, true, nil, []Option{SetCluster(cluster)}, tb) } -var initBasicOnce sync.Once -var userCache struct { - SystemAdminUser *model.User - BasicUser *model.User - BasicUser2 *model.User -} +var ( + initBasicOnce sync.Once + userCache struct { + SystemAdminUser *model.User + BasicUser *model.User + BasicUser2 *model.User + } +) func (th *TestHelper) InitBasic() *TestHelper { // create users once and cache them because password hashing is slow initBasicOnce.Do(func() { + var err *model.AppError + th.SystemAdminUser = th.CreateUser() th.App.UpdateUserRoles(th.Context, th.SystemAdminUser.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false) - th.SystemAdminUser, _ = th.App.GetUser(th.SystemAdminUser.Id) + th.SystemAdminUser, err = th.App.GetUser(th.SystemAdminUser.Id) + if err != nil { + panic(err) + } userCache.SystemAdminUser = th.SystemAdminUser.DeepCopy() th.BasicUser = th.CreateUser() - th.BasicUser, _ = th.App.GetUser(th.BasicUser.Id) + th.BasicUser, err = th.App.GetUser(th.BasicUser.Id) + if err != nil { + panic(err) + } userCache.BasicUser = th.BasicUser.DeepCopy() th.BasicUser2 = th.CreateUser() - th.BasicUser2, _ = th.App.GetUser(th.BasicUser2.Id) + th.BasicUser2, err = th.App.GetUser(th.BasicUser2.Id) + if err != nil { + panic(err) + } userCache.BasicUser2 = th.BasicUser2.DeepCopy() }) + // restore cached users th.SystemAdminUser = userCache.SystemAdminUser.DeepCopy() th.BasicUser = userCache.BasicUser.DeepCopy() th.BasicUser2 = userCache.BasicUser2.DeepCopy() users := []*model.User{th.SystemAdminUser, th.BasicUser, th.BasicUser2} - mainHelper.GetSQLStore().User().InsertUsers(users) + th.Store.User().InsertUsers(users) th.BasicTeam = th.CreateTeam() @@ -638,8 +685,8 @@ func (th *TestHelper) TearDown() { } } -func (*TestHelper) GetSqlStore() *sqlstore.SqlStore { - return mainHelper.GetSQLStore() +func (th *TestHelper) GetSqlStore() *sqlstore.SqlStore { + return th.SQLStore } func (th *TestHelper) ConfigureInbucketMail() { @@ -657,8 +704,8 @@ func (th *TestHelper) ConfigureInbucketMail() { }) } -func (*TestHelper) ResetRoleMigration() { - sqlStore := mainHelper.GetSQLStore() +func (th *TestHelper) ResetRoleMigration() { + sqlStore := th.SQLStore if _, err := sqlStore.GetMaster().Exec("DELETE from Roles"); err != nil { panic(err) } @@ -670,8 +717,8 @@ func (*TestHelper) ResetRoleMigration() { } } -func (*TestHelper) ResetEmojisMigration() { - sqlStore := mainHelper.GetSQLStore() +func (th *TestHelper) ResetEmojisMigration() { + sqlStore := th.SQLStore if _, err := sqlStore.GetMaster().Exec("UPDATE Roles SET Permissions=REPLACE(Permissions, ' create_emojis', '') WHERE builtin=True"); err != nil { panic(err) } @@ -852,3 +899,7 @@ func decodeJSON[T any](o any, result *T) *T { return result } + +func (th *TestHelper) Parallel(t *testing.T) { + mainHelper.Parallel(t) +} diff --git a/server/channels/app/import_functions_test.go b/server/channels/app/import_functions_test.go index 8ce087b1f4..6332be9788 100644 --- a/server/channels/app/import_functions_test.go +++ b/server/channels/app/import_functions_test.go @@ -27,6 +27,7 @@ import ( ) func TestImportImportScheme(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -223,6 +224,7 @@ func TestImportImportScheme(t *testing.T) { } func TestImportImportSchemeWithoutGuestRoles(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -411,6 +413,7 @@ func TestImportImportSchemeWithoutGuestRoles(t *testing.T) { } func TestImportImportRole(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -502,6 +505,7 @@ func TestImportImportRole(t *testing.T) { } func TestImportImportTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -599,6 +603,7 @@ func TestImportImportTeam(t *testing.T) { } func TestImportImportChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -745,6 +750,7 @@ func TestImportImportChannel(t *testing.T) { } func TestImportImportUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1741,6 +1747,7 @@ func TestImportImportUser(t *testing.T) { } func TestImportUserTeams(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() team2 := th.CreateTeam() @@ -1963,6 +1970,7 @@ func TestImportUserTeams(t *testing.T) { } func TestImportUserChannels(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() channel2 := th.CreateChannel(th.Context, th.BasicTeam) @@ -2097,6 +2105,7 @@ func TestImportUserChannels(t *testing.T) { } func TestImportUserDefaultNotifyProps(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -2136,6 +2145,7 @@ func TestImportUserDefaultNotifyProps(t *testing.T) { } func TestImportimportMultiplePostLines(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -3195,6 +3205,7 @@ func TestImportimportMultiplePostLines(t *testing.T) { } func TestImportImportPost(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -3802,6 +3813,7 @@ func TestImportImportPost(t *testing.T) { } func TestImportImportDirectChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() user3 := th.CreateUser() @@ -4173,6 +4185,7 @@ func TestImportImportDirectChannel(t *testing.T) { } func TestImportImportDirectPost(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -5120,6 +5133,7 @@ func TestImportImportDirectPost(t *testing.T) { } func TestImportImportEmoji(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -5171,6 +5185,7 @@ func TestImportImportEmoji(t *testing.T) { } func TestImportAttachment(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -5193,6 +5208,7 @@ func TestImportAttachment(t *testing.T) { } func TestImportPostAndRepliesWithAttachments(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -5434,6 +5450,7 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) { } func TestImportDirectPostWithAttachments(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -5561,6 +5578,7 @@ func TestImportDirectPostWithAttachments(t *testing.T) { } func TestZippedImportPostAndRepliesWithAttachments(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -5762,6 +5780,7 @@ func TestZippedImportPostAndRepliesWithAttachments(t *testing.T) { } func TestCompareFilesContent(t *testing.T) { + mainHelper.Parallel(t) t.Run("empty", func(t *testing.T) { ok, err := compareFilesContent(strings.NewReader(""), strings.NewReader(""), 0) require.NoError(t, err) diff --git a/server/channels/app/import_test.go b/server/channels/app/import_test.go index 84b4b0e6a4..09c7f57fdf 100644 --- a/server/channels/app/import_test.go +++ b/server/channels/app/import_test.go @@ -67,6 +67,7 @@ func AssertChannelCount(t *testing.T, a *App, channelType model.ChannelType, exp } func TestImportImportLine(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -115,6 +116,7 @@ func TestImportImportLine(t *testing.T) { } func TestStopOnError(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -145,6 +147,7 @@ func TestStopOnError(t *testing.T) { } func TestImportBulkImport(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -282,6 +285,7 @@ func TestImportBulkImport(t *testing.T) { } func TestImportProcessImportDataFileVersionLine(t *testing.T) { + mainHelper.Parallel(t) data := imports.LineImportData{ Type: "version", Version: model.NewPointer(1), @@ -451,6 +455,7 @@ func TestProcessAttachmentPaths(t *testing.T) { } func TestProcessAttachments(t *testing.T) { + mainHelper.Parallel(t) c := request.TestContext(t) genAttachments := func() *[]imports.AttachmentImportData { @@ -633,6 +638,7 @@ func BenchmarkBulkImport(b *testing.B) { } func TestImportBulkImportWithAttachments(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/import_utils_test.go b/server/channels/app/import_utils_test.go index 43a275a156..93350d68e1 100644 --- a/server/channels/app/import_utils_test.go +++ b/server/channels/app/import_utils_test.go @@ -11,6 +11,7 @@ import ( ) func TestGeneratePassword(t *testing.T) { + mainHelper.Parallel(t) t.Run("Should be the minimum length or 4, whichever is less", func(t *testing.T) { password1, err := generatePassword(5) require.NoError(t, err) diff --git a/server/channels/app/integration_action_test.go b/server/channels/app/integration_action_test.go index 3bb4bbc843..535065d652 100644 --- a/server/channels/app/integration_action_test.go +++ b/server/channels/app/integration_action_test.go @@ -21,6 +21,7 @@ import ( // Test for MM-13598 where an invalid integration URL was causing a crash func TestPostActionInvalidURL(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -71,6 +72,7 @@ func TestPostActionInvalidURL(t *testing.T) { } func TestPostActionEmptyResponse(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -172,6 +174,7 @@ func TestPostActionEmptyResponse(t *testing.T) { } func TestPostAction(t *testing.T) { + mainHelper.Parallel(t) testCases := []struct { Description string Channel func(th *TestHelper) *model.Channel @@ -463,6 +466,7 @@ func TestPostAction(t *testing.T) { } func TestPostActionProps(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -547,6 +551,7 @@ func TestPostActionProps(t *testing.T) { } func TestSubmitInteractiveDialog(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -669,6 +674,7 @@ func TestSubmitInteractiveDialog(t *testing.T) { } func TestPostActionRelativeURL(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -882,6 +888,7 @@ func TestPostActionRelativeURL(t *testing.T) { } func TestPostActionRelativePluginURL(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -891,7 +898,7 @@ func TestPostActionRelativePluginURL(t *testing.T) { import ( "net/http" - "encoding/json" + "encoding/json" "github.com/mattermost/mattermost/server/public/plugin" "github.com/mattermost/mattermost/server/public/model" @@ -1079,6 +1086,7 @@ func TestPostActionRelativePluginURL(t *testing.T) { } func TestDoPluginRequest(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/job_test.go b/server/channels/app/job_test.go index bf3d2eadbd..0cff6b96cb 100644 --- a/server/channels/app/job_test.go +++ b/server/channels/app/job_test.go @@ -15,6 +15,7 @@ import ( ) func TestGetJob(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -36,6 +37,7 @@ func TestGetJob(t *testing.T) { } func TestSessionHasPermissionToCreateJob(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -132,6 +134,7 @@ func TestSessionHasPermissionToCreateJob(t *testing.T) { } func TestSessionHasPermissionToReadJob(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -217,6 +220,7 @@ func TestSessionHasPermissionToReadJob(t *testing.T) { } func TestGetJobByType(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -262,6 +266,7 @@ func TestGetJobByType(t *testing.T) { } func TestGetJobsByTypes(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/license_test.go b/server/channels/app/license_test.go index 344a34f10a..0f17a111f6 100644 --- a/server/channels/app/license_test.go +++ b/server/channels/app/license_test.go @@ -13,6 +13,7 @@ import ( ) func TestLoadLicense(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -21,6 +22,7 @@ func TestLoadLicense(t *testing.T) { } func TestSaveLicense(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -31,6 +33,7 @@ func TestSaveLicense(t *testing.T) { } func TestRemoveLicense(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -39,6 +42,7 @@ func TestRemoveLicense(t *testing.T) { } func TestSetLicense(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -60,6 +64,7 @@ func TestSetLicense(t *testing.T) { } func TestGetSanitizedClientLicense(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/limits_test.go b/server/channels/app/limits_test.go index 06b6c10ea8..5d5183383d 100644 --- a/server/channels/app/limits_test.go +++ b/server/channels/app/limits_test.go @@ -11,6 +11,7 @@ import ( ) func TestGetServerLimits(t *testing.T) { + mainHelper.Parallel(t) t.Run("base case", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/login_test.go b/server/channels/app/login_test.go index 17649e2fc7..b69b106245 100644 --- a/server/channels/app/login_test.go +++ b/server/channels/app/login_test.go @@ -14,10 +14,11 @@ import ( ) func TestCheckForClientSideCert(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() - var tests = []struct { + tests := []struct { pem string subject string expectedEmail string @@ -40,6 +41,7 @@ func TestCheckForClientSideCert(t *testing.T) { } func TestCWSLogin(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() license := model.NewTestLicense() diff --git a/server/channels/app/main_test.go b/server/channels/app/main_test.go index 54c069ba7e..782d756e79 100644 --- a/server/channels/app/main_test.go +++ b/server/channels/app/main_test.go @@ -5,13 +5,18 @@ package app import ( "flag" + "os" + "strconv" "testing" + "github.com/mattermost/mattermost/server/public/shared/mlog" "github.com/mattermost/mattermost/server/v8/channels/testlib" ) -var mainHelper *testlib.MainHelper -var replicaFlag bool +var ( + mainHelper *testlib.MainHelper + replicaFlag bool +) func TestMain(m *testing.M) { if f := flag.Lookup("mysql-replica"); f == nil { @@ -19,10 +24,21 @@ func TestMain(m *testing.M) { flag.Parse() } - var options = testlib.HelperOptions{ + var parallelism int + if f := flag.Lookup("test.parallel"); f != nil { + parallelism, _ = strconv.Atoi(f.Value.String()) + } + runParallel := os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" && parallelism > 1 + if runParallel { + mlog.Info("Fully parallel tests enabled", mlog.Int("parallelism", parallelism)) + } + + options := testlib.HelperOptions{ EnableStore: true, EnableResources: true, WithReadReplica: replicaFlag, + RunParallel: runParallel, + Parallelism: parallelism, } mainHelper = testlib.NewMainHelperWithOptions(&options) diff --git a/server/channels/app/mention_keywords_test.go b/server/channels/app/mention_keywords_test.go index 93c378baa2..fd270bb3e8 100644 --- a/server/channels/app/mention_keywords_test.go +++ b/server/channels/app/mention_keywords_test.go @@ -28,6 +28,7 @@ func mapsToMentionKeywords(userKeywords map[string][]string, groups map[string]* } func TestMentionKeywords_AddUserProfile(t *testing.T) { + mainHelper.Parallel(t) t.Run("should add @user", func(t *testing.T) { user := &model.User{ Id: model.NewId(), diff --git a/server/channels/app/mention_parser_standard_test.go b/server/channels/app/mention_parser_standard_test.go index f770dc9513..6b4cda338b 100644 --- a/server/channels/app/mention_parser_standard_test.go +++ b/server/channels/app/mention_parser_standard_test.go @@ -11,6 +11,7 @@ import ( ) func TestIsKeywordMultibyte(t *testing.T) { + mainHelper.Parallel(t) id1 := model.NewId() for name, tc := range map[string]struct { @@ -116,6 +117,7 @@ func TestIsKeywordMultibyte(t *testing.T) { } func TestCheckForMentionUsers(t *testing.T) { + mainHelper.Parallel(t) id1 := model.NewId() id2 := model.NewId() @@ -213,6 +215,7 @@ func TestCheckForMentionUsers(t *testing.T) { } func TestCheckForMentionGroups(t *testing.T) { + mainHelper.Parallel(t) groupID1 := model.NewId() groupID2 := model.NewId() @@ -279,6 +282,7 @@ func TestCheckForMentionGroups(t *testing.T) { } func TestProcessText(t *testing.T) { + mainHelper.Parallel(t) userID1 := model.NewId() groupID1 := model.NewId() diff --git a/server/channels/app/mention_results_test.go b/server/channels/app/mention_results_test.go index da1f34d965..6e780cb387 100644 --- a/server/channels/app/mention_results_test.go +++ b/server/channels/app/mention_results_test.go @@ -11,6 +11,7 @@ import ( ) func TestAddMention(t *testing.T) { + mainHelper.Parallel(t) t.Run("should initialize Mentions and store new mentions", func(t *testing.T) { m := &MentionResults{} diff --git a/server/channels/app/metrics_test.go b/server/channels/app/metrics_test.go index 4b38572571..cf3ef814e0 100644 --- a/server/channels/app/metrics_test.go +++ b/server/channels/app/metrics_test.go @@ -22,7 +22,9 @@ func configureMetrics(th *TestHelper) { }) th.App.Srv().SetLicense(model.NewTestLicense("metrics")) } + func TestMobileMetrics(t *testing.T) { + mainHelper.Parallel(t) th := SetupEnterprise(t, StartMetrics) defer th.TearDown() diff --git a/server/channels/app/notification_email_test.go b/server/channels/app/notification_email_test.go index f7249e93b1..0facc2c8f8 100644 --- a/server/channels/app/notification_email_test.go +++ b/server/channels/app/notification_email_test.go @@ -22,6 +22,7 @@ import ( ) func TestGetDirectMessageNotificationEmailSubject(t *testing.T) { + mainHelper.Parallel(t) expectedPrefix := "[http://localhost:8065] New Direct Message from @sender on" user := &model.User{} post := &model.Post{ @@ -33,6 +34,7 @@ func TestGetDirectMessageNotificationEmailSubject(t *testing.T) { } func TestGetGroupMessageNotificationEmailSubjectFull(t *testing.T) { + mainHelper.Parallel(t) expectedPrefix := "[http://localhost:8065] New Group Message in sender on" user := &model.User{} post := &model.Post{ @@ -45,6 +47,7 @@ func TestGetGroupMessageNotificationEmailSubjectFull(t *testing.T) { } func TestGetGroupMessageNotificationEmailSubjectGeneric(t *testing.T) { + mainHelper.Parallel(t) expectedPrefix := "[http://localhost:8065] New Group Message on" user := &model.User{} post := &model.Post{ @@ -57,6 +60,7 @@ func TestGetGroupMessageNotificationEmailSubjectGeneric(t *testing.T) { } func TestGetNotificationEmailSubject(t *testing.T) { + mainHelper.Parallel(t) expectedPrefix := "[http://localhost:8065] Notification in team on" user := &model.User{} post := &model.Post{ @@ -68,6 +72,7 @@ func TestGetNotificationEmailSubject(t *testing.T) { } func TestGetNotificationEmailBodyFullNotificationPublicChannel(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -99,6 +104,7 @@ func TestGetNotificationEmailBodyFullNotificationPublicChannel(t *testing.T) { } func TestGetNotificationEmailBodyFullNotificationGroupChannel(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -130,6 +136,7 @@ func TestGetNotificationEmailBodyFullNotificationGroupChannel(t *testing.T) { } func TestGetNotificationEmailBodyFullNotificationPrivateChannel(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -161,6 +168,7 @@ func TestGetNotificationEmailBodyFullNotificationPrivateChannel(t *testing.T) { } func TestGetNotificationEmailBodyFullNotificationDirectChannel(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -192,6 +200,7 @@ func TestGetNotificationEmailBodyFullNotificationDirectChannel(t *testing.T) { } func TestGetNotificationEmailBodyFullNotificationLocaleTimeWithTimezone(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -227,6 +236,7 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTimeWithTimezone(t *testi } func TestGetNotificationEmailBodyFullNotificationLocaleTimeNoTimezone(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -275,6 +285,7 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTimeNoTimezone(t *testing } func TestGetNotificationEmailBodyFullNotificationLocaleTime12Hour(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -308,6 +319,7 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTime12Hour(t *testing.T) } func TestGetNotificationEmailBodyFullNotificationLocaleTime24Hour(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -341,6 +353,7 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTime24Hour(t *testing.T) } func TestGetNotificationEmailBodyWithUserPreference(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -385,6 +398,7 @@ func TestGetNotificationEmailBodyWithUserPreference(t *testing.T) { } func TestGetNotificationEmailBodyFullNotificationWithSlackAttachments(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -483,6 +497,7 @@ func TestGetNotificationEmailBodyFullNotificationWithSlackAttachments(t *testing // from here func TestGetNotificationEmailBodyGenericNotificationPublicChannel(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -513,6 +528,7 @@ func TestGetNotificationEmailBodyGenericNotificationPublicChannel(t *testing.T) } func TestGetNotificationEmailBodyGenericNotificationGroupChannel(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -543,6 +559,7 @@ func TestGetNotificationEmailBodyGenericNotificationGroupChannel(t *testing.T) { } func TestGetNotificationEmailBodyGenericNotificationPrivateChannel(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -573,6 +590,7 @@ func TestGetNotificationEmailBodyGenericNotificationPrivateChannel(t *testing.T) } func TestGetNotificationEmailBodyGenericNotificationDirectChannel(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -603,6 +621,7 @@ func TestGetNotificationEmailBodyGenericNotificationDirectChannel(t *testing.T) } func TestGetNotificationEmailEscapingChars(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -637,6 +656,7 @@ func TestGetNotificationEmailEscapingChars(t *testing.T) { } func TestGetNotificationEmailBodyPublicChannelMention(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -684,6 +704,7 @@ func TestGetNotificationEmailBodyPublicChannelMention(t *testing.T) { } func TestGetNotificationEmailBodyMultiPublicChannelMention(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -756,6 +777,7 @@ func TestGetNotificationEmailBodyMultiPublicChannelMention(t *testing.T) { } func TestGetNotificationEmailBodyPrivateChannelMention(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -803,6 +825,7 @@ func TestGetNotificationEmailBodyPrivateChannelMention(t *testing.T) { } func TestGenerateHyperlinkForChannelsPublic(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -834,6 +857,7 @@ func TestGenerateHyperlinkForChannelsPublic(t *testing.T) { } func TestGenerateHyperlinkForChannelsMultiPublic(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -890,6 +914,7 @@ func TestGenerateHyperlinkForChannelsMultiPublic(t *testing.T) { } func TestGenerateHyperlinkForChannelsPrivate(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -919,6 +944,7 @@ func TestGenerateHyperlinkForChannelsPrivate(t *testing.T) { } func TestLandingLink(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -948,6 +974,7 @@ func TestLandingLink(t *testing.T) { } func TestLandingLinkPermalink(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -978,6 +1005,7 @@ func TestLandingLinkPermalink(t *testing.T) { } func TestMarkdownConversion(t *testing.T) { + mainHelper.Parallel(t) tests := []struct { name string args string diff --git a/server/channels/app/notification_push_test.go b/server/channels/app/notification_push_test.go index 182089c8c2..5103719e1d 100644 --- a/server/channels/app/notification_push_test.go +++ b/server/channels/app/notification_push_test.go @@ -27,6 +27,7 @@ import ( ) func TestDoesNotifyPropsAllowPushNotification(t *testing.T) { + mainHelper.Parallel(t) tt := []struct { name string userNotifySetting string @@ -431,6 +432,7 @@ func TestDoesNotifyPropsAllowPushNotification(t *testing.T) { } func TestDoesStatusAllowPushNotification(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -646,6 +648,7 @@ func TestDoesStatusAllowPushNotification(t *testing.T) { } func TestGetPushNotificationMessage(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -1028,6 +1031,7 @@ func TestGetPushNotificationMessage(t *testing.T) { } func TestBuildPushNotificationMessageMentions(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1084,6 +1088,7 @@ func TestBuildPushNotificationMessageMentions(t *testing.T) { } func TestSendPushNotifications(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() _, err := th.App.CreateSession(th.Context, &model.Session{ @@ -1104,6 +1109,7 @@ func TestSendPushNotifications(t *testing.T) { } func TestShouldSendPushNotifications(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() t.Run("should return true if forced", func(t *testing.T) { @@ -1238,6 +1244,7 @@ func (h *testPushNotificationHandler) notificationAcks() []*model.PushNotificati } func TestClearPushNotificationSync(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -1314,6 +1321,7 @@ func TestClearPushNotificationSync(t *testing.T) { } func TestUpdateMobileAppBadgeSync(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -1373,6 +1381,7 @@ func TestUpdateMobileAppBadgeSync(t *testing.T) { } func TestSendTestPushNotification(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1400,6 +1409,7 @@ func TestSendTestPushNotification(t *testing.T) { } func TestSendAckToPushProxy(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -1444,6 +1454,7 @@ func TestSendAckToPushProxy(t *testing.T) { // TestAllPushNotifications is a master test which sends all various types // of notifications and verifies they have been properly sent. func TestAllPushNotifications(t *testing.T) { + mainHelper.Parallel(t) if testing.Short() { t.Skip("skipping all push notifications test in short mode") } @@ -1554,6 +1565,7 @@ func TestAllPushNotifications(t *testing.T) { } func TestPushNotificationRace(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1610,6 +1622,7 @@ func TestPushNotificationRace(t *testing.T) { } func TestPushNotificationAttachment(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/notification_test.go b/server/channels/app/notification_test.go index 9d508b2b82..7569a3038b 100644 --- a/server/channels/app/notification_test.go +++ b/server/channels/app/notification_test.go @@ -38,6 +38,7 @@ func getLicWithSkuShortName(skuShortName string) *model.License { } func TestSendNotifications(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -217,6 +218,7 @@ func TestSendNotifications(t *testing.T) { } func TestSendNotifications_MentionsFollowers(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -530,6 +532,7 @@ func connectFakeWebSocket(t *testing.T, th *TestHelper, userID string, connectio } func TestConnectFakeWebSocket(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -564,6 +567,7 @@ func TestConnectFakeWebSocket(t *testing.T) { } func TestSendNotificationsWithManyUsers(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -618,6 +622,7 @@ func TestSendNotificationsWithManyUsers(t *testing.T) { } func TestSendOutOfChannelMentions(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -659,6 +664,7 @@ func TestSendOutOfChannelMentions(t *testing.T) { } func TestFilterOutOfChannelMentions(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -852,6 +858,7 @@ func TestFilterOutOfChannelMentions(t *testing.T) { } func TestGetExplicitMentions(t *testing.T) { + mainHelper.Parallel(t) id1 := model.NewId() id2 := model.NewId() id3 := model.NewId() @@ -1440,6 +1447,7 @@ func TestGetExplicitMentions(t *testing.T) { } func TestGetExplicitMentionsAtHere(t *testing.T) { + mainHelper.Parallel(t) t.Run("Boundary cases", func(t *testing.T) { // test all the boundary cases that we know can break up terms (and those that we know won't) cases := map[string]bool{ @@ -1516,6 +1524,7 @@ func TestGetExplicitMentionsAtHere(t *testing.T) { } func TestAllowChannelMentions(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1554,6 +1563,7 @@ func TestAllowChannelMentions(t *testing.T) { } func TestAllowGroupMentions(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1612,6 +1622,7 @@ func TestAllowGroupMentions(t *testing.T) { } func TestGetMentionKeywords(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1937,6 +1948,7 @@ func TestGetMentionKeywords(t *testing.T) { } func TestGetMentionKeywords_Groups(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -2186,6 +2198,7 @@ func TestGetMentionKeywords_Groups(t *testing.T) { } func TestGetMentionsEnabledFields(t *testing.T) { + mainHelper.Parallel(t) attachmentWithTextAndPreText := model.SlackAttachment{ Text: "@here with mentions", Pretext: "@Channel some comment for the channel", @@ -2225,6 +2238,7 @@ func TestGetMentionsEnabledFields(t *testing.T) { } func TestPostNotificationGetChannelName(t *testing.T) { + mainHelper.Parallel(t) sender := &model.User{Id: model.NewId(), Username: "sender", FirstName: "Sender", LastName: "Sender", Nickname: "Sender"} recipient := &model.User{Id: model.NewId(), Username: "recipient", FirstName: "Recipient", LastName: "Recipient", Nickname: "Recipient"} otherUser := &model.User{Id: model.NewId(), Username: "other", FirstName: "Other", LastName: "Other", Nickname: "Other"} @@ -2307,6 +2321,7 @@ func TestPostNotificationGetChannelName(t *testing.T) { } func TestPostNotificationGetSenderName(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -2411,6 +2426,7 @@ func TestPostNotificationGetSenderName(t *testing.T) { } func TestGetNotificationNameFormat(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2434,6 +2450,7 @@ func TestGetNotificationNameFormat(t *testing.T) { } func TestUserAllowsEmail(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -2544,6 +2561,7 @@ func TestUserAllowsEmail(t *testing.T) { } func TestInsertGroupMentions(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2678,6 +2696,7 @@ func TestInsertGroupMentions(t *testing.T) { } func TestGetGroupsAllowedForReferenceInChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2803,6 +2822,7 @@ func TestGetGroupsAllowedForReferenceInChannel(t *testing.T) { } func TestReplyPostNotificationsWithCRT(t *testing.T) { + mainHelper.Parallel(t) t.Run("Reply posts only shows badges for explicit mentions in collapsed threads", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -2959,6 +2979,7 @@ func TestReplyPostNotificationsWithCRT(t *testing.T) { } func TestChannelAutoFollowThreads(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3022,6 +3043,7 @@ func TestChannelAutoFollowThreads(t *testing.T) { } func TestRemoveNotifications(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3135,6 +3157,7 @@ func TestRemoveNotifications(t *testing.T) { } func TestShouldAckWebsocketNotification(t *testing.T) { + mainHelper.Parallel(t) t.Run("should return true if channel notify level is ALL", func(t *testing.T) { assert.True(t, shouldAckWebsocketNotification(model.ChannelTypeOpen, model.UserNotifyNone, model.ChannelNotifyAll)) }) diff --git a/server/channels/app/notify_admin_test.go b/server/channels/app/notify_admin_test.go index 7ab3f13300..c6c6ee3fbf 100644 --- a/server/channels/app/notify_admin_test.go +++ b/server/channels/app/notify_admin_test.go @@ -15,6 +15,7 @@ import ( ) func Test_SendNotifyAdminPosts(t *testing.T) { + mainHelper.Parallel(t) t.Run("no error sending non trial upgrade post when no notifications are available", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -65,7 +66,7 @@ func Test_SendNotifyAdminPosts(t *testing.T) { // message sending is async, wait time for it var channel *model.Channel var err error - var timeout = 5 * time.Second + timeout := 5 * time.Second begin := time.Now() for { if time.Since(begin) > timeout { @@ -112,7 +113,7 @@ func Test_SendNotifyAdminPosts(t *testing.T) { // message sending is async, wait time for it var channel *model.Channel var err error - var timeout = 5 * time.Second + timeout := 5 * time.Second begin := time.Now() for { if time.Since(begin) > timeout { @@ -233,7 +234,7 @@ func Test_SendNotifyAdminPosts(t *testing.T) { // message sending is async, wait time for it var channel *model.Channel var err error - var timeout = 5 * time.Second + timeout := 5 * time.Second begin := time.Now() for { if time.Since(begin) > timeout { diff --git a/server/channels/app/oauth_test.go b/server/channels/app/oauth_test.go index dd523002f1..e5915b22d8 100644 --- a/server/channels/app/oauth_test.go +++ b/server/channels/app/oauth_test.go @@ -25,6 +25,7 @@ import ( ) func TestGetOAuthAccessTokenForImplicitFlow(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -74,6 +75,7 @@ func TestGetOAuthAccessTokenForImplicitFlow(t *testing.T) { } func TestOAuthRevokeAccessToken(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -92,6 +94,7 @@ func TestOAuthRevokeAccessToken(t *testing.T) { } func TestOAuthDeleteApp(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -135,7 +138,10 @@ func TestOAuthDeleteApp(t *testing.T) { } func TestAuthorizeOAuthUser(t *testing.T) { + mainHelper.Parallel(t) setup := func(t *testing.T, enable, tokenEndpoint, userEndpoint bool, serverURL string) *TestHelper { + mainHelper.Parallel(t) + th := Setup(t) th.App.UpdateConfig(func(cfg *model.Config) { @@ -545,6 +551,7 @@ func TestAuthorizeOAuthUser(t *testing.T) { } func TestGetAuthorizationCode(t *testing.T) { + mainHelper.Parallel(t) t.Run("not enabled", func(t *testing.T) { th := Setup(t) defer th.TearDown() @@ -602,6 +609,7 @@ func TestGetAuthorizationCode(t *testing.T) { } func TestDeauthorizeOAuthApp(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -644,6 +652,7 @@ func TestDeauthorizeOAuthApp(t *testing.T) { } func TestDeactivatedUserOAuthApp(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/onboarding_test.go b/server/channels/app/onboarding_test.go index 593846e6d6..59f1917b17 100644 --- a/server/channels/app/onboarding_test.go +++ b/server/channels/app/onboarding_test.go @@ -12,6 +12,7 @@ import ( ) func TestOnboardingSavesOrganizationName(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/opengraph_test.go b/server/channels/app/opengraph_test.go index fc15698f36..2272a85680 100644 --- a/server/channels/app/opengraph_test.go +++ b/server/channels/app/opengraph_test.go @@ -43,6 +43,7 @@ func BenchmarkForceHTMLEncodingToUTF8(b *testing.B) { } func TestMakeOpenGraphURLsAbsolute(t *testing.T) { + mainHelper.Parallel(t) for name, tc := range map[string]struct { HTML string RequestURL string @@ -128,6 +129,7 @@ func TestMakeOpenGraphURLsAbsolute(t *testing.T) { } func TestOpenGraphDecodeHTMLEntities(t *testing.T) { + mainHelper.Parallel(t) og := opengraph.NewOpenGraph() og.Title = "Test's are the best.©" og.Description = "Test's are the worst.©" diff --git a/server/channels/app/permissions_migrations_test.go b/server/channels/app/permissions_migrations_test.go index b684b91b8c..7e382d14ec 100644 --- a/server/channels/app/permissions_migrations_test.go +++ b/server/channels/app/permissions_migrations_test.go @@ -14,6 +14,7 @@ import ( ) func TestApplyPermissionsMap(t *testing.T) { + mainHelper.Parallel(t) tt := []struct { Name string RoleMap map[string]map[string]bool @@ -206,6 +207,7 @@ func TestApplyPermissionsMap(t *testing.T) { } func TestApplyPermissionsMapToSchemeRole(t *testing.T) { + mainHelper.Parallel(t) schemeRoleName := model.NewId() tt := []struct { Name string diff --git a/server/channels/app/permissions_test.go b/server/channels/app/permissions_test.go index 5eeb585058..52d8aecd3e 100644 --- a/server/channels/app/permissions_test.go +++ b/server/channels/app/permissions_test.go @@ -23,6 +23,7 @@ func (tw testWriter) Write(p []byte) (int, error) { } func TestExportPermissions(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -90,6 +91,7 @@ func TestExportPermissions(t *testing.T) { } func TestMigration(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/platform/busy_test.go b/server/channels/app/platform/busy_test.go index d04955c930..ac757703da 100644 --- a/server/channels/app/platform/busy_test.go +++ b/server/channels/app/platform/busy_test.go @@ -16,6 +16,8 @@ import ( ) func TestBusySet(t *testing.T) { + mainHelper.Parallel(t) + cluster := &ClusterMock{Busy: &Busy{}, t: t} busy := NewBusy(cluster) @@ -30,9 +32,9 @@ func TestBusySet(t *testing.T) { require.True(t, compareBusyState(t, busy, cluster.Busy)) // should automatically expire after 5s. - require.Eventually(t, isNotBusy, time.Second*15, time.Millisecond*100) + require.Eventually(t, isNotBusy, time.Second*10, time.Millisecond*100) // allow a moment for cluster to sync. - require.Eventually(t, func() bool { return compareBusyState(t, busy, cluster.Busy) }, time.Second*15, time.Millisecond*20) + require.Eventually(t, func() bool { return compareBusyState(t, busy, cluster.Busy) }, time.Second*5, time.Millisecond*20) // test set after auto expiry. busy.Set(time.Second * 30) @@ -54,6 +56,8 @@ func TestBusySet(t *testing.T) { } func TestBusyExpires(t *testing.T) { + mainHelper.Parallel(t) + cluster := &ClusterMock{Busy: &Busy{}, t: t} busy := NewBusy(cluster) @@ -86,10 +90,12 @@ func TestBusyExpires(t *testing.T) { // should be time.Time zero value require.Equal(t, time.Time{}.Unix(), expire.Unix()) // allow a moment for cluster to sync - require.Eventually(t, func() bool { return compareBusyState(t, busy, cluster.Busy) }, time.Second*15, time.Millisecond*20) + require.Eventually(t, func() bool { return compareBusyState(t, busy, cluster.Busy) }, time.Second*5, time.Millisecond*20) } func TestBusyRace(t *testing.T) { + mainHelper.Parallel(t) + cluster := &ClusterMock{Busy: &Busy{}, t: t} busy := NewBusy(cluster) @@ -147,12 +153,15 @@ func (c *ClusterMock) NotifyMsg(buf []byte) {} func (c *ClusterMock) GetClusterStats(rctx request.CTX) ([]*model.ClusterStats, *model.AppError) { return nil, nil } + func (c *ClusterMock) GetLogs(rctx request.CTX, page, perPage int) ([]string, *model.AppError) { return nil, nil } + func (c *ClusterMock) QueryLogs(rctx request.CTX, page, perPage int) (map[string][]string, *model.AppError) { return nil, nil } + func (c *ClusterMock) GenerateSupportPacket(rctx request.CTX, options *model.SupportPacketOptions) (map[string][]model.FileData, error) { return nil, nil } @@ -164,6 +173,7 @@ func (c *ClusterMock) HealthScore() int { return 0 } func (c *ClusterMock) WebConnCountForUser(userID string) (int, *model.AppError) { return 0, nil } + func (c *ClusterMock) GetWSQueues(userID, connectionID string, seqNum int64) (map[string]*model.WSQueues, error) { return nil, nil } diff --git a/server/channels/app/platform/cluster_discovery_test.go b/server/channels/app/platform/cluster_discovery_test.go index 1a68059cc8..167c49ea6a 100644 --- a/server/channels/app/platform/cluster_discovery_test.go +++ b/server/channels/app/platform/cluster_discovery_test.go @@ -11,6 +11,7 @@ import ( ) func TestClusterDiscoveryService(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/platform/config_test.go b/server/channels/app/platform/config_test.go index 5968365b3c..11892b5974 100644 --- a/server/channels/app/platform/config_test.go +++ b/server/channels/app/platform/config_test.go @@ -18,6 +18,7 @@ import ( ) func TestConfigListener(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -53,6 +54,7 @@ func TestConfigListener(t *testing.T) { } func TestConfigSave(t *testing.T) { + mainHelper.Parallel(t) cm := &mocks.ClusterInterface{} cm.On("SendClusterMessage", mock.AnythingOfType("*model.ClusterMessage")).Return(nil) th := SetupWithCluster(t, cm) @@ -106,6 +108,7 @@ func TestConfigSave(t *testing.T) { } func TestIsFirstUserAccount(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() storeMock := th.Service.Store.(*smocks.Store) @@ -148,6 +151,7 @@ func TestIsFirstUserAccount(t *testing.T) { } func TestIsFirstUserAccountThunderingHerd(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() storeMock := th.Service.Store.(*smocks.Store) diff --git a/server/channels/app/platform/helper_test.go b/server/channels/app/platform/helper_test.go index 28308fde1a..bd08695913 100644 --- a/server/channels/app/platform/helper_test.go +++ b/server/channels/app/platform/helper_test.go @@ -25,6 +25,7 @@ type TestHelper struct { Context request.CTX Service *PlatformService Suite SuiteIFace + Store store.Store BasicTeam *model.Team BasicUser *model.User @@ -35,15 +36,16 @@ type TestHelper struct { SystemAdminUser *model.User } -var initBasicOnce sync.Once -var userCache struct { - SystemAdminUser *model.User - BasicUser *model.User - BasicUser2 *model.User -} +var ( + initBasicOnce sync.Once + userCache struct { + SystemAdminUser *model.User + BasicUser *model.User + BasicUser2 *model.User + } +) -type mockSuite struct { -} +type mockSuite struct{} func (ms *mockSuite) SetStatusLastActivityAt(userID string, activityAt int64) {} func (ms *mockSuite) SetStatusOffline(userID string, manual bool, force bool) {} @@ -58,20 +60,38 @@ func (ms *mockSuite) RolesGrantPermission(roleNames []string, permissionId strin func (ms *mockSuite) UserCanSeeOtherUser(c request.CTX, userID string, otherUserId string) (bool, *model.AppError) { return true, nil } + func (ms *mockSuite) HasPermissionToReadChannel(c request.CTX, userID string, channel *model.Channel) bool { return true } +func setupDBStore(tb testing.TB) (store.Store, *model.SqlSettings) { + var dbStore store.Store + var dbSettings *model.SqlSettings + if mainHelper.Options.RunParallel { + dbStore, _, dbSettings, _ = mainHelper.GetNewStores(tb) + tb.Cleanup(func() { + dbStore.Close() + }) + } else { + dbStore = mainHelper.GetStore() + dbStore.DropAllTables() + dbStore.MarkSystemRanUnitTests() + dbSettings = mainHelper.Settings + mainHelper.PreloadMigrations() + } + + return dbStore, dbSettings +} + func Setup(tb testing.TB, options ...Option) *TestHelper { if testing.Short() { tb.SkipNow() } - dbStore := mainHelper.GetStore() - dbStore.DropAllTables() - dbStore.MarkSystemRanUnitTests() - mainHelper.PreloadMigrations() - return setupTestHelper(dbStore, false, true, tb, options...) + dbStore, dbSettings := setupDBStore(tb) + + return setupTestHelper(dbStore, dbSettings, false, true, tb, options...) } func (th *TestHelper) InitBasic() *TestHelper { @@ -92,7 +112,7 @@ func (th *TestHelper) InitBasic() *TestHelper { th.BasicUser2 = userCache.BasicUser2.DeepCopy() users := []*model.User{th.SystemAdminUser, th.BasicUser, th.BasicUser2} - mainHelper.GetSQLStore().User().InsertUsers(users) + th.Store.User().InsertUsers(users) th.BasicTeam = th.CreateTeam() @@ -106,7 +126,7 @@ func (th *TestHelper) InitBasic() *TestHelper { func SetupWithStoreMock(tb testing.TB, options ...Option) *TestHelper { mockStore := testlib.GetMockStoreForSetupFunctions() options = append(options, StoreOverride(mockStore)) - th := setupTestHelper(mockStore, false, false, tb, options...) + th := setupTestHelper(mockStore, &model.SqlSettings{}, false, false, tb, options...) return th } @@ -114,18 +134,16 @@ func SetupWithCluster(tb testing.TB, cluster einterfaces.ClusterInterface) *Test if testing.Short() { tb.SkipNow() } - dbStore := mainHelper.GetStore() - dbStore.DropAllTables() - dbStore.MarkSystemRanUnitTests() - mainHelper.PreloadMigrations() - th := setupTestHelper(dbStore, true, true, tb) + dbStore, dbSettings := setupDBStore(tb) + + th := setupTestHelper(dbStore, dbSettings, true, true, tb) th.Service.clusterIFace = cluster return th } -func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer bool, tb testing.TB, options ...Option) *TestHelper { +func setupTestHelper(dbStore store.Store, dbSettings *model.SqlSettings, enterprise bool, includeCacheLayer bool, tb testing.TB, options ...Option) *TestHelper { tempWorkspace, err := os.MkdirTemp("", "apptest") if err != nil { panic(err) @@ -134,7 +152,7 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo configStore := config.NewTestMemoryStore() memoryConfig := configStore.Get() - memoryConfig.SqlSettings = *mainHelper.GetSQLSettings() + memoryConfig.SqlSettings = *dbSettings *memoryConfig.PluginSettings.Directory = filepath.Join(tempWorkspace, "plugins") *memoryConfig.PluginSettings.ClientDirectory = filepath.Join(tempWorkspace, "webapp") *memoryConfig.PluginSettings.AutomaticPrepackagedPlugins = false @@ -161,6 +179,7 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo Context: request.TestContext(tb), Service: ps, Suite: &mockSuite{}, + Store: dbStore, } if _, ok := dbStore.(*mocks.Store); ok { diff --git a/server/channels/app/platform/license_test.go b/server/channels/app/platform/license_test.go index 13d5ed3ced..907c513988 100644 --- a/server/channels/app/platform/license_test.go +++ b/server/channels/app/platform/license_test.go @@ -18,6 +18,7 @@ import ( ) func TestLoadLicense(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -26,6 +27,7 @@ func TestLoadLicense(t *testing.T) { } func TestSaveLicense(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -75,6 +77,7 @@ func TestSaveEnterpriseAdvancedLicense(t *testing.T) { } func TestRemoveLicense(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -83,6 +86,7 @@ func TestRemoveLicense(t *testing.T) { } func TestSetLicense(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -104,6 +108,7 @@ func TestSetLicense(t *testing.T) { } func TestGetSanitizedClientLicense(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/platform/log_test.go b/server/channels/app/platform/log_test.go index 72caed332e..8f300e5d89 100644 --- a/server/channels/app/platform/log_test.go +++ b/server/channels/app/platform/log_test.go @@ -19,6 +19,8 @@ import ( ) func TestGetMattermostLog(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t) defer th.TearDown() @@ -72,6 +74,8 @@ func TestGetMattermostLog(t *testing.T) { } func TestGetNotificationLogFile(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t) defer th.TearDown() @@ -117,6 +121,8 @@ func TestGetNotificationLogFile(t *testing.T) { } func TestGetAdvancedLogs(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/platform/main_test.go b/server/channels/app/platform/main_test.go index 6b68df2aa4..767dd25eb3 100644 --- a/server/channels/app/platform/main_test.go +++ b/server/channels/app/platform/main_test.go @@ -5,13 +5,18 @@ package platform import ( "flag" + "os" + "strconv" "testing" + "github.com/mattermost/mattermost/server/public/shared/mlog" "github.com/mattermost/mattermost/server/v8/channels/testlib" ) -var mainHelper *testlib.MainHelper -var replicaFlag bool +var ( + mainHelper *testlib.MainHelper + replicaFlag bool +) func TestMain(m *testing.M) { if f := flag.Lookup("mysql-replica"); f == nil { @@ -19,10 +24,21 @@ func TestMain(m *testing.M) { flag.Parse() } - var options = testlib.HelperOptions{ + var parallelism int + if f := flag.Lookup("test.parallel"); f != nil { + parallelism, _ = strconv.Atoi(f.Value.String()) + } + runParallel := os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" && parallelism > 1 + if runParallel { + mlog.Info("Fully parallel tests enabled", mlog.Int("parallelism", parallelism)) + } + + options := testlib.HelperOptions{ EnableStore: true, EnableResources: true, WithReadReplica: replicaFlag, + RunParallel: runParallel, + Parallelism: parallelism, } mainHelper = testlib.NewMainHelperWithOptions(&options) diff --git a/server/channels/app/platform/service_test.go b/server/channels/app/platform/service_test.go index 4e0eec6a94..c21c15074a 100644 --- a/server/channels/app/platform/service_test.go +++ b/server/channels/app/platform/service_test.go @@ -59,6 +59,7 @@ func TestSetLicenseOnStart(t *testing.T) { } func TestReadReplicaDisabledBasedOnLicense(t *testing.T) { + mainHelper.Parallel(t) cfg := model.Config{} cfg.SetDefaults() driverName := os.Getenv("MM_SQLSETTINGS_DRIVERNAME") @@ -131,7 +132,9 @@ func TestReadReplicaDisabledBasedOnLicense(t *testing.T) { } func TestMetrics(t *testing.T) { + mainHelper.Parallel(t) t.Run("ensure the metrics server is not started by default", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -139,6 +142,7 @@ func TestMetrics(t *testing.T) { }) t.Run("ensure the metrics server is started", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t, StartMetrics()) defer th.TearDown() @@ -166,6 +170,7 @@ func TestMetrics(t *testing.T) { }) t.Run("ensure the metrics server is started with advanced metrics", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t, StartMetrics()) defer th.TearDown() @@ -180,6 +185,7 @@ func TestMetrics(t *testing.T) { }) t.Run("ensure advanced metrics have database metrics", func(t *testing.T) { + mainHelper.Parallel(t) mockMetricsImpl := &mocks.MetricsInterface{} mockMetricsImpl.On("Register").Return() mockMetricsImpl.On("ObserveStoreMethodDuration", mock.Anything, mock.Anything, mock.Anything).Return() @@ -198,6 +204,7 @@ func TestMetrics(t *testing.T) { } func TestShutdown(t *testing.T) { + mainHelper.Parallel(t) t.Run("should shutdown gracefully", func(t *testing.T) { th := Setup(t) rand.Seed(time.Now().UnixNano()) @@ -219,6 +226,7 @@ func TestShutdown(t *testing.T) { } func TestSetTelemetryId(t *testing.T) { + mainHelper.Parallel(t) t.Run("ensure client config is regenerated after setting the telemetry id", func(t *testing.T) { th := Setup(t) defer th.TearDown() @@ -235,6 +243,7 @@ func TestSetTelemetryId(t *testing.T) { } func TestDatabaseTypeAndMattermostVersion(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/platform/session_test.go b/server/channels/app/platform/session_test.go index bca401db72..e83f924d55 100644 --- a/server/channels/app/platform/session_test.go +++ b/server/channels/app/platform/session_test.go @@ -19,6 +19,7 @@ const ( ) func TestCache(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -71,6 +72,7 @@ func TestCache(t *testing.T) { } func TestSetSessionExpireInHours(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -117,6 +119,7 @@ func TestSetSessionExpireInHours(t *testing.T) { } func TestOAuthRevokeAccessToken(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -149,6 +152,7 @@ func TestOAuthRevokeAccessToken(t *testing.T) { } func TestUpdateSessionsIsGuest(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/platform/support_packet_test.go b/server/channels/app/platform/support_packet_test.go index 281bec6c5d..b179968ac4 100644 --- a/server/channels/app/platform/support_packet_test.go +++ b/server/channels/app/platform/support_packet_test.go @@ -25,6 +25,8 @@ import ( ) func TestGenerateSupportPacket(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/platform/web_broadcast_hook_test.go b/server/channels/app/platform/web_broadcast_hook_test.go index 0573f62379..9fb13276dc 100644 --- a/server/channels/app/platform/web_broadcast_hook_test.go +++ b/server/channels/app/platform/web_broadcast_hook_test.go @@ -25,6 +25,7 @@ func (h *testBroadcastHook) Process(msg *HookedWebSocketEvent, webConn *WebConn, } func TestRunBroadcastHooks(t *testing.T) { + mainHelper.Parallel(t) hub := &Hub{ broadcastHooks: map[string]BroadcastHook{ broadcastTest: &testBroadcastHook{}, diff --git a/server/channels/app/platform/web_hub_test.go b/server/channels/app/platform/web_hub_test.go index dc6ad09264..96c7953031 100644 --- a/server/channels/app/platform/web_hub_test.go +++ b/server/channels/app/platform/web_hub_test.go @@ -60,6 +60,7 @@ func registerDummyWebConn(t *testing.T, th *TestHelper, addr net.Addr, session * } func TestHubStopWithMultipleConnections(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -84,6 +85,7 @@ func TestHubStopWithMultipleConnections(t *testing.T) { // TestHubStopRaceCondition verifies that attempts to use the hub after it has shutdown does not // block the caller indefinitely. func TestHubStopRaceCondition(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.Service.Store.Close() // We do not call TearDown because th.TearDown shuts down the hub again. And hub close is not idempotent. @@ -131,6 +133,7 @@ func TestHubStopRaceCondition(t *testing.T) { } func TestHubSessionRevokeRace(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -184,6 +187,7 @@ func TestHubSessionRevokeRace(t *testing.T) { } func TestHubConnIndex(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -435,6 +439,7 @@ func TestHubConnIndex(t *testing.T) { } func TestHubConnIndexIncorrectRemoval(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -485,6 +490,7 @@ func TestHubConnIndexIncorrectRemoval(t *testing.T) { } func TestHubConnIndexInactive(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -549,6 +555,7 @@ func TestHubConnIndexInactive(t *testing.T) { } func TestReliableWebSocketSend(t *testing.T) { + mainHelper.Parallel(t) testCluster := &testlib.FakeClusterInterface{} th := SetupWithCluster(t, testCluster) @@ -584,6 +591,7 @@ func TestReliableWebSocketSend(t *testing.T) { } func TestHubIsRegistered(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -620,6 +628,7 @@ func TestHubIsRegistered(t *testing.T) { } func TestHubWebConnCount(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -841,6 +850,7 @@ func BenchmarkHubConnIndex(b *testing.B) { } func TestHubConnIndexRemoveMemLeak(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -893,6 +903,7 @@ func BenchmarkGetHubForUserId(b *testing.B) { } func TestClusterBroadcast(t *testing.T) { + mainHelper.Parallel(t) testCluster := &testlib.FakeClusterInterface{} th := SetupWithCluster(t, testCluster) @@ -921,6 +932,7 @@ func TestClusterBroadcast(t *testing.T) { } func TestClusterBroadcastHooks(t *testing.T) { + mainHelper.Parallel(t) t.Run("should send broadcast hook information across cluster", func(t *testing.T) { testCluster := &testlib.FakeClusterInterface{} diff --git a/server/channels/app/plugin_api_test.go b/server/channels/app/plugin_api_test.go index 4cde27ce87..25bb36f1c4 100644 --- a/server/channels/app/plugin_api_test.go +++ b/server/channels/app/plugin_api_test.go @@ -134,6 +134,7 @@ func setupPluginAPITest(t *testing.T, pluginCode string, pluginManifest string, } func TestPublicFilesPathConfiguration(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -164,6 +165,7 @@ func TestPublicFilesPathConfiguration(t *testing.T) { } func TestPluginAPIGetUserPreference(t *testing.T) { + mainHelper.Parallel(t) t.Run("should return preferences when called", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -211,6 +213,7 @@ func TestPluginAPIGetUserPreference(t *testing.T) { } func TestPluginAPIGetUserPreferences(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() api := th.SetupPluginAPI() @@ -244,6 +247,7 @@ func TestPluginAPIGetUserPreferences(t *testing.T) { } func TestPluginAPIDeleteUserPreferences(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() api := th.SetupPluginAPI() @@ -305,6 +309,7 @@ func TestPluginAPIDeleteUserPreferences(t *testing.T) { } func TestPluginAPIUpdateUserPreferences(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() api := th.SetupPluginAPI() @@ -356,6 +361,7 @@ func TestPluginAPIUpdateUserPreferences(t *testing.T) { } func TestPluginAPIGetUsers(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).DeleteBots() defer th.TearDown() api := th.SetupPluginAPI() @@ -455,6 +461,7 @@ func TestPluginAPIGetUsers(t *testing.T) { } func TestPluginAPIGetUsersByIds(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).DeleteBots() defer th.TearDown() api := th.SetupPluginAPI() @@ -519,6 +526,7 @@ func TestPluginAPIGetUsersByIds(t *testing.T) { } func TestPluginAPIGetUsersInTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() api := th.SetupPluginAPI() @@ -647,6 +655,7 @@ func TestPluginAPIGetUsersInTeam(t *testing.T) { } func TestPluginAPIUserCustomStatus(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() api := th.SetupPluginAPI() @@ -703,6 +712,7 @@ func TestPluginAPIUserCustomStatus(t *testing.T) { } func TestPluginAPIGetFile(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() api := th.SetupPluginAPI() @@ -731,6 +741,7 @@ func TestPluginAPIGetFile(t *testing.T) { } func TestPluginAPIGetFileInfos(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() api := th.SetupPluginAPI() @@ -828,6 +839,7 @@ func TestPluginAPIGetFileInfos(t *testing.T) { } func TestPluginAPISavePluginConfig(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -871,6 +883,7 @@ func TestPluginAPISavePluginConfig(t *testing.T) { } func TestPluginAPILoadPluginConfiguration(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -904,6 +917,7 @@ func TestPluginAPILoadPluginConfiguration(t *testing.T) { } func TestPluginAPILoadPluginConfigurationDefaults(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -941,6 +955,7 @@ func TestPluginAPILoadPluginConfigurationDefaults(t *testing.T) { } func TestPluginAPIGetPlugins(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() api := th.SetupPluginAPI() @@ -1000,6 +1015,7 @@ func TestPluginAPIGetPlugins(t *testing.T) { } func TestPluginAPIInstallPlugin(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() api := th.SetupPluginAPI() @@ -1036,6 +1052,7 @@ func TestPluginAPIInstallPlugin(t *testing.T) { } func TestInstallPlugin(t *testing.T) { + mainHelper.Parallel(t) // TODO(ilgooz): remove this setup func to use existent setupPluginAPITest(). // following setupTest() func is a modified version of setupPluginAPITest(). // we need a modified version of setupPluginAPITest() because it wasn't possible to use it directly here @@ -1162,6 +1179,7 @@ func TestInstallPlugin(t *testing.T) { } func TestPluginAPIGetTeamIcon(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() api := th.SetupPluginAPI() @@ -1193,6 +1211,7 @@ func TestPluginAPIGetTeamIcon(t *testing.T) { } func TestPluginAPISetTeamIcon(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() api := th.SetupPluginAPI() @@ -1223,6 +1242,7 @@ func TestPluginAPISetTeamIcon(t *testing.T) { } func TestPluginAPIRemoveTeamIcon(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() api := th.SetupPluginAPI() @@ -1278,6 +1298,7 @@ func pluginAPIHookTest(t *testing.T, th *TestHelper, fileName string, id string, // 5. Successfully running test should return nil, "OK". Any other returned string is considered and error func TestBasicAPIPlugins(t *testing.T) { + mainHelper.Parallel(t) defaultSchema := getDefaultPluginSettingsSchema() testFolder := filepath.Join(server.GetPackagePath(), "channels", "app", "plugin_api_tests") dirs, err := os.ReadDir(testFolder) @@ -1286,6 +1307,8 @@ func TestBasicAPIPlugins(t *testing.T) { d := dir.Name() if dir.IsDir() && !strings.HasPrefix(d, "manual.") { t.Run(d, func(t *testing.T) { + mainHelper.Parallel(t) + mainPath := filepath.Join(testFolder, d, "main.go") _, err := os.Stat(mainPath) require.NoError(t, err, "Cannot find plugin main file at %v", mainPath) @@ -1300,6 +1323,7 @@ func TestBasicAPIPlugins(t *testing.T) { } func TestPluginAPIKVCompareAndSet(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() api := th.SetupPluginAPI() @@ -1396,6 +1420,7 @@ func TestPluginAPIKVCompareAndSet(t *testing.T) { } func TestPluginAPIKVCompareAndDelete(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() api := th.SetupPluginAPI() @@ -1448,6 +1473,7 @@ func TestPluginAPIKVCompareAndDelete(t *testing.T) { } func TestPluginCreateBot(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() api := th.SetupPluginAPI() @@ -1469,6 +1495,7 @@ func TestPluginCreateBot(t *testing.T) { } func TestPluginCreatePostWithUploadedFile(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() api := th.SetupPluginAPI() @@ -1505,6 +1532,7 @@ func TestPluginCreatePostWithUploadedFile(t *testing.T) { } func TestPluginCreatePostAddsFromPluginProp(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() api := th.SetupPluginAPI() @@ -1524,6 +1552,7 @@ func TestPluginCreatePostAddsFromPluginProp(t *testing.T) { } func TestPluginAPIGetConfig(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() api := th.SetupPluginAPI() @@ -1561,6 +1590,7 @@ func TestPluginAPIGetConfig(t *testing.T) { } func TestPluginAPIGetUnsanitizedConfig(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() api := th.SetupPluginAPI() @@ -1598,6 +1628,7 @@ func TestPluginAPIGetUnsanitizedConfig(t *testing.T) { } func TestPluginAddUserToChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() api := th.SetupPluginAPI() @@ -1610,6 +1641,7 @@ func TestPluginAddUserToChannel(t *testing.T) { } func TestInterpluginPluginHTTP(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1740,6 +1772,7 @@ func TestInterpluginPluginHTTP(t *testing.T) { } func TestAPIMetrics(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1821,6 +1854,7 @@ func TestAPIMetrics(t *testing.T) { } func TestPluginAPIGetPostsForChannel(t *testing.T) { + mainHelper.Parallel(t) require := require.New(t) th := Setup(t).InitBasic() @@ -1864,6 +1898,7 @@ func TestPluginAPIGetPostsForChannel(t *testing.T) { } func TestPluginHTTPConnHijack(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1983,6 +2018,7 @@ func TestPluginMFAEnforcement(t *testing.T) { } func TestPluginHTTPUpgradeWebSocket(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -2054,6 +2090,7 @@ func (mscp *MockSlashCommandProvider) DoCommand(a *App, c request.CTX, args *mod } func TestPluginExecuteSlashCommand(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() api := th.SetupPluginAPI() @@ -2079,6 +2116,7 @@ func TestPluginExecuteSlashCommand(t *testing.T) { } func TestPluginAPISearchPostsInTeamByUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() api := th.SetupPluginAPI() @@ -2126,6 +2164,7 @@ func TestPluginAPISearchPostsInTeamByUser(t *testing.T) { } func TestPluginAPICreateCommandAndListCommands(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() api := th.SetupPluginAPI() @@ -2164,6 +2203,7 @@ func TestPluginAPICreateCommandAndListCommands(t *testing.T) { } func TestPluginAPIUpdateCommand(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() api := th.SetupPluginAPI() @@ -2222,6 +2262,7 @@ func TestPluginAPIIsEnterpriseReady(t *testing.T) { } func TestPluginUploadsAPI(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2321,6 +2362,7 @@ func TestPluginUploadsAPI(t *testing.T) { var configurationWillBeSavedHookTemplate string func TestConfigurationWillBeSavedHook(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2422,6 +2464,7 @@ func TestConfigurationWillBeSavedHook(t *testing.T) { } func TestSendPushNotification(t *testing.T) { + mainHelper.Parallel(t) if testing.Short() { t.Skip("skipping TestSendPushNotification test in short mode") } @@ -2519,6 +2562,7 @@ func TestSendPushNotification(t *testing.T) { } func TestPluginServeMetrics(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t, StartMetrics) defer th.TearDown() @@ -2577,6 +2621,7 @@ func TestPluginServeMetrics(t *testing.T) { } func TestPluginGetChannelsForTeamForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2680,6 +2725,7 @@ func TestPluginGetChannelsForTeamForUser(t *testing.T) { } func TestPluginPatchChannelMembersNotifications(t *testing.T) { + mainHelper.Parallel(t) t.Run("should be able to set fields for multiple members", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/plugin_commands_test.go b/server/channels/app/plugin_commands_test.go index 76dec63f97..69ba8fd648 100644 --- a/server/channels/app/plugin_commands_test.go +++ b/server/channels/app/plugin_commands_test.go @@ -14,6 +14,7 @@ import ( ) func TestPluginCommand(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/plugin_db_driver_test.go b/server/channels/app/plugin_db_driver_test.go index 6f9c8f0d61..09b6258f44 100644 --- a/server/channels/app/plugin_db_driver_test.go +++ b/server/channels/app/plugin_db_driver_test.go @@ -10,6 +10,7 @@ import ( ) func TestConnCreateTimeout(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -21,6 +22,7 @@ func TestConnCreateTimeout(t *testing.T) { } func TestShutdownPluginConns(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/plugin_deadlock_test.go b/server/channels/app/plugin_deadlock_test.go index caaf85a147..35f122d965 100644 --- a/server/channels/app/plugin_deadlock_test.go +++ b/server/channels/app/plugin_deadlock_test.go @@ -16,6 +16,7 @@ import ( ) func TestPluginDeadlock(t *testing.T) { + mainHelper.Parallel(t) t.Run("Single Plugin", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/plugin_health_check_test.go b/server/channels/app/plugin_health_check_test.go index e3f8f26855..fac673b359 100644 --- a/server/channels/app/plugin_health_check_test.go +++ b/server/channels/app/plugin_health_check_test.go @@ -13,6 +13,7 @@ import ( ) func TestHealthCheckJob(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/plugin_hooks_test.go b/server/channels/app/plugin_hooks_test.go index 65d4874f9e..dcf3a2fdb7 100644 --- a/server/channels/app/plugin_hooks_test.go +++ b/server/channels/app/plugin_hooks_test.go @@ -75,7 +75,9 @@ func setAppEnvironmentWithPlugins(t *testing.T, pluginCode []string, app *App, a } func TestHookMessageWillBePosted(t *testing.T) { + mainHelper.Parallel(t) t.Run("rejected", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -116,6 +118,7 @@ func TestHookMessageWillBePosted(t *testing.T) { }) t.Run("rejected, returned post ignored", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -157,6 +160,7 @@ func TestHookMessageWillBePosted(t *testing.T) { }) t.Run("allowed", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -200,6 +204,7 @@ func TestHookMessageWillBePosted(t *testing.T) { }) t.Run("updated", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -244,6 +249,7 @@ func TestHookMessageWillBePosted(t *testing.T) { }) t.Run("multiple updated", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -307,6 +313,7 @@ func TestHookMessageWillBePosted(t *testing.T) { } func TestHookMessageHasBeenPosted(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -350,6 +357,7 @@ func TestHookMessageHasBeenPosted(t *testing.T) { } func TestHookMessageWillBeUpdated(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -395,6 +403,7 @@ func TestHookMessageWillBeUpdated(t *testing.T) { } func TestHookMessageHasBeenUpdated(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -443,6 +452,7 @@ func TestHookMessageHasBeenUpdated(t *testing.T) { } func TestHookMessageHasBeenDeleted(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -488,7 +498,9 @@ func TestHookMessageHasBeenDeleted(t *testing.T) { } func TestHookFileWillBeUploaded(t *testing.T) { + mainHelper.Parallel(t) t.Run("rejected", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -533,6 +545,7 @@ func TestHookFileWillBeUploaded(t *testing.T) { }) t.Run("rejected, returned file ignored", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -583,6 +596,7 @@ func TestHookFileWillBeUploaded(t *testing.T) { }) t.Run("allowed", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -639,6 +653,7 @@ func TestHookFileWillBeUploaded(t *testing.T) { }) t.Run("updated", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -712,6 +727,7 @@ func TestHookFileWillBeUploaded(t *testing.T) { } func TestUserWillLogIn_Blocked(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -751,6 +767,7 @@ func TestUserWillLogIn_Blocked(t *testing.T) { } func TestUserWillLogInIn_Passed(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -793,6 +810,7 @@ func TestUserWillLogInIn_Passed(t *testing.T) { } func TestUserHasLoggedIn(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -840,6 +858,7 @@ func TestUserHasLoggedIn(t *testing.T) { } func TestUserHasBeenDeactivated(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -889,6 +908,7 @@ func TestUserHasBeenDeactivated(t *testing.T) { } func TestUserHasBeenCreated(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -934,6 +954,7 @@ func TestUserHasBeenCreated(t *testing.T) { } func TestErrorString(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1008,6 +1029,7 @@ func TestErrorString(t *testing.T) { } func TestHookContext(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() ctx := request.EmptyContext(th.TestLogger) @@ -1063,6 +1085,7 @@ func TestHookContext(t *testing.T) { } func TestActiveHooks(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1134,6 +1157,7 @@ func TestActiveHooks(t *testing.T) { } func TestHookMetrics(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1233,6 +1257,7 @@ func TestHookMetrics(t *testing.T) { } func TestHookReactionHasBeenAdded(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1276,6 +1301,7 @@ func TestHookReactionHasBeenAdded(t *testing.T) { } func TestHookReactionHasBeenRemoved(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1325,6 +1351,7 @@ func TestHookReactionHasBeenRemoved(t *testing.T) { } func TestHookRunDataRetention(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1370,6 +1397,7 @@ func TestHookRunDataRetention(t *testing.T) { } func TestHookOnSendDailyTelemetry(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1414,6 +1442,7 @@ func TestHookOnSendDailyTelemetry(t *testing.T) { } func TestHookOnCloudLimitsUpdated(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1462,6 +1491,7 @@ func TestHookOnCloudLimitsUpdated(t *testing.T) { var hookNotificationWillBePushedTmpl string func TestHookNotificationWillBePushed(t *testing.T) { + mainHelper.Parallel(t) if testing.Short() { t.Skip("skipping TestHookNotificationWillBePushed test in short mode") } @@ -1492,6 +1522,8 @@ func TestHookNotificationWillBePushed(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() @@ -1586,6 +1618,8 @@ func TestHookNotificationWillBePushed(t *testing.T) { } func TestHookMessagesWillBeConsumed(t *testing.T) { + mainHelper.Parallel(t) + setupPlugin := func(t *testing.T, th *TestHelper) { var mockAPI plugintest.API mockAPI.On("LoadPluginConfiguration", mock.Anything).Return(nil) @@ -1618,10 +1652,11 @@ func TestHookMessagesWillBeConsumed(t *testing.T) { } t.Run("feature flag disabled", func(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_CONSUMEPOSTHOOK", "false") - defer os.Unsetenv("MM_FEATUREFLAGS_CONSUMEPOSTHOOK") + mainHelper.Parallel(t) - th := Setup(t).InitBasic() + th := SetupConfig(t, func(cfg *model.Config) { + cfg.FeatureFlags.ConsumePostHook = false + }).InitBasic() t.Cleanup(th.TearDown) setupPlugin(t, th) @@ -1641,10 +1676,12 @@ func TestHookMessagesWillBeConsumed(t *testing.T) { }) t.Run("feature flag enabled", func(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_CONSUMEPOSTHOOK", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_CONSUMEPOSTHOOK") + mainHelper.Parallel(t) + + th := SetupConfig(t, func(cfg *model.Config) { + cfg.FeatureFlags.ConsumePostHook = true + }).InitBasic() - th := Setup(t).InitBasic() t.Cleanup(th.TearDown) setupPlugin(t, th) @@ -1665,7 +1702,9 @@ func TestHookMessagesWillBeConsumed(t *testing.T) { } func TestHookPreferencesHaveChanged(t *testing.T) { + mainHelper.Parallel(t) t.Run("should be called when preferences are changed by non-plugin code", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1734,6 +1773,7 @@ func TestHookPreferencesHaveChanged(t *testing.T) { }) t.Run("should be called when preferences are changed by plugin code", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1819,6 +1859,7 @@ func TestHookPreferencesHaveChanged(t *testing.T) { } func TestChannelHasBeenCreated(t *testing.T) { + mainHelper.Parallel(t) getPluginCode := func(th *TestHelper) string { return ` package main @@ -1856,6 +1897,7 @@ func TestChannelHasBeenCreated(t *testing.T) { pluginManifest := `{"id": "testplugin", "server": {"executable": "backend.exe"}}` t.Run("should call hook when a regular channel is created", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1886,6 +1928,7 @@ func TestChannelHasBeenCreated(t *testing.T) { }) t.Run("should call hook when a DM is created", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1911,6 +1954,7 @@ func TestChannelHasBeenCreated(t *testing.T) { }) t.Run("should call hook when a GM is created", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1938,6 +1982,7 @@ func TestChannelHasBeenCreated(t *testing.T) { } func TestUserHasJoinedChannel(t *testing.T) { + mainHelper.Parallel(t) getPluginCode := func(th *TestHelper) string { return ` package main @@ -1982,6 +2027,7 @@ func TestUserHasJoinedChannel(t *testing.T) { pluginManifest := `{"id": "testplugin", "server": {"executable": "backend.exe"}}` t.Run("should call hook when a user joins an existing channel", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2027,6 +2073,7 @@ func TestUserHasJoinedChannel(t *testing.T) { }) t.Run("should call hook when a user is added to an existing channel", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2072,6 +2119,7 @@ func TestUserHasJoinedChannel(t *testing.T) { }) t.Run("should not call hook when a regular channel is created", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2106,6 +2154,7 @@ func TestUserHasJoinedChannel(t *testing.T) { }) t.Run("should not call hook when a DM is created", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2136,6 +2185,7 @@ func TestUserHasJoinedChannel(t *testing.T) { }) t.Run("should not call hook when a GM is created", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/plugin_install_test.go b/server/channels/app/plugin_install_test.go index 85d15322fc..56e5fa392a 100644 --- a/server/channels/app/plugin_install_test.go +++ b/server/channels/app/plugin_install_test.go @@ -21,8 +21,7 @@ import ( "github.com/mattermost/mattermost/server/v8/channels/utils/fileutils" ) -type nilReadSeeker struct { -} +type nilReadSeeker struct{} func (r *nilReadSeeker) Read(p []byte) (int, error) { return 0, io.EOF @@ -69,6 +68,7 @@ func (b byBundleInfoID) Swap(i, j int) { b[i], b[j] = b[j], b[i] } func (b byBundleInfoID) Less(i, j int) bool { return b[i].Manifest.Id < b[j].Manifest.Id } func TestInstallPluginLocally(t *testing.T) { + mainHelper.Parallel(t) t.Run("invalid tar", func(t *testing.T) { th := Setup(t) defer th.TearDown() @@ -268,6 +268,7 @@ func TestInstallPluginLocally(t *testing.T) { } func TestInstallPluginAlreadyActive(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/plugin_shutdown_test.go b/server/channels/app/plugin_shutdown_test.go index 63cc9932e9..489eece70b 100644 --- a/server/channels/app/plugin_shutdown_test.go +++ b/server/channels/app/plugin_shutdown_test.go @@ -11,6 +11,7 @@ import ( ) func TestPluginShutdownTest(t *testing.T) { + mainHelper.Parallel(t) if testing.Short() { t.Skip("skipping test to verify forced shutdown of slow plugin") } diff --git a/server/channels/app/plugin_signature_test.go b/server/channels/app/plugin_signature_test.go index c09105dc13..a7b0ca0432 100644 --- a/server/channels/app/plugin_signature_test.go +++ b/server/channels/app/plugin_signature_test.go @@ -17,6 +17,7 @@ import ( ) func TestPluginPublicKeys(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -64,6 +65,7 @@ func TestPluginPublicKeys(t *testing.T) { } func TestVerifySignature(t *testing.T) { + mainHelper.Parallel(t) path, _ := fileutils.FindDir("tests") pluginFilename := "testplugin.tar.gz" signatureFilename := "testplugin.tar.gz.sig" diff --git a/server/channels/app/plugin_test.go b/server/channels/app/plugin_test.go index e3f9eb214f..3d6c87a123 100644 --- a/server/channels/app/plugin_test.go +++ b/server/channels/app/plugin_test.go @@ -38,6 +38,7 @@ func getHashedKey(key string) string { } func TestPluginKeyValueStore(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -138,6 +139,7 @@ func TestPluginKeyValueStore(t *testing.T) { } func TestPluginKeyValueStoreCompareAndSet(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -195,6 +197,7 @@ func TestPluginKeyValueStoreCompareAndSet(t *testing.T) { } func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) { + mainHelper.Parallel(t) pluginID := "testpluginid" t.Run("storing a value without providing options works", func(t *testing.T) { @@ -339,6 +342,7 @@ func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) { } func TestServePluginRequest(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -351,6 +355,7 @@ func TestServePluginRequest(t *testing.T) { } func TestPrivateServePluginRequest(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -396,6 +401,7 @@ func TestPrivateServePluginRequest(t *testing.T) { } func TestHandlePluginRequest(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -443,6 +449,7 @@ func TestHandlePluginRequest(t *testing.T) { } func TestGetPluginStatusesDisabled(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -456,6 +463,7 @@ func TestGetPluginStatusesDisabled(t *testing.T) { } func TestGetPluginStatuses(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -469,6 +477,7 @@ func TestGetPluginStatuses(t *testing.T) { } func TestPluginSync(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -632,6 +641,7 @@ func TestPluginSync(t *testing.T) { // See https://github.com/mattermost/mattermost-server/issues/19189 func TestChannelsPluginsInit(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -661,6 +671,7 @@ func TestChannelsPluginsInit(t *testing.T) { } func TestSyncPluginsActiveState(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -720,6 +731,7 @@ func TestSyncPluginsActiveState(t *testing.T) { } func TestPluginPanicLogs(t *testing.T) { + mainHelper.Parallel(t) t.Run("should panic", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -768,6 +780,7 @@ func TestPluginPanicLogs(t *testing.T) { } func TestPluginStatusActivateError(t *testing.T) { + mainHelper.Parallel(t) t.Run("should return error from OnActivate in plugin statuses", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -818,6 +831,7 @@ func (a pluginStatusById) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a pluginStatusById) Less(i, j int) bool { return a[i].PluginId < a[j].PluginId } func TestProcessPrepackagedPlugins(t *testing.T) { + mainHelper.Parallel(t) // Find the tests folder before we change directories to the temporary workspace. testsPath, _ := fileutils.FindDir("tests") @@ -827,18 +841,8 @@ func TestProcessPrepackagedPlugins(t *testing.T) { th := Setup(t) t.Cleanup(th.TearDown) - wd, err := os.Getwd() - require.NoError(t, err) - t.Cleanup(func() { - err = os.Chdir(wd) - require.NoError(t, err) - }) - - err = os.Chdir(th.tempWorkspace) - require.NoError(t, err) - // Make a prepackaged_plugins directory for use with the tests. - err = os.Mkdir(prepackagedPluginsDir, os.ModePerm) + err := os.Mkdir(filepath.Join(th.tempWorkspace, prepackagedPluginsDir), os.ModePerm) require.NoError(t, err) th.App.UpdateConfig(func(cfg *model.Config) { @@ -855,7 +859,7 @@ func TestProcessPrepackagedPlugins(t *testing.T) { appErr := th.App.ch.syncPlugins() require.Nil(t, appErr) - err := th.App.ch.processPrepackagedPlugins(prepackagedPluginsDir) + err := th.App.ch.processPrepackagedPlugins(filepath.Join(th.tempWorkspace, prepackagedPluginsDir)) require.NoError(t, err) env := th.App.GetPluginsEnvironment() @@ -865,22 +869,22 @@ func TestProcessPrepackagedPlugins(t *testing.T) { return plugins, transitionalPlugins } - copyAsPrepackagedPlugin := func(t *testing.T, filename string) { + copyAsPrepackagedPlugin := func(t *testing.T, th *TestHelper, filename string) { t.Helper() - err := testlib.CopyFile(filepath.Join(testsPath, filename), filepath.Join(prepackagedPluginsDir, filename)) + err := testlib.CopyFile(filepath.Join(testsPath, filename), filepath.Join(th.tempWorkspace, prepackagedPluginsDir, filename)) require.NoError(t, err) - err = testlib.CopyFile(filepath.Join(testsPath, fmt.Sprintf("%s.sig", filename)), filepath.Join(prepackagedPluginsDir, fmt.Sprintf("%s.sig", filename))) + err = testlib.CopyFile(filepath.Join(testsPath, fmt.Sprintf("%s.sig", filename)), filepath.Join(th.tempWorkspace, prepackagedPluginsDir, fmt.Sprintf("%s.sig", filename))) require.NoError(t, err) } - copyAsFilestorePlugin := func(t *testing.T, bundleFilename, pluginID string) { + copyAsFilestorePlugin := func(t *testing.T, th *TestHelper, bundleFilename, pluginID string) { t.Helper() - err := testlib.CopyFile(filepath.Join(testsPath, bundleFilename), filepath.Join(fmt.Sprintf("data/plugins/%s.tar.gz", pluginID))) + err := testlib.CopyFile(filepath.Join(testsPath, bundleFilename), filepath.Join(*th.App.Config().FileSettings.Directory, fmt.Sprintf("plugins/%s.tar.gz", pluginID))) require.NoError(t, err) - err = testlib.CopyFile(filepath.Join(testsPath, fmt.Sprintf("%s.sig", bundleFilename)), filepath.Join(fmt.Sprintf("data/plugins/%s.tar.gz.sig", pluginID))) + err = testlib.CopyFile(filepath.Join(testsPath, fmt.Sprintf("%s.sig", bundleFilename)), filepath.Join(*th.App.Config().FileSettings.Directory, fmt.Sprintf("plugins/%s.tar.gz.sig", pluginID))) require.NoError(t, err) } @@ -892,13 +896,13 @@ func TestProcessPrepackagedPlugins(t *testing.T) { require.Equal(t, version, actual.Manifest.Version) } - expectPluginInFilestore := func(t *testing.T, pluginID, version string) { + expectPluginInFilestore := func(t *testing.T, th *TestHelper, pluginID, version string) { t.Helper() - bundlePath := fmt.Sprintf("data/plugins/%s.tar.gz", pluginID) + bundlePath := filepath.Join(*th.App.Config().FileSettings.Directory, fmt.Sprintf("plugins/%s.tar.gz", pluginID)) require.FileExists(t, bundlePath) - require.FileExists(t, fmt.Sprintf("data/plugins/%s.tar.gz.sig", pluginID)) + require.FileExists(t, filepath.Join(*th.App.Config().FileSettings.Directory, fmt.Sprintf("plugins/%s.tar.gz.sig", pluginID))) // Verify the version recorded in the Manifest f, err := os.Open(bundlePath) @@ -930,11 +934,11 @@ func TestProcessPrepackagedPlugins(t *testing.T) { require.Equal(t, version, manifest.Version) } - expectPluginNotInFilestore := func(t *testing.T, pluginID string) { + expectPluginNotInFilestore := func(t *testing.T, th *TestHelper, pluginID string) { t.Helper() - require.NoFileExists(t, fmt.Sprintf("data/plugins/%s.tar.gz", pluginID)) - require.NoFileExists(t, fmt.Sprintf("data/plugins/%s.tar.gz.sig", pluginID)) + require.NoFileExists(t, filepath.Join(*th.App.Config().FileSettings.Directory, fmt.Sprintf("plugins/%s.tar.gz", pluginID))) + require.NoFileExists(t, filepath.Join(*th.App.Config().FileSettings.Directory, fmt.Sprintf("plugins/%s.tar.gz.sig", pluginID))) } expectPluginStatus := func(t *testing.T, pluginID, version string, actual *model.PluginStatus) { @@ -953,7 +957,7 @@ func TestProcessPrepackagedPlugins(t *testing.T) { cfg.PluginSettings.PluginStates["testplugin"] = &model.PluginState{Enable: true} }) - copyAsPrepackagedPlugin(t, "testplugin.tar.gz") + copyAsPrepackagedPlugin(t, th, "testplugin.tar.gz") plugins, transitionalPlugins := initPlugins(t, th) require.Len(t, plugins, 1, "expected one prepackaged plugin") @@ -965,7 +969,7 @@ func TestProcessPrepackagedPlugins(t *testing.T) { require.Len(t, pluginStatus, 1) expectPluginStatus(t, "testplugin", "0.0.1", pluginStatus[0]) - expectPluginNotInFilestore(t, "testplugin") + expectPluginNotInFilestore(t, th, "testplugin") }) t.Run("single plugin, not automatically installed since not enabled", func(t *testing.T) { @@ -976,7 +980,7 @@ func TestProcessPrepackagedPlugins(t *testing.T) { *cfg.PluginSettings.AutomaticPrepackagedPlugins = true }) - copyAsPrepackagedPlugin(t, "testplugin.tar.gz") + copyAsPrepackagedPlugin(t, th, "testplugin.tar.gz") plugins, transitionalPlugins := initPlugins(t, th) require.Len(t, plugins, 1, "expected one prepackaged plugin") @@ -987,7 +991,7 @@ func TestProcessPrepackagedPlugins(t *testing.T) { require.NoError(t, err) require.Empty(t, pluginStatus, 0) - expectPluginNotInFilestore(t, "testplugin") + expectPluginNotInFilestore(t, th, "testplugin") }) t.Run("single plugin, not automatically installed despite enabled since automatic prepackaged plugins disabled", func(t *testing.T) { @@ -999,7 +1003,7 @@ func TestProcessPrepackagedPlugins(t *testing.T) { cfg.PluginSettings.PluginStates["testplugin"] = &model.PluginState{Enable: true} }) - copyAsPrepackagedPlugin(t, "testplugin.tar.gz") + copyAsPrepackagedPlugin(t, th, "testplugin.tar.gz") plugins, transitionalPlugins := initPlugins(t, th) require.Len(t, plugins, 1, "expected one prepackaged plugin") @@ -1010,7 +1014,7 @@ func TestProcessPrepackagedPlugins(t *testing.T) { require.NoError(t, err) require.Empty(t, pluginStatus, 0) - expectPluginNotInFilestore(t, "testplugin") + expectPluginNotInFilestore(t, th, "testplugin") }) t.Run("multiple plugins, some automatically installed since enabled", func(t *testing.T) { @@ -1022,8 +1026,8 @@ func TestProcessPrepackagedPlugins(t *testing.T) { cfg.PluginSettings.PluginStates["testplugin2"] = &model.PluginState{Enable: true} }) - copyAsPrepackagedPlugin(t, "testplugin.tar.gz") - copyAsPrepackagedPlugin(t, "testplugin2.tar.gz") + copyAsPrepackagedPlugin(t, th, "testplugin.tar.gz") + copyAsPrepackagedPlugin(t, th, "testplugin2.tar.gz") plugins, transitionalPlugins := initPlugins(t, th) require.Len(t, plugins, 2, "expected two prepackaged plugins") @@ -1037,8 +1041,8 @@ func TestProcessPrepackagedPlugins(t *testing.T) { require.Len(t, pluginStatus, 1) expectPluginStatus(t, "testplugin2", "1.2.3", pluginStatus[0]) - expectPluginNotInFilestore(t, "testplugin") - expectPluginNotInFilestore(t, "testplugin2") + expectPluginNotInFilestore(t, th, "testplugin") + expectPluginNotInFilestore(t, th, "testplugin2") }) t.Run("multiple plugins, one previously installed, all now installed", func(t *testing.T) { @@ -1049,15 +1053,15 @@ func TestProcessPrepackagedPlugins(t *testing.T) { *cfg.PluginSettings.AutomaticPrepackagedPlugins = true }) - copyAsFilestorePlugin(t, "testplugin.tar.gz", "testplugin") + copyAsFilestorePlugin(t, th, "testplugin.tar.gz", "testplugin") th.App.UpdateConfig(func(cfg *model.Config) { cfg.PluginSettings.PluginStates["testplugin"] = &model.PluginState{Enable: true} cfg.PluginSettings.PluginStates["testplugin2"] = &model.PluginState{Enable: true} }) - copyAsPrepackagedPlugin(t, "testplugin.tar.gz") - copyAsPrepackagedPlugin(t, "testplugin2.tar.gz") + copyAsPrepackagedPlugin(t, th, "testplugin.tar.gz") + copyAsPrepackagedPlugin(t, th, "testplugin2.tar.gz") plugins, transitionalPlugins := initPlugins(t, th) require.Len(t, plugins, 2, "expected two prepackaged plugins") @@ -1075,8 +1079,8 @@ func TestProcessPrepackagedPlugins(t *testing.T) { expectPluginStatus(t, "testplugin", "0.0.1", pluginStatus[0]) expectPluginStatus(t, "testplugin2", "1.2.3", pluginStatus[1]) - expectPluginInFilestore(t, "testplugin", "0.0.1") - expectPluginNotInFilestore(t, "testplugin2") + expectPluginInFilestore(t, th, "testplugin", "0.0.1") + expectPluginNotInFilestore(t, th, "testplugin2") }) t.Run("multiple plugins, one previously installed and now upgraded, all now installed", func(t *testing.T) { @@ -1087,18 +1091,18 @@ func TestProcessPrepackagedPlugins(t *testing.T) { *cfg.PluginSettings.AutomaticPrepackagedPlugins = true }) - copyAsFilestorePlugin(t, "testplugin.tar.gz", "testplugin") + copyAsFilestorePlugin(t, th, "testplugin.tar.gz", "testplugin") th.App.UpdateConfig(func(cfg *model.Config) { cfg.PluginSettings.PluginStates["testplugin"] = &model.PluginState{Enable: true} cfg.PluginSettings.PluginStates["testplugin2"] = &model.PluginState{Enable: true} }) - copyAsPrepackagedPlugin(t, "testplugin-v0.0.2.tar.gz") - copyAsPrepackagedPlugin(t, "testplugin2.tar.gz") + copyAsPrepackagedPlugin(t, th, "testplugin-v0.0.2.tar.gz") + copyAsPrepackagedPlugin(t, th, "testplugin2.tar.gz") plugins, transitionalPlugins := initPlugins(t, th) - err := th.App.ch.processPrepackagedPlugins(prepackagedPluginsDir) + err := th.App.ch.processPrepackagedPlugins(filepath.Join(th.tempWorkspace, prepackagedPluginsDir)) require.NoError(t, err) require.Len(t, plugins, 2, "expected two prepackaged plugins") @@ -1116,8 +1120,8 @@ func TestProcessPrepackagedPlugins(t *testing.T) { expectPluginStatus(t, "testplugin", "0.0.2", pluginStatus[0]) expectPluginStatus(t, "testplugin2", "1.2.3", pluginStatus[1]) - expectPluginInFilestore(t, "testplugin", "0.0.1") - expectPluginNotInFilestore(t, "testplugin2") + expectPluginInFilestore(t, th, "testplugin", "0.0.1") + expectPluginNotInFilestore(t, th, "testplugin2") }) t.Run("multiple plugins, one previously installed but prepackaged is older, all now installed", func(t *testing.T) { @@ -1128,15 +1132,15 @@ func TestProcessPrepackagedPlugins(t *testing.T) { *cfg.PluginSettings.AutomaticPrepackagedPlugins = true }) - copyAsFilestorePlugin(t, "testplugin-v0.0.2.tar.gz", "testplugin") + copyAsFilestorePlugin(t, th, "testplugin-v0.0.2.tar.gz", "testplugin") th.App.UpdateConfig(func(cfg *model.Config) { cfg.PluginSettings.PluginStates["testplugin"] = &model.PluginState{Enable: true} cfg.PluginSettings.PluginStates["testplugin2"] = &model.PluginState{Enable: true} }) - copyAsPrepackagedPlugin(t, "testplugin.tar.gz") - copyAsPrepackagedPlugin(t, "testplugin2.tar.gz") + copyAsPrepackagedPlugin(t, th, "testplugin.tar.gz") + copyAsPrepackagedPlugin(t, th, "testplugin2.tar.gz") plugins, transitionalPlugins := initPlugins(t, th) require.Len(t, plugins, 2, "expected two prepackaged plugins") @@ -1154,8 +1158,8 @@ func TestProcessPrepackagedPlugins(t *testing.T) { expectPluginStatus(t, "testplugin", "0.0.2", pluginStatus[0]) expectPluginStatus(t, "testplugin2", "1.2.3", pluginStatus[1]) - expectPluginInFilestore(t, "testplugin", "0.0.2") - expectPluginNotInFilestore(t, "testplugin2") + expectPluginInFilestore(t, th, "testplugin", "0.0.2") + expectPluginNotInFilestore(t, th, "testplugin2") }) t.Run("multiple plugins, not automatically installed despite enabled since automatic prepackaged plugins disabled", func(t *testing.T) { @@ -1168,8 +1172,8 @@ func TestProcessPrepackagedPlugins(t *testing.T) { cfg.PluginSettings.PluginStates["testplugin2"] = &model.PluginState{Enable: true} }) - copyAsPrepackagedPlugin(t, "testplugin.tar.gz") - copyAsPrepackagedPlugin(t, "testplugin2.tar.gz") + copyAsPrepackagedPlugin(t, th, "testplugin.tar.gz") + copyAsPrepackagedPlugin(t, th, "testplugin2.tar.gz") plugins, transitionalPlugins := initPlugins(t, th) require.Len(t, plugins, 2, "expected two prepackaged plugins") @@ -1182,8 +1186,8 @@ func TestProcessPrepackagedPlugins(t *testing.T) { require.NoError(t, err) require.Len(t, pluginStatus, 0) - expectPluginNotInFilestore(t, "testplugin") - expectPluginNotInFilestore(t, "testplugin2") + expectPluginNotInFilestore(t, th, "testplugin") + expectPluginNotInFilestore(t, th, "testplugin2") }) t.Run("removing a prepackaged plugin leaves it disabled", func(t *testing.T) { @@ -1196,8 +1200,8 @@ func TestProcessPrepackagedPlugins(t *testing.T) { cfg.PluginSettings.PluginStates["testplugin2"] = &model.PluginState{Enable: true} }) - copyAsPrepackagedPlugin(t, "testplugin.tar.gz") - copyAsPrepackagedPlugin(t, "testplugin2.tar.gz") + copyAsPrepackagedPlugin(t, th, "testplugin.tar.gz") + copyAsPrepackagedPlugin(t, th, "testplugin2.tar.gz") plugins, transitionalPlugins := initPlugins(t, th) require.Len(t, plugins, 2, "expected two prepackaged plugins") @@ -1235,8 +1239,8 @@ func TestProcessPrepackagedPlugins(t *testing.T) { require.Len(t, pluginStatus, 1) expectPluginStatus(t, "testplugin2", "1.2.3", pluginStatus[0]) - expectPluginNotInFilestore(t, "testplugin") - expectPluginNotInFilestore(t, "testplugin2") + expectPluginNotInFilestore(t, th, "testplugin") + expectPluginNotInFilestore(t, th, "testplugin2") }) t.Run("single transitional plugin automatically installed and persisted since enabled", func(t *testing.T) { @@ -1254,7 +1258,7 @@ func TestProcessPrepackagedPlugins(t *testing.T) { cfg.PluginSettings.PluginStates["testplugin"] = &model.PluginState{Enable: true} }) - copyAsPrepackagedPlugin(t, "testplugin.tar.gz") + copyAsPrepackagedPlugin(t, th, "testplugin.tar.gz") plugins, transitionalPlugins := initPlugins(t, th) require.Empty(t, plugins) @@ -1266,8 +1270,8 @@ func TestProcessPrepackagedPlugins(t *testing.T) { require.Len(t, pluginStatus, 1) expectPluginStatus(t, "testplugin", "0.0.1", pluginStatus[0]) - expectPluginInFilestore(t, "testplugin", "0.0.1") - expectPluginNotInFilestore(t, "testplugin2") + expectPluginInFilestore(t, th, "testplugin", "0.0.1") + expectPluginNotInFilestore(t, th, "testplugin2") }) t.Run("single transitional plugin not persisted since already in filestore", func(t *testing.T) { @@ -1285,8 +1289,8 @@ func TestProcessPrepackagedPlugins(t *testing.T) { cfg.PluginSettings.PluginStates["testplugin"] = &model.PluginState{Enable: true} }) - copyAsFilestorePlugin(t, "testplugin.tar.gz", "testplugin") - copyAsPrepackagedPlugin(t, "testplugin.tar.gz") + copyAsFilestorePlugin(t, th, "testplugin.tar.gz", "testplugin") + copyAsPrepackagedPlugin(t, th, "testplugin.tar.gz") plugins, transitionalPlugins := initPlugins(t, th) require.Empty(t, plugins) @@ -1297,8 +1301,8 @@ func TestProcessPrepackagedPlugins(t *testing.T) { require.Len(t, pluginStatus, 1) expectPluginStatus(t, "testplugin", "0.0.1", pluginStatus[0]) - expectPluginInFilestore(t, "testplugin", "0.0.1") - expectPluginNotInFilestore(t, "testplugin2") + expectPluginInFilestore(t, th, "testplugin", "0.0.1") + expectPluginNotInFilestore(t, th, "testplugin2") }) t.Run("single transitional plugin persisted since newer than filestore", func(t *testing.T) { @@ -1316,8 +1320,8 @@ func TestProcessPrepackagedPlugins(t *testing.T) { cfg.PluginSettings.PluginStates["testplugin"] = &model.PluginState{Enable: true} }) - copyAsFilestorePlugin(t, "testplugin.tar.gz", "testplugin") - copyAsPrepackagedPlugin(t, "testplugin-v0.0.2.tar.gz") + copyAsFilestorePlugin(t, th, "testplugin.tar.gz", "testplugin") + copyAsPrepackagedPlugin(t, th, "testplugin-v0.0.2.tar.gz") plugins, transitionalPlugins := initPlugins(t, th) require.Empty(t, plugins) @@ -1329,8 +1333,8 @@ func TestProcessPrepackagedPlugins(t *testing.T) { require.Len(t, pluginStatus, 1) expectPluginStatus(t, "testplugin", "0.0.2", pluginStatus[0]) - expectPluginInFilestore(t, "testplugin", "0.0.2") - expectPluginNotInFilestore(t, "testplugin2") + expectPluginInFilestore(t, th, "testplugin", "0.0.2") + expectPluginNotInFilestore(t, th, "testplugin2") }) t.Run("transitional plugins persisted only once", func(t *testing.T) { @@ -1348,7 +1352,7 @@ func TestProcessPrepackagedPlugins(t *testing.T) { cfg.PluginSettings.PluginStates["testplugin"] = &model.PluginState{Enable: true} }) - copyAsPrepackagedPlugin(t, "testplugin.tar.gz") + copyAsPrepackagedPlugin(t, th, "testplugin.tar.gz") plugins, transitionalPlugins := initPlugins(t, th) require.Empty(t, plugins) @@ -1364,12 +1368,13 @@ func TestProcessPrepackagedPlugins(t *testing.T) { th.App.ch.persistTransitionallyPrepackagedPlugins() - expectPluginNotInFilestore(t, "testplugin") - expectPluginNotInFilestore(t, "testplugin2") + expectPluginNotInFilestore(t, th, "testplugin") + expectPluginNotInFilestore(t, th, "testplugin2") }) } func TestGetPluginStateOverride(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1387,10 +1392,10 @@ func TestGetPluginStateOverride(t *testing.T) { }) t.Run("with enabled flag set to true", func(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_APPSENABLED", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_APPSENABLED") - - th2 := Setup(t) + mainHelper.Parallel(t) + th2 := SetupConfig(t, func(cfg *model.Config) { + cfg.FeatureFlags.AppsEnabled = true + }) defer th2.TearDown() overrides, value := th2.App.ch.getPluginStateOverride("com.mattermost.apps") @@ -1399,10 +1404,10 @@ func TestGetPluginStateOverride(t *testing.T) { }) t.Run("with enabled flag set to false", func(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_APPSENABLED", "false") - defer os.Unsetenv("MM_FEATUREFLAGS_APPSENABLED") - - th2 := Setup(t) + mainHelper.Parallel(t) + th2 := SetupConfig(t, func(cfg *model.Config) { + cfg.FeatureFlags.AppsEnabled = false + }) defer th2.TearDown() overrides, value := th2.App.ch.getPluginStateOverride("com.mattermost.apps") diff --git a/server/channels/app/post.go b/server/channels/app/post.go index 9a925cdd6a..b817c18281 100644 --- a/server/channels/app/post.go +++ b/server/channels/app/post.go @@ -26,9 +26,10 @@ import ( "github.com/mattermost/mattermost/server/v8/platform/services/telemetry" ) +var pendingPostIDsCacheTTL = 30 * time.Second + const ( PendingPostIDsCacheSize = 25000 - PendingPostIDsCacheTTL = 30 * time.Second PageDefault = 0 ) @@ -146,7 +147,7 @@ func (a *App) deduplicateCreatePost(rctx request.CTX, post *model.Post) (foundPo var postID string nErr := a.Srv().seenPendingPostIdsCache.Get(post.PendingPostId, &postID) if nErr == cache.ErrKeyNotFound { - if appErr := a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, unknownPostId, PendingPostIDsCacheTTL); appErr != nil { + if appErr := a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, unknownPostId, pendingPostIDsCacheTTL); appErr != nil { return nil, model.NewAppError("deduplicateCreatePost", "api.post.deduplicate_create_post.cache_error", nil, "", http.StatusInternalServerError).Wrap(appErr) } return nil, nil @@ -205,7 +206,7 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel return } - if appErr := a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, savedPost.Id, PendingPostIDsCacheTTL); appErr != nil { + if appErr := a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, savedPost.Id, pendingPostIDsCacheTTL); appErr != nil { err = model.NewAppError("CreatePost", "api.post.deduplicate_create_post.cache_error", nil, "", http.StatusInternalServerError).Wrap(appErr) } }() @@ -371,7 +372,7 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel // Update the mapping from pending post id to the actual post id, for any clients that // might be duplicating requests. - if appErr := a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, rpost.Id, PendingPostIDsCacheTTL); appErr != nil { + if appErr := a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, rpost.Id, pendingPostIDsCacheTTL); appErr != nil { return nil, model.NewAppError("CreatePost", "api.post.deduplicate_create_post.cache_error", nil, "", http.StatusInternalServerError).Wrap(appErr) } @@ -1383,6 +1384,7 @@ func (a *App) AddCursorIdsForPostList(originalList *model.PostList, afterPost, b originalList.NextPostId = nextPostId originalList.PrevPostId = prevPostId } + func (a *App) GetPostsForChannelAroundLastUnread(c request.CTX, channelID, userID string, limitBefore, limitAfter int, skipFetchThreads bool, collapsedThreads, collapsedThreadsExtended bool) (*model.PostList, *model.AppError) { var lastViewedAt int64 var err *model.AppError @@ -2156,7 +2158,6 @@ func (a *App) GetPostsByIds(postIDs []string) ([]*model.Post, int64, *model.AppE func (a *App) GetEditHistoryForPost(postID string) ([]*model.Post, *model.AppError) { posts, err := a.Srv().Store().Post().GetEditHistoryForPost(postID) - if err != nil { var nfErr *store.ErrNotFound switch { diff --git a/server/channels/app/post_acknowledgements_test.go b/server/channels/app/post_acknowledgements_test.go index d91457983e..8918abdd2c 100644 --- a/server/channels/app/post_acknowledgements_test.go +++ b/server/channels/app/post_acknowledgements_test.go @@ -12,12 +12,14 @@ import ( ) func TestPostAcknowledgementsApp(t *testing.T) { + mainHelper.Parallel(t) t.Run("SaveAcknowledgementForPost", func(t *testing.T) { testSaveAcknowledgementForPost(t) }) t.Run("DeleteAcknowledgementForPost", func(t *testing.T) { testDeleteAcknowledgementForPost(t) }) t.Run("GetAcknowledgementsForPostList", func(t *testing.T) { testGetAcknowledgementsForPostList(t) }) } func testSaveAcknowledgementForPost(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -60,6 +62,7 @@ func testSaveAcknowledgementForPost(t *testing.T) { } func testDeleteAcknowledgementForPost(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() post, err1 := th.App.CreatePostAsUser(th.Context, &model.Post{ @@ -126,6 +129,7 @@ func testDeleteAcknowledgementForPost(t *testing.T) { } func testGetAcknowledgementsForPostList(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() p1, err := th.App.CreatePostAsUser(th.Context, &model.Post{ diff --git a/server/channels/app/post_file_change_test.go b/server/channels/app/post_file_change_test.go index 4c0fe36eb1..cb2720044a 100644 --- a/server/channels/app/post_file_change_test.go +++ b/server/channels/app/post_file_change_test.go @@ -11,6 +11,7 @@ import ( ) func TestProcessPostFileChanges(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/post_helpers_test.go b/server/channels/app/post_helpers_test.go index 516ac834a7..6adba5f2fa 100644 --- a/server/channels/app/post_helpers_test.go +++ b/server/channels/app/post_helpers_test.go @@ -13,7 +13,8 @@ import ( ) func TestGetTimeSortedPostAccessibleBounds(t *testing.T) { - var postFromCreateAt = func(at int64) *model.Post { + mainHelper.Parallel(t) + postFromCreateAt := func(at int64) *model.Post { return &model.Post{CreateAt: at} } @@ -193,6 +194,7 @@ func TestGetTimeSortedPostAccessibleBounds(t *testing.T) { } func TestFilterInaccessiblePosts(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) th.App.Srv().SetLicense(model.NewTestLicense("cloud")) err := th.App.Srv().Store().System().Save(&model.System{ @@ -203,7 +205,7 @@ func TestFilterInaccessiblePosts(t *testing.T) { defer th.TearDown() - var postFromCreateAt = func(at int64) *model.Post { + postFromCreateAt := func(at int64) *model.Post { return &model.Post{CreateAt: at} } @@ -322,6 +324,7 @@ func TestFilterInaccessiblePosts(t *testing.T) { } func TestGetFilteredAccessiblePosts(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) th.App.Srv().SetLicense(model.NewTestLicense("cloud")) err := th.App.Srv().Store().System().Save(&model.System{ @@ -332,7 +335,7 @@ func TestGetFilteredAccessiblePosts(t *testing.T) { defer th.TearDown() - var postFromCreateAt = func(at int64) *model.Post { + postFromCreateAt := func(at int64) *model.Post { return &model.Post{CreateAt: at} } @@ -364,6 +367,7 @@ func TestGetFilteredAccessiblePosts(t *testing.T) { } func TestIsInaccessiblePost(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) th.App.Srv().SetLicense(model.NewTestLicense("cloud")) err := th.App.Srv().Store().System().Save(&model.System{ @@ -386,6 +390,7 @@ func TestIsInaccessiblePost(t *testing.T) { } func Test_getInaccessibleRange(t *testing.T) { + mainHelper.Parallel(t) type test struct { label string bounds accessibleBounds diff --git a/server/channels/app/post_metadata_test.go b/server/channels/app/post_metadata_test.go index 3719a1f2c1..dfee7d272f 100644 --- a/server/channels/app/post_metadata_test.go +++ b/server/channels/app/post_metadata_test.go @@ -37,6 +37,7 @@ import ( ) func TestPreparePostListForClient(t *testing.T) { + mainHelper.Parallel(t) // Most of this logic is covered by TestPreparePostForClient, so this just tests handling of multiple posts th := Setup(t) @@ -68,6 +69,7 @@ func TestPreparePostListForClient(t *testing.T) { } func TestPreparePostForClient(t *testing.T) { + mainHelper.Parallel(t) var serverURL string server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { @@ -862,6 +864,7 @@ func TestPreparePostForClient(t *testing.T) { } func TestPreparePostForClientWithImageProxy(t *testing.T) { + mainHelper.Parallel(t) setup := func(t *testing.T) *TestHelper { th := Setup(t).InitBasic() @@ -981,6 +984,7 @@ func testProxyOpenGraphImage(t *testing.T, th *TestHelper, shouldProxy bool) { } func TestGetEmbedForPost(t *testing.T) { + mainHelper.Parallel(t) server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/index.html" { w.Header().Set("Content-Type", "text/html") @@ -1157,6 +1161,7 @@ func TestGetEmbedForPost(t *testing.T) { } func TestGetImagesForPost(t *testing.T) { + mainHelper.Parallel(t) t.Run("with an image link", func(t *testing.T) { th := Setup(t) defer th.TearDown() @@ -1445,6 +1450,7 @@ func TestGetImagesForPost(t *testing.T) { } func TestGetEmojiNamesForString(t *testing.T) { + mainHelper.Parallel(t) testCases := []struct { Description string Input string @@ -1496,6 +1502,7 @@ func TestGetEmojiNamesForString(t *testing.T) { } func TestGetEmojiNamesForPost(t *testing.T) { + mainHelper.Parallel(t) testCases := []struct { Description string Post *model.Post @@ -1591,6 +1598,7 @@ func TestGetEmojiNamesForPost(t *testing.T) { } func TestGetCustomEmojisForPost(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1670,6 +1678,7 @@ func TestGetCustomEmojisForPost(t *testing.T) { } func TestGetFirstLinkAndImages(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1838,6 +1847,7 @@ func TestGetFirstLinkAndImages(t *testing.T) { } func TestGetImagesInMessageAttachments(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2623,6 +2633,7 @@ func TestGetLinkMetadata(t *testing.T) { } func TestResolveMetadataURL(t *testing.T) { + mainHelper.Parallel(t) for _, test := range []struct { Name string RequestURL string @@ -2664,6 +2675,7 @@ func TestResolveMetadataURL(t *testing.T) { } func TestParseLinkMetadata(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -2760,6 +2772,7 @@ func TestParseLinkMetadata(t *testing.T) { } func TestParseImages(t *testing.T) { + mainHelper.Parallel(t) for name, testCase := range map[string]struct { FileName string Expected *model.PostImage @@ -2879,6 +2892,7 @@ func TestParseImages(t *testing.T) { } func TestLooksLikeAPermalink(t *testing.T) { + mainHelper.Parallel(t) const siteURLWithSubpath = "http://localhost:8065/foo" const siteURLWithTrailingSlash = "http://test.com/" const siteURL = "http://test.com" @@ -2910,6 +2924,7 @@ func TestLooksLikeAPermalink(t *testing.T) { } func TestContainsPermalink(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -2949,6 +2964,7 @@ func TestContainsPermalink(t *testing.T) { } func TestSanitizePostMetadataForUserAndChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3073,6 +3089,7 @@ func TestSanitizePostMetadataForUserAndChannel(t *testing.T) { } func TestSanitizePostMetaDataForAudit(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3125,6 +3142,7 @@ func TestSanitizePostMetaDataForAudit(t *testing.T) { } func TestSanitizePostMetadataForUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/post_persistent_notification_test.go b/server/channels/app/post_persistent_notification_test.go index cf8b1b4ac5..c83cab8512 100644 --- a/server/channels/app/post_persistent_notification_test.go +++ b/server/channels/app/post_persistent_notification_test.go @@ -14,6 +14,7 @@ import ( ) func TestResolvePersistentNotification(t *testing.T) { + mainHelper.Parallel(t) t.Run("should not delete when no posts exist", func(t *testing.T) { th := SetupWithStoreMock(t) defer th.TearDown() @@ -148,6 +149,7 @@ func TestResolvePersistentNotification(t *testing.T) { } func TestDeletePersistentNotification(t *testing.T) { + mainHelper.Parallel(t) t.Run("should not delete when no posts exist", func(t *testing.T) { th := SetupWithStoreMock(t) defer th.TearDown() @@ -195,6 +197,7 @@ func TestDeletePersistentNotification(t *testing.T) { } func TestSendPersistentNotifications(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/post_restore_test.go b/server/channels/app/post_restore_test.go index b4b111e17b..70627efc8b 100644 --- a/server/channels/app/post_restore_test.go +++ b/server/channels/app/post_restore_test.go @@ -12,6 +12,7 @@ import ( ) func TestRestorePostVersion(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/post_test.go b/server/channels/app/post_test.go index be06542753..1e7fc9818e 100644 --- a/server/channels/app/post_test.go +++ b/server/channels/app/post_test.go @@ -195,6 +195,12 @@ func TestCreatePostDeduplicate(t *testing.T) { }) t.Run("duplicate create post after cache expires is not idempotent", func(t *testing.T) { + originalCacheTTL := pendingPostIDsCacheTTL + pendingPostIDsCacheTTL = time.Second + t.Cleanup(func() { + pendingPostIDsCacheTTL = originalCacheTTL + }) + session := &model.Session{ UserId: th.BasicUser.Id, } @@ -212,7 +218,7 @@ func TestCreatePostDeduplicate(t *testing.T) { require.Nil(t, err) require.Equal(t, "message", post.Message) - time.Sleep(PendingPostIDsCacheTTL) + time.Sleep(pendingPostIDsCacheTTL) duplicatePost, err := th.App.CreatePostAsUser(th.Context.WithSession(session), &model.Post{ UserId: th.BasicUser.Id, @@ -276,6 +282,7 @@ func TestCreatePostDeduplicate(t *testing.T) { } func TestAttachFilesToPost(t *testing.T) { + mainHelper.Parallel(t) t.Run("should attach files", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -343,6 +350,7 @@ func TestAttachFilesToPost(t *testing.T) { } func TestUpdatePostEditAt(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -365,6 +373,7 @@ func TestUpdatePostEditAt(t *testing.T) { } func TestUpdatePostTimeLimit(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -399,6 +408,7 @@ func TestUpdatePostTimeLimit(t *testing.T) { } func TestUpdatePostInArchivedChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -413,6 +423,7 @@ func TestUpdatePostInArchivedChannel(t *testing.T) { } func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) { + mainHelper.Parallel(t) // This test ensures that when replying to a root post made by a user who has since left the channel, the reply // post completes successfully. This is a regression test for PLT-6523. th := Setup(t).InitBasic() @@ -442,6 +453,7 @@ func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) { } func TestPostAttachPostToChildPost(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -487,6 +499,7 @@ func TestPostAttachPostToChildPost(t *testing.T) { } func TestUpdatePostPluginHooks(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -628,6 +641,7 @@ func TestUpdatePostPluginHooks(t *testing.T) { } func TestPostChannelMentions(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -694,6 +708,7 @@ func TestPostChannelMentions(t *testing.T) { } func TestImageProxy(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -817,6 +832,7 @@ func TestImageProxy(t *testing.T) { } func TestDeletePostWithFileAttachments(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -861,6 +877,7 @@ func TestDeletePostWithFileAttachments(t *testing.T) { } func TestDeletePostInArchivedChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -875,7 +892,9 @@ func TestDeletePostInArchivedChannel(t *testing.T) { } func TestCreatePost(t *testing.T) { + mainHelper.Parallel(t) t.Run("call PreparePostForClient before returning", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -904,6 +923,7 @@ func TestCreatePost(t *testing.T) { }) t.Run("Sets prop MENTION_HIGHLIGHT_DISABLED when it should", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() th.AddUserToChannel(th.BasicUser, th.BasicChannel) @@ -956,6 +976,7 @@ func TestCreatePost(t *testing.T) { }) t.Run("Sets PostPropsPreviewedPost when a permalink is the first link", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() th.AddUserToChannel(th.BasicUser, th.BasicChannel) @@ -991,6 +1012,7 @@ func TestCreatePost(t *testing.T) { }) t.Run("creates a single record for a permalink preview post", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1030,6 +1052,7 @@ func TestCreatePost(t *testing.T) { }) t.Run("sanitizes post metadata appropriately", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1092,6 +1115,7 @@ func TestCreatePost(t *testing.T) { }) t.Run("Should not allow to create posts on shared DMs", func(t *testing.T) { + mainHelper.Parallel(t) th := setupSharedChannels(t).InitBasic() defer th.TearDown() @@ -1131,6 +1155,7 @@ func TestCreatePost(t *testing.T) { }) t.Run("Should not allow to create posts on shared GMs", func(t *testing.T) { + mainHelper.Parallel(t) th := setupSharedChannels(t).InitBasic() defer th.TearDown() @@ -1171,6 +1196,7 @@ func TestCreatePost(t *testing.T) { }) t.Run("MM-40016 should not panic with `concurrent map read and map write`", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1222,6 +1248,7 @@ func TestCreatePost(t *testing.T) { }) t.Run("should sanitize the force notifications prop if the flag is not set", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() th.AddUserToChannel(th.BasicUser, th.BasicChannel) @@ -1238,6 +1265,7 @@ func TestCreatePost(t *testing.T) { }) t.Run("should add the force notifications prop if the flag is set", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() th.AddUserToChannel(th.BasicUser, th.BasicChannel) @@ -1254,7 +1282,9 @@ func TestCreatePost(t *testing.T) { } func TestPatchPost(t *testing.T) { + mainHelper.Parallel(t) t.Run("call PreparePostForClient before returning", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1291,6 +1321,7 @@ func TestPatchPost(t *testing.T) { }) t.Run("Sets Prop MENTION_HIGHLIGHT_DISABLED when it should", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1341,7 +1372,9 @@ func TestPatchPost(t *testing.T) { } func TestCreatePostAsUser(t *testing.T) { + mainHelper.Parallel(t) t.Run("marks channel as viewed for regular user", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1365,6 +1398,7 @@ func TestCreatePostAsUser(t *testing.T) { }) t.Run("does not mark channel as viewed for webhook from user", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1389,6 +1423,7 @@ func TestCreatePostAsUser(t *testing.T) { }) t.Run("does not mark channel as viewed for bot user in channel", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1420,6 +1455,7 @@ func TestCreatePostAsUser(t *testing.T) { }) t.Run("does not log warning for bot user not in channel", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1445,6 +1481,7 @@ func TestCreatePostAsUser(t *testing.T) { }) t.Run("marks channel as viewed for reply post when CRT is off", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1480,6 +1517,7 @@ func TestCreatePostAsUser(t *testing.T) { }) t.Run("does not mark channel as viewed for reply post when CRT is on", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1517,6 +1555,7 @@ func TestCreatePostAsUser(t *testing.T) { } func TestPatchPostInArchivedChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1531,7 +1570,9 @@ func TestPatchPostInArchivedChannel(t *testing.T) { } func TestUpdateEphemeralPost(t *testing.T) { + mainHelper.Parallel(t) t.Run("Post contains preview if the user has permissions", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() th.AddUserToChannel(th.BasicUser, th.BasicChannel) @@ -1566,6 +1607,7 @@ func TestUpdateEphemeralPost(t *testing.T) { }) t.Run("Post does not contain preview if the user has no permissions", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() privateChannel := th.CreatePrivateChannel(th.Context, th.BasicTeam) @@ -1601,7 +1643,9 @@ func TestUpdateEphemeralPost(t *testing.T) { } func TestUpdatePost(t *testing.T) { + mainHelper.Parallel(t) t.Run("call PreparePostForClient before returning", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1637,6 +1681,7 @@ func TestUpdatePost(t *testing.T) { }) t.Run("Sets PostPropsPreviewedPost when a post is updated to have a permalink as the first link", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() th.AddUserToChannel(th.BasicUser, th.BasicChannel) @@ -1676,6 +1721,7 @@ func TestUpdatePost(t *testing.T) { }) t.Run("sanitizes post metadata appropriately", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1741,6 +1787,7 @@ func TestUpdatePost(t *testing.T) { } func TestSearchPostsForUser(t *testing.T) { + mainHelper.Parallel(t) perPage := 5 searchTerm := "searchTerm" @@ -1777,6 +1824,7 @@ func TestSearchPostsForUser(t *testing.T) { } t.Run("should return everything as first page of posts from database", func(t *testing.T) { + mainHelper.Parallel(t) th, posts := setup(t, false) defer th.TearDown() @@ -1797,6 +1845,7 @@ func TestSearchPostsForUser(t *testing.T) { }) t.Run("should not return later pages of posts from database", func(t *testing.T) { + mainHelper.Parallel(t) th, _ := setup(t, false) defer th.TearDown() @@ -1809,6 +1858,7 @@ func TestSearchPostsForUser(t *testing.T) { }) t.Run("should return first page of posts from ElasticSearch", func(t *testing.T) { + mainHelper.Parallel(t) th, posts := setup(t, true) defer th.TearDown() @@ -1839,6 +1889,7 @@ func TestSearchPostsForUser(t *testing.T) { }) t.Run("should return later pages of posts from ElasticSearch", func(t *testing.T) { + mainHelper.Parallel(t) th, posts := setup(t, true) defer th.TearDown() @@ -1866,6 +1917,7 @@ func TestSearchPostsForUser(t *testing.T) { }) t.Run("should fall back to database if ElasticSearch fails on first page", func(t *testing.T) { + mainHelper.Parallel(t) th, posts := setup(t, true) defer th.TearDown() @@ -1898,6 +1950,7 @@ func TestSearchPostsForUser(t *testing.T) { }) t.Run("should return nothing if ElasticSearch fails on later pages", func(t *testing.T) { + mainHelper.Parallel(t) th, _ := setup(t, true) defer th.TearDown() @@ -1922,6 +1975,7 @@ func TestSearchPostsForUser(t *testing.T) { }) t.Run("should return the same results if there is a tilde in the channel name", func(t *testing.T) { + mainHelper.Parallel(t) th, _ := setup(t, false) defer th.TearDown() @@ -1943,6 +1997,7 @@ func TestSearchPostsForUser(t *testing.T) { }) t.Run("should return the same results if there is an 'at' in the user", func(t *testing.T) { + mainHelper.Parallel(t) th, _ := setup(t, false) defer th.TearDown() @@ -1965,7 +2020,9 @@ func TestSearchPostsForUser(t *testing.T) { } func TestCountMentionsFromPost(t *testing.T) { + mainHelper.Parallel(t) t.Run("should not count posts without mentions", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2001,6 +2058,7 @@ func TestCountMentionsFromPost(t *testing.T) { }) t.Run("should count keyword mentions", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2040,6 +2098,7 @@ func TestCountMentionsFromPost(t *testing.T) { }) t.Run("should count channel-wide mentions when enabled", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2079,6 +2138,7 @@ func TestCountMentionsFromPost(t *testing.T) { }) t.Run("should not count channel-wide mentions when disabled for user", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2116,6 +2176,7 @@ func TestCountMentionsFromPost(t *testing.T) { }) t.Run("should not count channel-wide mentions when disabled for channel", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2158,6 +2219,7 @@ func TestCountMentionsFromPost(t *testing.T) { }) t.Run("should count comment mentions when using COMMENTS_NOTIFY_ROOT", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2212,6 +2274,7 @@ func TestCountMentionsFromPost(t *testing.T) { }) t.Run("should count comment mentions when using COMMENTS_NOTIFY_ANY", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2266,6 +2329,7 @@ func TestCountMentionsFromPost(t *testing.T) { }) t.Run("should count mentions caused by being added to the channel", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2315,6 +2379,7 @@ func TestCountMentionsFromPost(t *testing.T) { }) t.Run("should return the number of posts made by the other user for a direct channel", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2350,6 +2415,7 @@ func TestCountMentionsFromPost(t *testing.T) { }) t.Run("should return the number of posts made by the other user for a group message", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2393,6 +2459,7 @@ func TestCountMentionsFromPost(t *testing.T) { }) t.Run("should not count mentions from the before the given post", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2430,6 +2497,7 @@ func TestCountMentionsFromPost(t *testing.T) { }) t.Run("should not count mentions from the user's own posts", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2461,6 +2529,7 @@ func TestCountMentionsFromPost(t *testing.T) { }) t.Run("should include comments made before the given post when counting comment mentions", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2508,6 +2577,7 @@ func TestCountMentionsFromPost(t *testing.T) { }) t.Run("should not include comments made before the given post when rootPost is inaccessible", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2568,6 +2638,7 @@ func TestCountMentionsFromPost(t *testing.T) { }) t.Run("should count mentions from the user's webhook posts", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2608,6 +2679,7 @@ func TestCountMentionsFromPost(t *testing.T) { }) t.Run("should count multiple pages of mentions", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2644,6 +2716,7 @@ func TestCountMentionsFromPost(t *testing.T) { }) t.Run("should count urgent mentions", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2700,7 +2773,9 @@ func TestCountMentionsFromPost(t *testing.T) { } func TestFillInPostProps(t *testing.T) { + mainHelper.Parallel(t) t.Run("should not add disable group highlight to post props for user with group mention permissions", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() th.App.Srv().SetLicense(model.NewTestLicense("ldap")) @@ -2723,6 +2798,7 @@ func TestFillInPostProps(t *testing.T) { }) t.Run("should not add disable group highlight to post props for app without license", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2755,6 +2831,7 @@ func TestFillInPostProps(t *testing.T) { }) t.Run("should add disable group highlight to post props for guest user", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() th.App.Srv().SetLicense(model.NewTestLicense("ldap")) @@ -2789,7 +2866,9 @@ func TestFillInPostProps(t *testing.T) { } func TestThreadMembership(t *testing.T) { + mainHelper.Parallel(t) t.Run("should update memberships for conversation participants", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() th.App.UpdateConfig(func(cfg *model.Config) { @@ -2850,6 +2929,7 @@ func TestThreadMembership(t *testing.T) { } func TestFollowThreadSkipsParticipants(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2919,6 +2999,7 @@ func TestFollowThreadSkipsParticipants(t *testing.T) { } func TestAutofollowBasedOnRootPost(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2947,6 +3028,7 @@ func TestAutofollowBasedOnRootPost(t *testing.T) { } func TestViewChannelShouldNotUpdateThreads(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2981,6 +3063,7 @@ func TestViewChannelShouldNotUpdateThreads(t *testing.T) { } func TestCollapsedThreadFetch(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3197,6 +3280,7 @@ func TestReplyToPostWithLag(t *testing.T) { } func TestSharedChannelSyncForPostActions(t *testing.T) { + mainHelper.Parallel(t) t.Run("creating a post in a shared channel performs a content sync when sync service is running on that node", func(t *testing.T) { th := setupSharedChannels(t).InitBasic() defer th.TearDown() @@ -3281,6 +3365,7 @@ func TestSharedChannelSyncForPostActions(t *testing.T) { } func TestAutofollowOnPostingAfterUnfollow(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3322,6 +3407,7 @@ func TestAutofollowOnPostingAfterUnfollow(t *testing.T) { } func TestGetPostIfAuthorized(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3386,6 +3472,7 @@ func TestGetPostIfAuthorized(t *testing.T) { } func TestShouldNotRefollowOnOthersReply(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3435,6 +3522,7 @@ func TestShouldNotRefollowOnOthersReply(t *testing.T) { } func TestGetLastAccessiblePostTime(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -3468,6 +3556,7 @@ func TestGetLastAccessiblePostTime(t *testing.T) { } func TestComputeLastAccessiblePostTime(t *testing.T) { + mainHelper.Parallel(t) t.Run("Updates the time, if cloud limit is applicable", func(t *testing.T) { th := SetupWithStoreMock(t) defer th.TearDown() @@ -3525,6 +3614,7 @@ func TestComputeLastAccessiblePostTime(t *testing.T) { } func TestGetEditHistoryForPost(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3666,6 +3756,7 @@ func TestGetEditHistoryForPost(t *testing.T) { } func TestCopyWranglerPostlist(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3718,6 +3809,7 @@ func TestCopyWranglerPostlist(t *testing.T) { } func TestValidateMoveOrCopy(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3842,6 +3934,7 @@ func TestValidateMoveOrCopy(t *testing.T) { } func TestPermanentDeletePost(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -3933,6 +4026,7 @@ func TestPermanentDeletePost(t *testing.T) { } func TestSendTestMessage(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() t.Run("Should create the post with the correct prop", func(t *testing.T) { @@ -3943,6 +4037,7 @@ func TestSendTestMessage(t *testing.T) { } func TestPopulateEditHistoryFileMetadata(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/product_notices_test.go b/server/channels/app/product_notices_test.go index b83c116313..cb8eb7cdb9 100644 --- a/server/channels/app/product_notices_test.go +++ b/server/channels/app/product_notices_test.go @@ -19,6 +19,7 @@ import ( ) func TestNoticeValidation(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) mockStore := th.App.Srv().Store().(*mocks.Store) mockRoleStore := mocks.RoleStore{} @@ -599,6 +600,7 @@ func TestNoticeValidation(t *testing.T) { } func TestNoticeFetch(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/ratelimit_test.go b/server/channels/app/ratelimit_test.go index 2c57b25ae9..149930976e 100644 --- a/server/channels/app/ratelimit_test.go +++ b/server/channels/app/ratelimit_test.go @@ -27,6 +27,7 @@ func genRateLimitSettings(useAuth, useIP bool, header string) *model.RateLimitSe } func TestNewRateLimiterSuccess(t *testing.T) { + mainHelper.Parallel(t) settings := genRateLimitSettings(false, false, "") rateLimiter, err := NewRateLimiter(settings, nil) require.NotNil(t, rateLimiter) @@ -38,6 +39,7 @@ func TestNewRateLimiterSuccess(t *testing.T) { } func TestNewRateLimiterFailure(t *testing.T) { + mainHelper.Parallel(t) invalidSettings := genRateLimitSettings(false, false, "") invalidSettings.MaxBurst = model.NewPointer(-100) rateLimiter, err := NewRateLimiter(invalidSettings, nil) @@ -50,6 +52,7 @@ func TestNewRateLimiterFailure(t *testing.T) { } func TestGenerateKey(t *testing.T) { + mainHelper.Parallel(t) cases := []struct { useAuth bool useIP bool @@ -91,6 +94,7 @@ func TestGenerateKey(t *testing.T) { } func TestGenerateKey_TrustedHeader(t *testing.T) { + mainHelper.Parallel(t) req := httptest.NewRequest("GET", "/", nil) req.RemoteAddr = "10.10.10.5:80" req.Header.Set("X-Forwarded-For", "10.6.3.1, 10.5.1.2") diff --git a/server/channels/app/reaction_test.go b/server/channels/app/reaction_test.go index 9da4159010..b50bfeec30 100644 --- a/server/channels/app/reaction_test.go +++ b/server/channels/app/reaction_test.go @@ -14,6 +14,7 @@ import ( ) func TestSaveReactionForPost(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() post := th.CreatePost(th.BasicChannel) @@ -97,6 +98,7 @@ func TestSaveReactionForPost(t *testing.T) { } func TestSharedChannelSyncForReactionActions(t *testing.T) { + mainHelper.Parallel(t) t.Run("adding a reaction in a shared channel performs a content sync when sync service is running on that node", func(t *testing.T) { th := setupSharedChannels(t).InitBasic() diff --git a/server/channels/app/remote_cluster_test.go b/server/channels/app/remote_cluster_test.go index ac20a9f8ff..2e955c75fa 100644 --- a/server/channels/app/remote_cluster_test.go +++ b/server/channels/app/remote_cluster_test.go @@ -18,6 +18,7 @@ func setupRemoteCluster(tb testing.TB) *TestHelper { } func TestAddRemoteCluster(t *testing.T) { + mainHelper.Parallel(t) th := setupRemoteCluster(t).InitBasic() defer th.TearDown() @@ -41,6 +42,7 @@ func TestAddRemoteCluster(t *testing.T) { } func TestUpdateRemoteCluster(t *testing.T) { + mainHelper.Parallel(t) th := setupRemoteCluster(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/report_test.go b/server/channels/app/report_test.go index 0758b17842..f2f7aeb1a2 100644 --- a/server/channels/app/report_test.go +++ b/server/channels/app/report_test.go @@ -47,6 +47,7 @@ var testData []model.ReportableObject = []model.ReportableObject{ } func TestSaveReportChunk(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -69,6 +70,7 @@ func TestSaveReportChunk(t *testing.T) { } func TestCompileReportChunks(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -89,8 +91,7 @@ func TestCompileReportChunks(t *testing.T) { require.Nil(t, readErr) require.NotNil(t, bytes) - expected := - `Name,NumPosts,StartDate + expected := `Name,NumPosts,StartDate some-name,400,2024-01-01 some-other-name,500,2023-01-01 some-other-other-name,600,2022-01-01 @@ -110,6 +111,7 @@ some-other-other-name,600,2022-01-01 } func TestCheckForExistingJobs(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/role_test.go b/server/channels/app/role_test.go index 211eb6bb5f..460d43d882 100644 --- a/server/channels/app/role_test.go +++ b/server/channels/app/role_test.go @@ -28,6 +28,7 @@ type permissionInheritanceTestData struct { } func TestGetRolesByNames(t *testing.T) { + mainHelper.Parallel(t) testPermissionInheritance(t, func(t *testing.T, th *TestHelper, testData permissionInheritanceTestData) { actualRoles, err := th.App.GetRolesByNames([]string{testData.channelRole.Name}) require.Nil(t, err) @@ -42,6 +43,7 @@ func TestGetRolesByNames(t *testing.T) { } func TestGetRoleByName(t *testing.T) { + mainHelper.Parallel(t) testPermissionInheritance(t, func(t *testing.T, th *TestHelper, testData permissionInheritanceTestData) { actualRole, err := th.App.GetRoleByName(context.Background(), testData.channelRole.Name) require.Nil(t, err) @@ -52,6 +54,7 @@ func TestGetRoleByName(t *testing.T) { } func TestGetRoleByID(t *testing.T) { + mainHelper.Parallel(t) testPermissionInheritance(t, func(t *testing.T, th *TestHelper, testData permissionInheritanceTestData) { actualRole, err := th.App.GetRole(testData.channelRole.Id) require.Nil(t, err) @@ -62,6 +65,7 @@ func TestGetRoleByID(t *testing.T) { } func TestGetAllRoles(t *testing.T) { + mainHelper.Parallel(t) testPermissionInheritance(t, func(t *testing.T, th *TestHelper, testData permissionInheritanceTestData) { actualRoles, err := th.App.GetAllRoles() require.Nil(t, err) diff --git a/server/channels/app/scheduled_post_job_test.go b/server/channels/app/scheduled_post_job_test.go index 4a2a091169..9353a85936 100644 --- a/server/channels/app/scheduled_post_job_test.go +++ b/server/channels/app/scheduled_post_job_test.go @@ -14,6 +14,7 @@ import ( ) func TestProcessScheduledPosts(t *testing.T) { + mainHelper.Parallel(t) t.Run("base case - happy path", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -266,6 +267,7 @@ func TestProcessScheduledPosts(t *testing.T) { } func TestHandleFailedScheduledPosts(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -354,7 +356,7 @@ func TestHandleFailedScheduledPosts(t *testing.T) { // Helper function to check notifications for a specific user checkUserNotification := func(user *model.User) { // Wait time for notifications to be sent (adding 5 secs because it is run in a separate goroutine) - var timeout = 5 * time.Second + timeout := 5 * time.Second begin := time.Now() channel, appErr := th.App.GetOrCreateDirectChannel(rctx, user.Id, systemBot.UserId) assert.True(t, appErr == nil) diff --git a/server/channels/app/scheduled_post_test.go b/server/channels/app/scheduled_post_test.go index c1a1404f79..b5d17c5e64 100644 --- a/server/channels/app/scheduled_post_test.go +++ b/server/channels/app/scheduled_post_test.go @@ -14,6 +14,7 @@ import ( ) func TestSaveScheduledPost(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() user1ConnID := model.NewId() @@ -225,6 +226,7 @@ func TestSaveScheduledPost(t *testing.T) { } func TestGetUserTeamScheduledPosts(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() user1ConnID := model.NewId() @@ -459,6 +461,7 @@ func TestGetUserTeamScheduledPosts(t *testing.T) { } func TestUpdateScheduledPost(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() user1ConnID := model.NewId() @@ -672,6 +675,7 @@ func TestUpdateScheduledPost(t *testing.T) { } func TestDeleteScheduledPost(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() user1ConnID := model.NewId() @@ -756,6 +760,7 @@ func TestDeleteScheduledPost(t *testing.T) { } func TestPublishScheduledPostEvent(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/server_test.go b/server/channels/app/server_test.go index 5c6d19fb47..d9cd6ed350 100644 --- a/server/channels/app/server_test.go +++ b/server/channels/app/server_test.go @@ -54,6 +54,7 @@ func newServerWithConfig(t *testing.T, f func(cfg *model.Config)) (*Server, erro } func TestStartServerSuccess(t *testing.T) { + mainHelper.Parallel(t) s, err := newServerWithConfig(t, func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = "localhost:0" }) @@ -70,6 +71,7 @@ func TestStartServerSuccess(t *testing.T) { } func TestStartServerPortUnavailable(t *testing.T) { + mainHelper.Parallel(t) // Listen on the next available port listener, err := net.Listen("tcp", "localhost:0") require.NoError(t, err) @@ -88,6 +90,7 @@ func TestStartServerPortUnavailable(t *testing.T) { } func TestStartServerNoS3Bucket(t *testing.T) { + mainHelper.Parallel(t) s3Host := os.Getenv("CI_MINIO_HOST") if s3Host == "" { s3Host = "localhost" @@ -140,6 +143,7 @@ func TestStartServerNoS3Bucket(t *testing.T) { } func TestStartServerTLSSuccess(t *testing.T) { + mainHelper.Parallel(t) s, err := newServerWithConfig(t, func(cfg *model.Config) { testDir, _ := fileutils.FindDir("tests") @@ -165,6 +169,7 @@ func TestStartServerTLSSuccess(t *testing.T) { } func TestStartServerTLSVersion(t *testing.T) { + mainHelper.Parallel(t) configStore, _ := config.NewMemoryStore() store, _ := config.NewStoreFromBacking(configStore, nil, false) cfg := store.Get() @@ -205,7 +210,6 @@ func TestStartServerTLSVersion(t *testing.T) { } err = checkEndpoint(t, client, "https://localhost:"+strconv.Itoa(s.ListenAddr.Port)+"/") - if err != nil { t.Errorf("Expected nil, got %s", err) } @@ -215,6 +219,7 @@ func TestStartServerTLSVersion(t *testing.T) { } func TestStartServerTLSOverwriteCipher(t *testing.T) { + mainHelper.Parallel(t) s, err := newServerWithConfig(t, func(cfg *model.Config) { testDir, _ := fileutils.FindDir("tests") @@ -280,6 +285,7 @@ func checkEndpoint(t *testing.T, client *http.Client, url string) error { } func TestPanicLog(t *testing.T) { + mainHelper.Parallel(t) // Creating a temp dir for log tmpDir, err := os.MkdirTemp("", "mlog-test") require.NoError(t, err, "cannot create tmp dir for log file") @@ -347,8 +353,8 @@ func TestPanicLog(t *testing.T) { s.Shutdown() // Checking whether panic was logged - var panicLogged = false - var infoLogged = false + panicLogged := false + infoLogged := false logFile, err := os.Open(config.GetLogFileLocation(tmpDir)) require.NoError(t, err, "cannot open log file") @@ -494,6 +500,7 @@ func TestSentry(t *testing.T) { } func TestCancelTaskSetsTaskToNil(t *testing.T) { + mainHelper.Parallel(t) var taskMut sync.Mutex task := model.CreateRecurringTaskFromNextIntervalTime("a test task", func() {}, 5*time.Minute) require.NotNil(t, task) @@ -503,6 +510,7 @@ func TestCancelTaskSetsTaskToNil(t *testing.T) { } func TestOriginChecker(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/session_test.go b/server/channels/app/session_test.go index 310d21b12e..8b9cdbf29e 100644 --- a/server/channels/app/session_test.go +++ b/server/channels/app/session_test.go @@ -19,6 +19,7 @@ import ( ) func TestGetSessionIdleTimeoutInMinutes(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -98,6 +99,7 @@ func TestGetSessionIdleTimeoutInMinutes(t *testing.T) { } func TestUpdateSessionOnPromoteDemote(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -151,10 +153,13 @@ func TestUpdateSessionOnPromoteDemote(t *testing.T) { }) } -const hourMillis int64 = 60 * 60 * 1000 -const dayMillis int64 = 24 * hourMillis +const ( + hourMillis int64 = 60 * 60 * 1000 + dayMillis int64 = 24 * hourMillis +) func TestApp_GetSessionLengthInMillis(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -222,7 +227,8 @@ func TestApp_GetSessionLengthInMillis(t *testing.T) { UserId: model.NewId(), Props: map[string]string{ model.UserAuthServiceIsSaml: "true", - }} + }, + } session, err := th.App.CreateSession(th.Context, session) require.Nil(t, err) @@ -243,6 +249,7 @@ func TestApp_GetSessionLengthInMillis(t *testing.T) { } func TestApp_ExtendExpiryIfNeeded(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -284,7 +291,7 @@ func TestApp_ExtendExpiryIfNeeded(t *testing.T) { require.False(t, session.IsExpired()) }) - var tests = []struct { + tests := []struct { enabled bool name string session *model.Session @@ -365,6 +372,7 @@ func TestGetCloudSession(t *testing.T) { } func TestGetRemoteClusterSession(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) token := model.NewId() remoteID := model.NewId() @@ -400,6 +408,7 @@ func TestGetRemoteClusterSession(t *testing.T) { } func TestSessionsLimit(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -447,6 +456,7 @@ func TestSessionsLimit(t *testing.T) { } func TestSetExtraSessionProps(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/shared_channel_test.go b/server/channels/app/shared_channel_test.go index 3fcd489e51..903c5e742d 100644 --- a/server/channels/app/shared_channel_test.go +++ b/server/channels/app/shared_channel_test.go @@ -20,6 +20,7 @@ func setupSharedChannels(tb testing.TB) *TestHelper { } func TestApp_CheckCanInviteToSharedChannel(t *testing.T) { + mainHelper.Parallel(t) th := setupSharedChannels(t).InitBasic() channel1 := th.CreateChannel(th.Context, th.BasicTeam) diff --git a/server/channels/app/slack_test.go b/server/channels/app/slack_test.go index 31b35cd34b..990ce89422 100644 --- a/server/channels/app/slack_test.go +++ b/server/channels/app/slack_test.go @@ -10,6 +10,7 @@ import ( ) func TestProcessSlackText(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -33,6 +34,7 @@ func TestProcessSlackText(t *testing.T) { } func TestProcessSlackAnnouncement(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/status_test.go b/server/channels/app/status_test.go index 2aff8654c5..7b1e1976f8 100644 --- a/server/channels/app/status_test.go +++ b/server/channels/app/status_test.go @@ -17,6 +17,7 @@ import ( ) func TestCustomStatus(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -44,6 +45,7 @@ func TestCustomStatus(t *testing.T) { } func TestCustomStatusErrors(t *testing.T) { + mainHelper.Parallel(t) fakeUserID := "foobar" mockErr := store.NewErrNotFound("User", fakeUserID) mockUser := &model.User{Id: fakeUserID} @@ -111,6 +113,7 @@ func TestCustomStatusErrors(t *testing.T) { } func TestSetCustomStatus(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/support_packet_test.go b/server/channels/app/support_packet_test.go index f76c014245..8b027547de 100644 --- a/server/channels/app/support_packet_test.go +++ b/server/channels/app/support_packet_test.go @@ -22,6 +22,7 @@ import ( ) func TestGenerateSupportPacket(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -270,6 +271,7 @@ func TestGenerateSupportPacket(t *testing.T) { } func TestGetPluginsFile(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -334,6 +336,7 @@ func TestGetPluginsFile(t *testing.T) { } func TestGetSupportPacketStats(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) generateStats := func(t *testing.T) *model.SupportPacketStats { @@ -463,6 +466,7 @@ func TestGetSupportPacketStats(t *testing.T) { } func TestGetSupportPacketJobList(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -576,6 +580,7 @@ func TestGetSupportPacketJobList(t *testing.T) { } func TestGetSupportPacketPermissionsInfo(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -662,6 +667,7 @@ func TestGetSupportPacketPermissionsInfo(t *testing.T) { } func TestGetSupportPacketMetadata(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/syncables_test.go b/server/channels/app/syncables_test.go index 66f5e5232c..3fbf97ded5 100644 --- a/server/channels/app/syncables_test.go +++ b/server/channels/app/syncables_test.go @@ -17,6 +17,7 @@ import ( //nolint:govet // The setup code leads to a lot of variable shadowing. func TestCreateDefaultMemberships(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -530,6 +531,7 @@ func (us *mokeUserStore) Get(_ context.Context, id string) (*model.User, error) } func TestDeleteGroupMemberships(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -597,6 +599,7 @@ func TestDeleteGroupMemberships(t *testing.T) { } func TestSyncSyncableRoles(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/team_test.go b/server/channels/app/team_test.go index 0c9f58c405..61ddf79899 100644 --- a/server/channels/app/team_test.go +++ b/server/channels/app/team_test.go @@ -31,6 +31,7 @@ import ( ) func TestCreateTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -50,6 +51,7 @@ func TestCreateTeam(t *testing.T) { } func TestCreateTeamWithUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -69,6 +71,7 @@ func TestCreateTeamWithUser(t *testing.T) { } func TestUpdateTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -80,6 +83,7 @@ func TestUpdateTeam(t *testing.T) { } func TestAddUserToTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -223,6 +227,7 @@ func TestAddUserToTeam(t *testing.T) { } func TestAddUserToTeamByToken(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -482,6 +487,7 @@ func TestAddUserToTeamByToken(t *testing.T) { } func TestAddUserToTeamByTeamId(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -512,6 +518,7 @@ func TestAddUserToTeamByTeamId(t *testing.T) { } func TestAdjustTeamsFromProductLimits(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() teams := []*model.Team{ @@ -665,6 +672,7 @@ func TestAdjustTeamsFromProductLimits(t *testing.T) { } func TestPermanentDeleteTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -713,6 +721,7 @@ func TestPermanentDeleteTeam(t *testing.T) { } func TestSanitizeTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -839,6 +848,7 @@ func TestSanitizeTeam(t *testing.T) { } func TestSanitizeTeams(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -912,6 +922,7 @@ func TestSanitizeTeams(t *testing.T) { } func TestJoinUserToTeam(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1045,6 +1056,7 @@ func TestJoinUserToTeam(t *testing.T) { } func TestLeaveTeamPanic(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -1058,7 +1070,8 @@ func TestLeaveTeamPanic(t *testing.T) { mockChannelStore.On("GetMember", context.Background(), "channelID", "userID").Return(&model.ChannelMember{ NotifyProps: model.StringMap{ model.PushNotifyProp: model.ChannelNotifyDefault, - }}, nil) + }, + }, nil) mockChannelStore.On("GetChannels", "myteam", "userID", mock.Anything).Return(model.ChannelList{}, nil) var err error @@ -1127,6 +1140,7 @@ func TestLeaveTeamPanic(t *testing.T) { } func TestAppUpdateTeamScheme(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1182,6 +1196,7 @@ func TestAppUpdateTeamScheme(t *testing.T) { } func TestGetTeamMembers(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1293,6 +1308,7 @@ func TestGetTeamMembers(t *testing.T) { } func TestGetTeamStats(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1357,6 +1373,7 @@ func TestGetTeamStats(t *testing.T) { } func TestUpdateTeamMemberRolesChangingGuest(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1420,6 +1437,7 @@ func TestUpdateTeamMemberRolesChangingGuest(t *testing.T) { } func TestInvalidateAllResendInviteEmailJobs(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1443,6 +1461,7 @@ func TestInvalidateAllResendInviteEmailJobs(t *testing.T) { } func TestInvalidateAllEmailInvites(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -1487,6 +1506,7 @@ func TestInvalidateAllEmailInvites(t *testing.T) { } func TestClearTeamMembersCache(t *testing.T) { + mainHelper.Parallel(t) th := SetupWithStoreMock(t) defer th.TearDown() @@ -1509,6 +1529,7 @@ func TestClearTeamMembersCache(t *testing.T) { } func TestInviteNewUsersToTeamGracefully(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1622,6 +1643,7 @@ func TestInviteNewUsersToTeamGracefully(t *testing.T) { } func TestInviteGuestsToChannelsGracefully(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1686,6 +1708,7 @@ func TestInviteGuestsToChannelsGracefully(t *testing.T) { } func TestTeamSendEvents(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/upload_test.go b/server/channels/app/upload_test.go index ed82bc201a..e550eab799 100644 --- a/server/channels/app/upload_test.go +++ b/server/channels/app/upload_test.go @@ -21,6 +21,7 @@ import ( ) func TestCreateUploadSession(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -85,6 +86,7 @@ func TestCreateUploadSession(t *testing.T) { } func TestUploadData(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -244,6 +246,7 @@ func TestUploadData(t *testing.T) { } func TestUploadDataConcurrent(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/usage_test.go b/server/channels/app/usage_test.go index 7bfb02e095..074b5e3720 100644 --- a/server/channels/app/usage_test.go +++ b/server/channels/app/usage_test.go @@ -14,6 +14,7 @@ import ( ) func TestGetPostsUsage(t *testing.T) { + mainHelper.Parallel(t) t.Run("returns error when AnalyticsPostCount fails", func(t *testing.T) { th := SetupWithStoreMock(t) defer th.TearDown() diff --git a/server/channels/app/user_agent_test.go b/server/channels/app/user_agent_test.go index 0f975ae163..bae27273a1 100644 --- a/server/channels/app/user_agent_test.go +++ b/server/channels/app/user_agent_test.go @@ -47,6 +47,7 @@ var testUserAgents = []testUserAgent{ } func TestGetPlatformName(t *testing.T) { + mainHelper.Parallel(t) expected := []string{ "Windows", "Macintosh", @@ -88,6 +89,7 @@ func TestGetPlatformName(t *testing.T) { } func TestGetOSName(t *testing.T) { + mainHelper.Parallel(t) expected := []string{ "Windows 7", "Mac OS", @@ -129,6 +131,7 @@ func TestGetOSName(t *testing.T) { } func TestGetBrowserName(t *testing.T) { + mainHelper.Parallel(t) expected := []string{ "Firefox", "Chrome", @@ -170,6 +173,7 @@ func TestGetBrowserName(t *testing.T) { } func TestGetBrowserVersion(t *testing.T) { + mainHelper.Parallel(t) expected := []string{ "40.1", "60.0.3112", // Doesn't report the fourth part of the version diff --git a/server/channels/app/user_terms_of_service_test.go b/server/channels/app/user_terms_of_service_test.go index 928b62d5ea..e3ed903824 100644 --- a/server/channels/app/user_terms_of_service_test.go +++ b/server/channels/app/user_terms_of_service_test.go @@ -10,6 +10,7 @@ import ( ) func TestUserTermsOfService(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/user_test.go b/server/channels/app/user_test.go index 15a93de5bd..9238e1bf73 100644 --- a/server/channels/app/user_test.go +++ b/server/channels/app/user_test.go @@ -30,6 +30,7 @@ import ( ) func TestCreateOAuthUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -87,6 +88,7 @@ func TestCreateOAuthUser(t *testing.T) { } func TestUpdateDefaultProfileImage(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() startTime := model.GetMillis() @@ -109,6 +111,7 @@ func TestUpdateDefaultProfileImage(t *testing.T) { } func TestAdjustProfileImage(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -134,6 +137,7 @@ func TestAdjustProfileImage(t *testing.T) { } func TestUpdateUserToRestrictedDomain(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -194,6 +198,7 @@ func TestUpdateUserToRestrictedDomain(t *testing.T) { } func TestUpdateUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -237,6 +242,7 @@ func TestUpdateUser(t *testing.T) { } func TestUpdateUserMissingFields(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -270,6 +276,7 @@ func TestUpdateUserMissingFields(t *testing.T) { } func TestCreateUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -340,6 +347,7 @@ func TestCreateUser(t *testing.T) { } func TestUpdateUserActive(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -358,6 +366,7 @@ func TestUpdateUserActive(t *testing.T) { } func TestUpdateActiveBotsSideEffect(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -410,6 +419,7 @@ func TestUpdateActiveBotsSideEffect(t *testing.T) { } func TestUpdateOAuthUserAttrs(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -519,6 +529,7 @@ func TestUpdateOAuthUserAttrs(t *testing.T) { } func TestCreateUserConflict(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -559,6 +570,7 @@ func TestCreateUserConflict(t *testing.T) { } func TestUpdateUserEmail(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -739,6 +751,7 @@ func createGitlabUser(t *testing.T, a *App, c request.CTX, id int64, username st } func TestGetUsersByStatus(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() @@ -869,6 +882,7 @@ func TestGetUsersByStatus(t *testing.T) { } func TestCreateUserWithInviteId(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -897,6 +911,7 @@ func TestCreateUserWithInviteId(t *testing.T) { } func TestCreateUserWithToken(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1091,6 +1106,7 @@ func TestCreateUserWithToken(t *testing.T) { } func TestPermanentDeleteUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic().DeleteBots() defer th.TearDown() @@ -1116,8 +1132,7 @@ func TestPermanentDeleteUser(t *testing.T) { bots1 := []*model.Bot{} bots2 := []*model.Bot{} - sqlStore := mainHelper.GetSQLStore() - err1 := sqlStore.GetMaster().Select(&bots1, "SELECT * FROM Bots") + err1 := th.SQLStore.GetMaster().Select(&bots1, "SELECT * FROM Bots") assert.NoError(t, err1) assert.Equal(t, 1, len(bots1)) @@ -1128,7 +1143,7 @@ func TestPermanentDeleteUser(t *testing.T) { err = th.App.PermanentDeleteUser(th.Context, retUser1) assert.Nil(t, err) - err1 = sqlStore.GetMaster().Select(&bots2, "SELECT * FROM Bots") + err1 = th.SQLStore.GetMaster().Select(&bots2, "SELECT * FROM Bots") assert.NoError(t, err1) assert.Equal(t, 0, len(bots2)) @@ -1187,6 +1202,7 @@ func TestPermanentDeleteUser(t *testing.T) { } func TestPasswordRecovery(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1242,6 +1258,7 @@ func TestPasswordRecovery(t *testing.T) { } func TestInvalidatePasswordRecoveryTokens(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1280,6 +1297,7 @@ func TestInvalidatePasswordRecoveryTokens(t *testing.T) { } func TestPasswordChangeSessionTermination(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1427,6 +1445,7 @@ func TestPasswordChangeSessionTermination(t *testing.T) { } func TestGetViewUsersRestrictions(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1562,6 +1581,7 @@ func TestGetViewUsersRestrictions(t *testing.T) { } func TestPromoteGuestToUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1698,6 +1718,7 @@ func TestPromoteGuestToUser(t *testing.T) { } func TestDemoteUserToGuest(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1883,6 +1904,7 @@ func TestDemoteUserToGuest(t *testing.T) { } func TestDeactivateGuests(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -1907,6 +1929,7 @@ func TestDeactivateGuests(t *testing.T) { } func TestUpdateUserRolesWithUser(t *testing.T) { + mainHelper.Parallel(t) // InitBasic is used to let the first CreateUser call not be // a system_admin th := Setup(t).InitBasic() @@ -1932,6 +1955,7 @@ func TestUpdateUserRolesWithUser(t *testing.T) { } func TestUpdateLastAdminUserRolesWithUser(t *testing.T) { + mainHelper.Parallel(t) // InitBasic is used to let the first CreateUser call not be // a system_admin th := Setup(t).InitBasic() @@ -1970,6 +1994,7 @@ func TestUpdateLastAdminUserRolesWithUser(t *testing.T) { } func TestDeactivateMfa(t *testing.T) { + mainHelper.Parallel(t) t.Run("MFA is disabled", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -1985,6 +2010,7 @@ func TestDeactivateMfa(t *testing.T) { } func TestPatchUser(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2023,6 +2049,7 @@ func TestPatchUser(t *testing.T) { } func TestUpdateThreadReadForUser(t *testing.T) { + mainHelper.Parallel(t) t.Run("Ensure thread membership exists before updating read", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -2051,6 +2078,7 @@ func TestUpdateThreadReadForUser(t *testing.T) { } func TestCreateUserWithInitialPreferences(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -2107,6 +2135,7 @@ func TestCreateUserWithInitialPreferences(t *testing.T) { } func TestSendSubscriptionHistoryEvent(t *testing.T) { + mainHelper.Parallel(t) cloudProduct := &model.Product{ ID: "prod_test1", Name: "name1", @@ -2188,6 +2217,7 @@ func TestSendSubscriptionHistoryEvent(t *testing.T) { } func TestGetUsersForReporting(t *testing.T) { + mainHelper.Parallel(t) t.Run("should throw error on invalid date range", func(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() @@ -2264,6 +2294,7 @@ func TestGetUsersForReporting(t *testing.T) { } func TestCreateUserOrGuest(t *testing.T) { + mainHelper.Parallel(t) t.Run("base case - you can create a user", func(t *testing.T) { th := Setup(t) defer th.TearDown() diff --git a/server/channels/app/user_viewmembers_test.go b/server/channels/app/user_viewmembers_test.go index 4bdf4b21d0..8203076fae 100644 --- a/server/channels/app/user_viewmembers_test.go +++ b/server/channels/app/user_viewmembers_test.go @@ -14,6 +14,7 @@ import ( ) func TestRestrictedViewMembers(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).DeleteBots() defer th.TearDown() diff --git a/server/channels/app/web_broadcast_hooks_test.go b/server/channels/app/web_broadcast_hooks_test.go index cd6469bda7..1d1e990f05 100644 --- a/server/channels/app/web_broadcast_hooks_test.go +++ b/server/channels/app/web_broadcast_hooks_test.go @@ -13,6 +13,7 @@ import ( ) func TestAddMentionsHook_Process(t *testing.T) { + mainHelper.Parallel(t) hook := &addMentionsBroadcastHook{} userID := model.NewId() @@ -51,6 +52,7 @@ func TestAddMentionsHook_Process(t *testing.T) { } func TestAddFollowersHook_Process(t *testing.T) { + mainHelper.Parallel(t) hook := &addFollowersBroadcastHook{} userID := model.NewId() @@ -88,6 +90,7 @@ func TestAddFollowersHook_Process(t *testing.T) { } func TestPostedAckHook_Process(t *testing.T) { + mainHelper.Parallel(t) hook := &postedAckBroadcastHook{} userID := model.NewId() webConn := &platform.WebConn{ @@ -190,6 +193,7 @@ func TestPostedAckHook_Process(t *testing.T) { } func TestAddMentionsAndAddFollowersHooks(t *testing.T) { + mainHelper.Parallel(t) addMentionsHook := &addMentionsBroadcastHook{} addFollowersHook := &addFollowersBroadcastHook{} @@ -223,6 +227,7 @@ func TestAddMentionsAndAddFollowersHooks(t *testing.T) { } func TestPermalinkBroadcastHook(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() diff --git a/server/channels/app/web_conn_test.go b/server/channels/app/web_conn_test.go index 1b0c02de55..012491b699 100644 --- a/server/channels/app/web_conn_test.go +++ b/server/channels/app/web_conn_test.go @@ -4,7 +4,6 @@ package app import ( - "os" "testing" "github.com/stretchr/testify/assert" @@ -19,8 +18,8 @@ import ( // happen inside web_hub.go before the event is actually broadcasted, and checked // via ShouldSendEvent. func TestWebConnShouldSendEvent(t *testing.T) { - os.Setenv("MM_FEATUREFLAGS_WEBSOCKETEVENTSCOPE", "true") - defer os.Unsetenv("MM_FEATUREFLAGS_WEBSOCKETEVENTSCOPE") + mainHelper.Parallel(t) + th := Setup(t).InitBasic() defer th.TearDown() session, err := th.App.CreateSession(th.Context, &model.Session{UserId: th.BasicUser.Id, Roles: th.BasicUser.GetRawRoles(), TeamMembers: []*model.TeamMember{ diff --git a/server/channels/app/webhook_test.go b/server/channels/app/webhook_test.go index d276d94320..5f3f1b2e1b 100644 --- a/server/channels/app/webhook_test.go +++ b/server/channels/app/webhook_test.go @@ -23,6 +23,7 @@ import ( ) func TestCreateIncomingWebhookForChannel(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -155,6 +156,7 @@ func TestCreateIncomingWebhookForChannel(t *testing.T) { } func TestUpdateIncomingWebhook(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -293,6 +295,7 @@ func TestUpdateIncomingWebhook(t *testing.T) { } func TestCreateWebhookPost(t *testing.T) { + mainHelper.Parallel(t) testCluster := &testlib.FakeClusterInterface{} th := SetupWithClusterMock(t, testCluster).InitBasic() defer th.TearDown() @@ -502,6 +505,7 @@ func TestCreateWebhookPostWithOverriddenIcon(t *testing.T) { } func TestCreateWebhookPostWithPriority(t *testing.T) { + mainHelper.Parallel(t) testCluster := &testlib.FakeClusterInterface{} th := SetupWithClusterMock(t, testCluster).InitBasic() defer th.TearDown() @@ -552,6 +556,7 @@ func TestCreateWebhookPostWithPriority(t *testing.T) { } func TestCreateWebhookPostLinks(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -586,6 +591,7 @@ func TestCreateWebhookPostLinks(t *testing.T) { } func TestSplitWebhookPost(t *testing.T) { + mainHelper.Parallel(t) type TestCase struct { Post *model.Post Expected []*model.Post @@ -699,6 +705,7 @@ func makePost(message int, attachments []int) *model.Post { } func TestSplitWebhookPostAttachments(t *testing.T) { + mainHelper.Parallel(t) maxPostSize := 10000 testCases := []struct { name string @@ -759,6 +766,7 @@ func TestSplitWebhookPostAttachments(t *testing.T) { } func TestCreateOutGoingWebhookWithUsernameAndIconURL(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic() defer th.TearDown() @@ -790,6 +798,7 @@ func TestCreateOutGoingWebhookWithUsernameAndIconURL(t *testing.T) { } func TestTriggerOutGoingWebhookWithUsernameAndIconURL(t *testing.T) { + mainHelper.Parallel(t) getPayload := func(hook *model.OutgoingWebhook, th *TestHelper, channel *model.Channel) *model.OutgoingWebhookPayload { return &model.OutgoingWebhookPayload{ Token: hook.Token, @@ -931,6 +940,7 @@ func TestTriggerOutGoingWebhookWithUsernameAndIconURL(t *testing.T) { } func TestTriggerOutGoingWebhookWithMultipleURLs(t *testing.T) { + mainHelper.Parallel(t) getPayload := func(hook *model.OutgoingWebhook, th *TestHelper, channel *model.Channel) *model.OutgoingWebhookPayload { return &model.OutgoingWebhookPayload{ Token: hook.Token, @@ -1038,6 +1048,7 @@ func (r InfiniteReader) Read(p []byte) (n int, err error) { } func TestDoOutgoingWebhookRequest(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t) defer th.TearDown() diff --git a/server/channels/jobs/base_workers_test.go b/server/channels/jobs/base_workers_test.go index c5d4e49a48..47d19a1877 100644 --- a/server/channels/jobs/base_workers_test.go +++ b/server/channels/jobs/base_workers_test.go @@ -5,6 +5,7 @@ package jobs import ( "errors" + "os" "testing" "github.com/mattermost/mattermost/server/public/model" @@ -14,6 +15,10 @@ import ( ) func TestSimpleWorkerPanic(t *testing.T) { + if os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" { + t.Parallel() + } + jobServer, mockStore, mockMetrics := makeJobServer(t) job := &model.Job{ diff --git a/server/channels/jobs/batch_migration_worker_test.go b/server/channels/jobs/batch_migration_worker_test.go index 2ee34ed112..b5a5e32a31 100644 --- a/server/channels/jobs/batch_migration_worker_test.go +++ b/server/channels/jobs/batch_migration_worker_test.go @@ -45,6 +45,8 @@ func (ma *MockApp) SetOutOfSync() { } func TestBatchMigrationWorker(t *testing.T) { + mainHelper.Parallel(t) + setupBatchWorker := func(t *testing.T, th *TestHelper, mockApp *MockApp, doMigrationBatch func(model.StringMap, store.Store) (model.StringMap, bool, error)) (model.Worker, *model.Job) { t.Helper() diff --git a/server/channels/jobs/batch_report_worker_test.go b/server/channels/jobs/batch_report_worker_test.go index 528809e210..a6d3163a23 100644 --- a/server/channels/jobs/batch_report_worker_test.go +++ b/server/channels/jobs/batch_report_worker_test.go @@ -20,17 +20,22 @@ type ReportMockApp struct{} func (rma *ReportMockApp) SaveReportChunk(format string, prefix string, count int, reportData []model.ReportableObject) *model.AppError { return nil } + func (rma *ReportMockApp) CompileReportChunks(format string, prefix string, numberOfChunks int, headers []string) *model.AppError { return nil } + func (rma *ReportMockApp) SendReportToUser(rctx request.CTX, job *model.Job, format string) *model.AppError { return nil } + func (rma *ReportMockApp) CleanupReportChunks(format string, prefix string, numberOfChunks int) *model.AppError { return nil } func TestBatchReportWorker(t *testing.T) { + mainHelper.Parallel(t) + setupBatchWorker := func( t *testing.T, th *TestHelper, @@ -83,6 +88,8 @@ func TestBatchReportWorker(t *testing.T) { } t.Run("should finish when the report is done, incrementing file count along the way", func(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic(t) var worker model.Worker @@ -113,6 +120,7 @@ func TestBatchReportWorker(t *testing.T) { }) t.Run("should fail job when get data throws an error", func(t *testing.T) { + mainHelper.Parallel(t) th := Setup(t).InitBasic(t) var worker model.Worker diff --git a/server/channels/jobs/batch_worker_test.go b/server/channels/jobs/batch_worker_test.go index 92131904da..fbee687c8c 100644 --- a/server/channels/jobs/batch_worker_test.go +++ b/server/channels/jobs/batch_worker_test.go @@ -17,6 +17,8 @@ import ( // TestBatchWorkerRace tests race conditions during the start/stop // cases of the batch worker. Use the -race flag while testing this. func TestBatchWorkerRace(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t) worker := jobs.MakeBatchWorker(th.Server.Jobs, th.Server.Store(), 1*time.Second, func(rctx *request.Context, job *model.Job) bool { @@ -28,6 +30,8 @@ func TestBatchWorkerRace(t *testing.T) { } func TestBatchWorker(t *testing.T) { + mainHelper.Parallel(t) + createBatchWorker := func(t *testing.T, th *TestHelper, doBatch func(rctx *request.Context, job *model.Job) bool) (*jobs.BatchWorker, *model.Job) { t.Helper() @@ -58,6 +62,8 @@ func TestBatchWorker(t *testing.T) { } t.Run("stop after first batch", func(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic(t) var worker *jobs.BatchWorker @@ -84,6 +90,8 @@ func TestBatchWorker(t *testing.T) { }) t.Run("stop after second batch", func(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic(t) var worker *jobs.BatchWorker @@ -110,6 +118,8 @@ func TestBatchWorker(t *testing.T) { }) t.Run("done after first batch", func(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic(t) var worker *jobs.BatchWorker @@ -133,6 +143,8 @@ func TestBatchWorker(t *testing.T) { }) t.Run("done after three batches", func(t *testing.T) { + mainHelper.Parallel(t) + th := Setup(t).InitBasic(t) var worker *jobs.BatchWorker diff --git a/server/channels/jobs/export_delete_test.go b/server/channels/jobs/export_delete_test.go index 5350674f06..b7b52d69df 100644 --- a/server/channels/jobs/export_delete_test.go +++ b/server/channels/jobs/export_delete_test.go @@ -15,6 +15,7 @@ import ( ) func TestExportDelete(t *testing.T) { + mainHelper.Parallel(t) // Create a temporary export directory fileSettingsDir, err := os.MkdirTemp("", "") require.NoError(t, err) diff --git a/server/channels/jobs/helper_test.go b/server/channels/jobs/helper_test.go index 439d391fa9..2ad1b901b5 100644 --- a/server/channels/jobs/helper_test.go +++ b/server/channels/jobs/helper_test.go @@ -29,6 +29,7 @@ type TestHelper struct { BasicTeam *model.Team BasicUser *model.User BasicUser2 *model.User + Store store.Store SystemAdminUser *model.User LogBuffer *mlog.Buffer @@ -36,18 +37,18 @@ type TestHelper struct { IncludeCacheLayer bool ConfigStore *config.Store - tempWorkspace string - oldWatcherPollingInterval int + tempWorkspace string } -func setupTestHelper(tb testing.TB, dbStore store.Store, enterprise bool, includeCacheLayer bool, - updateCfg func(cfg *model.Config), options []app.Option) *TestHelper { +func setupTestHelper(tb testing.TB, dbStore store.Store, sqlSettings *model.SqlSettings, enterprise bool, includeCacheLayer bool, + updateCfg func(cfg *model.Config), options []app.Option, +) *TestHelper { tempWorkspace, err := os.MkdirTemp("", "jobstest") require.NoError(tb, err) configStore := config.NewTestMemoryStore() memoryConfig := configStore.Get() - memoryConfig.SqlSettings = *mainHelper.GetSQLSettings() + memoryConfig.SqlSettings = *sqlSettings *memoryConfig.PluginSettings.Directory = filepath.Join(tempWorkspace, "plugins") *memoryConfig.PluginSettings.ClientDirectory = filepath.Join(tempWorkspace, "webapp") *memoryConfig.PluginSettings.AutomaticPrepackagedPlugins = false @@ -96,6 +97,7 @@ func setupTestHelper(tb testing.TB, dbStore store.Store, enterprise bool, includ TestLogger: testLogger, IncludeCacheLayer: includeCacheLayer, ConfigStore: configStore, + Store: dbStore, tempWorkspace: tempWorkspace, } @@ -131,10 +133,6 @@ func setupTestHelper(tb testing.TB, dbStore store.Store, enterprise bool, includ if th.tempWorkspace != "" { os.RemoveAll(th.tempWorkspace) } - - if th.oldWatcherPollingInterval != 0 { - jobs.DefaultWatcherPollingInterval = th.oldWatcherPollingInterval - } }) return th @@ -150,16 +148,22 @@ func SetupWithUpdateCfg(tb testing.TB, updateCfg func(cfg *model.Config), option tb.SkipNow() } - oldWatcherPollingInterval := jobs.DefaultWatcherPollingInterval - jobs.DefaultWatcherPollingInterval = 100 + var dbStore store.Store + var dbSettings *model.SqlSettings + if mainHelper.Options.RunParallel { + dbStore, _, dbSettings, _ = mainHelper.GetNewStores(tb) + tb.Cleanup(func() { + dbStore.Close() + }) + } else { + dbStore = mainHelper.GetStore() + dbSettings = mainHelper.GetSQLSettings() + dbStore.DropAllTables() + dbStore.MarkSystemRanUnitTests() + mainHelper.PreloadMigrations() + } - dbStore := mainHelper.GetStore() - dbStore.DropAllTables() - dbStore.MarkSystemRanUnitTests() - mainHelper.PreloadMigrations() - - th := setupTestHelper(tb, dbStore, false, true, updateCfg, options) - th.oldWatcherPollingInterval = oldWatcherPollingInterval + th := setupTestHelper(tb, dbStore, dbSettings, false, true, updateCfg, options) return th } @@ -228,6 +232,22 @@ func (th *TestHelper) CreateUserOrGuest(tb testing.TB, guest bool) *model.User { return user } +func (th *TestHelper) ShutdownApp() { + done := make(chan bool) + go func() { + th.Server.Shutdown() + close(done) + }() + + select { + case <-done: + case <-time.After(30 * time.Second): + // panic instead of fatal to terminate all tests in this package, otherwise the + // still running App could spuriously fail subsequent tests. + panic("failed to shutdown App within 30 seconds") + } +} + func (th *TestHelper) SetupBatchWorker(tb testing.TB, worker *jobs.BatchWorker) *model.Job { tb.Helper() diff --git a/server/channels/jobs/jobs_test.go b/server/channels/jobs/jobs_test.go index 0860343900..7ebe5677ba 100644 --- a/server/channels/jobs/jobs_test.go +++ b/server/channels/jobs/jobs_test.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "net/http" + "os" "testing" "github.com/stretchr/testify/mock" @@ -64,6 +65,10 @@ func makeTeamEditionJobServer(t *testing.T) (*JobServer, *storetest.Store) { } func TestClaimJob(t *testing.T) { + if os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" { + t.Parallel() + } + t.Run("error claiming job", func(t *testing.T) { jobServer, mockStore, _ := makeJobServer(t) @@ -141,6 +146,10 @@ func TestClaimJob(t *testing.T) { } func TestSetJobProgress(t *testing.T) { + if os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" { + t.Parallel() + } + t.Run("error setting progress", func(t *testing.T) { jobServer, mockStore, _ := makeJobServer(t) @@ -180,6 +189,10 @@ func TestSetJobProgress(t *testing.T) { } func TestSetJobWarning(t *testing.T) { + if os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" { + t.Parallel() + } + t.Run("error setting status", func(t *testing.T) { jobServer, mockStore, _ := makeJobServer(t) @@ -216,6 +229,10 @@ func TestSetJobWarning(t *testing.T) { } func TestSetJobSuccess(t *testing.T) { + if os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" { + t.Parallel() + } + t.Run("error setting status", func(t *testing.T) { jobServer, mockStore, _ := makeJobServer(t) @@ -261,6 +278,10 @@ func TestSetJobSuccess(t *testing.T) { } func TestSetJobError(t *testing.T) { + if os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" { + t.Parallel() + } + t.Run("nil provided job error", func(t *testing.T) { t.Run("error setting status", func(t *testing.T) { jobServer, mockStore, _ := makeJobServer(t) @@ -448,6 +469,10 @@ func TestSetJobError(t *testing.T) { } func TestSetJobCanceled(t *testing.T) { + if os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" { + t.Parallel() + } + t.Run("error setting status", func(t *testing.T) { jobServer, mockStore, _ := makeJobServer(t) @@ -493,6 +518,10 @@ func TestSetJobCanceled(t *testing.T) { } func TestUpdateInProgressJobData(t *testing.T) { + if os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" { + t.Parallel() + } + t.Run("error updating", func(t *testing.T) { jobServer, mockStore, _ := makeJobServer(t) @@ -527,6 +556,10 @@ func TestUpdateInProgressJobData(t *testing.T) { } func TestHandleJobPanic(t *testing.T) { + if os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" { + t.Parallel() + } + t.Run("no panic", func(t *testing.T) { logger := mlog.CreateConsoleTestLogger(t) jobServer, _, _ := makeJobServer(t) @@ -589,6 +622,10 @@ func TestHandleJobPanic(t *testing.T) { } func TestRequestCancellation(t *testing.T) { + if os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" { + t.Parallel() + } + ctx := request.TestContext(t) t.Run("error cancelling", func(t *testing.T) { jobServer, mockStore, _ := makeJobServer(t) diff --git a/server/channels/jobs/main_test.go b/server/channels/jobs/main_test.go index 943d307f6d..8d8338947f 100644 --- a/server/channels/jobs/main_test.go +++ b/server/channels/jobs/main_test.go @@ -4,17 +4,39 @@ package jobs_test import ( + "flag" + "os" + "strconv" "testing" + "github.com/mattermost/mattermost/server/public/shared/mlog" + "github.com/mattermost/mattermost/server/v8/channels/jobs" "github.com/mattermost/mattermost/server/v8/channels/testlib" ) var mainHelper *testlib.MainHelper func TestMain(m *testing.M) { - var options = testlib.HelperOptions{ + var parallelism int + if f := flag.Lookup("test.parallel"); f != nil { + parallelism, _ = strconv.Atoi(f.Value.String()) + } + runParallel := os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" && parallelism > 1 + if runParallel { + mlog.Info("Fully parallel tests enabled", mlog.Int("parallelism", parallelism)) + } + + oldWatcherPollingInterval := jobs.DefaultWatcherPollingInterval + jobs.DefaultWatcherPollingInterval = 100 + defer func() { + jobs.DefaultWatcherPollingInterval = oldWatcherPollingInterval + }() + + options := testlib.HelperOptions{ EnableStore: true, EnableResources: true, + RunParallel: runParallel, + Parallelism: parallelism, } mainHelper = testlib.NewMainHelperWithOptions(&options) diff --git a/server/channels/jobs/schedulers_test.go b/server/channels/jobs/schedulers_test.go index fddf9d0b12..53bfdb45f9 100644 --- a/server/channels/jobs/schedulers_test.go +++ b/server/channels/jobs/schedulers_test.go @@ -3,6 +3,7 @@ package jobs import ( + "os" "sync" "testing" "time" @@ -35,6 +36,10 @@ func (scheduler *MockScheduler) ScheduleJob(c request.CTX, cfg *model.Config, pe } func TestScheduler(t *testing.T) { + if os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" { + t.Parallel() + } + mockStore := &storetest.Store{} defer mockStore.AssertExpectations(t) @@ -171,6 +176,10 @@ func TestScheduler(t *testing.T) { } func TestRandomDelay(t *testing.T) { + if os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" { + t.Parallel() + } + cases := []int64{5, 10, 100} for _, c := range cases { out := getRandomDelay(c) diff --git a/server/channels/jobs/server_test.go b/server/channels/jobs/server_test.go index 9c550c54d9..4330f60348 100644 --- a/server/channels/jobs/server_test.go +++ b/server/channels/jobs/server_test.go @@ -4,6 +4,7 @@ package jobs import ( + "os" "testing" "time" @@ -11,6 +12,10 @@ import ( ) func TestStartWorkers(t *testing.T) { + if os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" { + t.Parallel() + } + t.Run("uninitialized", func(t *testing.T) { jobServer, _, _ := makeJobServer(t) err := jobServer.StartWorkers() @@ -43,6 +48,10 @@ func TestStartWorkers(t *testing.T) { } func TestStopWorkers(t *testing.T) { + if os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" { + t.Parallel() + } + t.Run("uninitialized", func(t *testing.T) { jobServer, _, _ := makeJobServer(t) err := jobServer.StopWorkers() @@ -69,6 +78,10 @@ func TestStopWorkers(t *testing.T) { } func TestStartSchedulers(t *testing.T) { + if os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" { + t.Parallel() + } + t.Run("uninitialized", func(t *testing.T) { jobServer, _, _ := makeJobServer(t) err := jobServer.StartSchedulers() @@ -99,6 +112,10 @@ func TestStartSchedulers(t *testing.T) { } func TestStopSchedulers(t *testing.T) { + if os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" { + t.Parallel() + } + t.Run("uninitialized", func(t *testing.T) { jobServer, _, _ := makeJobServer(t) err := jobServer.StopSchedulers() diff --git a/server/channels/store/sqlstore/channel_store_test.go b/server/channels/store/sqlstore/channel_store_test.go index ae32bf8362..0169c11f40 100644 --- a/server/channels/store/sqlstore/channel_store_test.go +++ b/server/channels/store/sqlstore/channel_store_test.go @@ -25,6 +25,10 @@ func TestSearchChannelStore(t *testing.T) { } func TestChannelSearchQuerySQLInjection(t *testing.T) { + if enableFullyParallelTests { + t.Parallel() + } + for _, st := range storeTypes { t.Run(st.Name, func(t *testing.T) { s := &SqlChannelStore{ diff --git a/server/channels/store/sqlstore/context_test.go b/server/channels/store/sqlstore/context_test.go index 6bc60c12cf..645b19ad65 100644 --- a/server/channels/store/sqlstore/context_test.go +++ b/server/channels/store/sqlstore/context_test.go @@ -12,6 +12,10 @@ import ( ) func TestContextMaster(t *testing.T) { + if enableFullyParallelTests { + t.Parallel() + } + ctx := context.Background() m := WithMaster(ctx) @@ -19,6 +23,10 @@ func TestContextMaster(t *testing.T) { } func TestRequestContextWithMaster(t *testing.T) { + if enableFullyParallelTests { + t.Parallel() + } + t.Run("set and get", func(t *testing.T) { var rctx request.CTX = request.TestContext(t) diff --git a/server/channels/store/sqlstore/init_test.go b/server/channels/store/sqlstore/init_test.go index a0e92351f0..2ff1b47488 100644 --- a/server/channels/store/sqlstore/init_test.go +++ b/server/channels/store/sqlstore/init_test.go @@ -7,8 +7,11 @@ import ( "github.com/mattermost/mattermost/server/public/shared/mlog" ) -func InitTest(logger mlog.LoggerIFace) { - initStores(logger) +var enableFullyParallelTests bool + +func InitTest(logger mlog.LoggerIFace, parallelism int) { + enableFullyParallelTests = parallelism > 1 + initStores(logger, parallelism) } func TearDownTest() { diff --git a/server/channels/store/sqlstore/main_test.go b/server/channels/store/sqlstore/main_test.go index e070300cf2..db6b8854b8 100644 --- a/server/channels/store/sqlstore/main_test.go +++ b/server/channels/store/sqlstore/main_test.go @@ -4,8 +4,12 @@ package sqlstore_test import ( + "flag" + "os" + "strconv" "testing" + "github.com/mattermost/mattermost/server/public/shared/mlog" "github.com/mattermost/mattermost/server/v8/channels/store/sqlstore" "github.com/mattermost/mattermost/server/v8/channels/testlib" ) @@ -13,10 +17,21 @@ import ( var mainHelper *testlib.MainHelper func TestMain(m *testing.M) { + var parallelism int + if f := flag.Lookup("test.parallel"); f != nil { + parallelism, _ = strconv.Atoi(f.Value.String()) + } + runParallel := os.Getenv("ENABLE_FULLY_PARALLEL_TESTS") == "true" && parallelism > 1 + if runParallel { + mlog.Info("Fully parallel tests enabled", mlog.Int("parallelism", parallelism)) + } else { + parallelism = 1 + } + mainHelper = testlib.NewMainHelperWithOptions(nil) defer mainHelper.Close() - sqlstore.InitTest(mainHelper.Logger) + sqlstore.InitTest(mainHelper.Logger, parallelism) mainHelper.Main(m) sqlstore.TearDownTest() diff --git a/server/channels/store/sqlstore/store_test.go b/server/channels/store/sqlstore/store_test.go index 55156dd928..d169692a17 100644 --- a/server/channels/store/sqlstore/store_test.go +++ b/server/channels/store/sqlstore/store_test.go @@ -41,7 +41,32 @@ type storeType struct { Store store.Store } -var storeTypes []*storeType +var ( + storeTypes []*storeType + storePools []*TestPool +) + +func getStoresFromPools(t *testing.T) []*storeType { + stores := make([]*storeType, len(storePools)) + for i, pool := range storePools { + entry := pool.Get(t) + if entry == nil { + panic("failed to get store from pool") + } + + entry.Store.DropAllTables() + entry.Store.MarkSystemRanUnitTests() + + stores[i] = &storeType{ + Name: *entry.Settings.DriverName, + SqlSettings: entry.Settings, + SqlStore: entry.Store, + Store: entry.Store, + } + } + + return stores +} func newStoreType(name, driver string) *storeType { return &storeType{ @@ -57,7 +82,14 @@ func StoreTest(t *testing.T, f func(*testing.T, request.CTX, store.Store)) { panic(err) } }() - for _, st := range storeTypes { + + stores := storeTypes + if enableFullyParallelTests { + t.Parallel() + stores = getStoresFromPools(t) + } + + for _, st := range stores { st := st rctx := request.TestContext(t) @@ -65,6 +97,7 @@ func StoreTest(t *testing.T, f func(*testing.T, request.CTX, store.Store)) { if testing.Short() { t.SkipNow() } + f(t, rctx, st.Store) }) } @@ -78,13 +111,21 @@ func StoreTestWithSearchTestEngine(t *testing.T, f func(*testing.T, store.Store, } }() - for _, st := range storeTypes { + stores := storeTypes + if enableFullyParallelTests { + t.Parallel() + stores = getStoresFromPools(t) + } + + for _, st := range stores { st := st searchTestEngine := &searchtest.SearchTestEngine{ Driver: *st.SqlSettings.DriverName, } - t.Run(st.Name, func(t *testing.T) { f(t, st.Store, searchTestEngine) }) + t.Run(st.Name, func(t *testing.T) { + f(t, st.Store, searchTestEngine) + }) } } @@ -95,7 +136,14 @@ func StoreTestWithSqlStore(t *testing.T, f func(*testing.T, request.CTX, store.S panic(err) } }() - for _, st := range storeTypes { + + stores := storeTypes + if enableFullyParallelTests { + t.Parallel() + stores = getStoresFromPools(t) + } + + for _, st := range stores { st := st rctx := request.TestContext(t) @@ -108,7 +156,7 @@ func StoreTestWithSqlStore(t *testing.T, f func(*testing.T, request.CTX, store.S } } -func initStores(logger mlog.LoggerIFace) { +func initStores(logger mlog.LoggerIFace, parallelism int) { if testing.Short() { return } @@ -120,12 +168,31 @@ func initStores(logger mlog.LoggerIFace) { storeTypes = append(storeTypes, newStoreType("MySQL", model.DatabaseDriverMysql)) case "postgres": storeTypes = append(storeTypes, newStoreType("PostgreSQL", model.DatabaseDriverPostgres)) + if enableFullyParallelTests { + pgStorePool, err := NewTestPool(logger, model.DatabaseDriverPostgres, parallelism) + if err != nil { + panic(err) + } + storePools = append(storePools, pgStorePool) + } } } else { storeTypes = append(storeTypes, newStoreType("MySQL", model.DatabaseDriverMysql), newStoreType("PostgreSQL", model.DatabaseDriverPostgres), ) + + if enableFullyParallelTests { + pgStorePool, err := NewTestPool(logger, model.DatabaseDriverPostgres, parallelism) + if err != nil { + panic(err) + } + msStorePool, err := NewTestPool(logger, model.DatabaseDriverMysql, parallelism) + if err != nil { + panic(err) + } + storePools = append(storePools, pgStorePool, msStorePool) + } } defer func() { @@ -177,7 +244,19 @@ func tearDownStores() { wg.Done() }() } + + var wgPool sync.WaitGroup + wgPool.Add(len(storePools)) + for _, pool := range storePools { + pool := pool + go func() { + defer wgPool.Done() + pool.Close() + }() + } + wg.Wait() + wgPool.Wait() }) } @@ -185,6 +264,10 @@ func tearDownStores() { // before the fix in MM-28397. // Keeping it here to help avoiding future regressions. func TestStoreLicenseRace(t *testing.T) { + if enableFullyParallelTests { + t.Parallel() + } + logger := mlog.CreateTestLogger(t) settings, err := makeSqlSettings(model.DatabaseDriverPostgres) @@ -422,6 +505,10 @@ func TestGetReplica(t *testing.T) { } func TestGetDbVersion(t *testing.T) { + if enableFullyParallelTests { + t.Parallel() + } + logger := mlog.CreateTestLogger(t) testDrivers := []string{ @@ -449,6 +536,10 @@ func TestGetDbVersion(t *testing.T) { } func TestEnsureMinimumDBVersion(t *testing.T) { + if enableFullyParallelTests { + t.Parallel() + } + tests := []struct { driver string ver string @@ -530,6 +621,10 @@ func TestEnsureMinimumDBVersion(t *testing.T) { } func TestIsBinaryParamEnabled(t *testing.T) { + if enableFullyParallelTests { + t.Parallel() + } + tests := []struct { store SqlStore expected bool @@ -677,6 +772,10 @@ func TestGetAllConns(t *testing.T) { } func TestIsDuplicate(t *testing.T) { + if enableFullyParallelTests { + t.Parallel() + } + testErrors := map[error]bool{ &pq.Error{Code: "42P06"}: false, &pq.Error{Code: PGDupTableErrorCode}: true, @@ -696,6 +795,10 @@ func TestIsDuplicate(t *testing.T) { } func TestVersionString(t *testing.T) { + if enableFullyParallelTests { + t.Parallel() + } + versions := []struct { input int driver string @@ -735,6 +838,10 @@ func TestVersionString(t *testing.T) { } func TestReplicaLagQuery(t *testing.T) { + if enableFullyParallelTests { + t.Parallel() + } + testDrivers := []string{ model.DatabaseDriverPostgres, model.DatabaseDriverMysql, @@ -796,6 +903,10 @@ func TestReplicaLagQuery(t *testing.T) { } func TestInvalidReplicaLagDataSource(t *testing.T) { + if enableFullyParallelTests { + t.Parallel() + } + logger := mlog.CreateConsoleTestLogger(t) testDrivers := []string{ @@ -910,6 +1021,10 @@ func TestMySQLReadTimeout(t *testing.T) { } func TestGetDBSchemaVersion(t *testing.T) { + if enableFullyParallelTests { + t.Parallel() + } + testDrivers := []string{ model.DatabaseDriverPostgres, model.DatabaseDriverMysql, @@ -950,6 +1065,10 @@ func TestGetDBSchemaVersion(t *testing.T) { } func TestGetLocalSchemaVersion(t *testing.T) { + if enableFullyParallelTests { + t.Parallel() + } + testDrivers := []string{ model.DatabaseDriverPostgres, model.DatabaseDriverMysql, @@ -978,6 +1097,10 @@ func TestGetLocalSchemaVersion(t *testing.T) { } func TestGetAppliedMigrations(t *testing.T) { + if enableFullyParallelTests { + t.Parallel() + } + testDrivers := []string{ model.DatabaseDriverPostgres, model.DatabaseDriverMysql, @@ -1026,6 +1149,10 @@ func TestGetAppliedMigrations(t *testing.T) { } func TestSkipMigrationsOption(t *testing.T) { + if enableFullyParallelTests { + t.Parallel() + } + testDrivers := []string{ model.DatabaseDriverPostgres, model.DatabaseDriverMysql, diff --git a/server/channels/store/sqlstore/testpool.go b/server/channels/store/sqlstore/testpool.go new file mode 100644 index 0000000000..e1fdabafc7 --- /dev/null +++ b/server/channels/store/sqlstore/testpool.go @@ -0,0 +1,114 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +package sqlstore + +import ( + "sync" + "testing" + + "golang.org/x/sync/errgroup" + + "github.com/mattermost/mattermost/server/public/model" + "github.com/mattermost/mattermost/server/public/shared/mlog" + "github.com/mattermost/mattermost/server/v8/channels/store/storetest" +) + +// TestPool is used to facilitate the efficient (and safe) use of test stores in parallel tests (e.g. in api4, app, sqlstore). +type TestPool struct { + entries map[string]*TestPoolEntry + mut sync.Mutex + logger mlog.LoggerIFace +} + +type TestPoolEntry struct { + Store *SqlStore + Settings *model.SqlSettings +} + +func NewTestPool(logger mlog.LoggerIFace, driverName string, poolSize int) (*TestPool, error) { + logger.Info("Creating test store pool", mlog.Int("poolSize", poolSize)) + + entries := make(map[string]*TestPoolEntry, poolSize) + + var mut sync.Mutex + var eg errgroup.Group + for i := 0; i < poolSize; i++ { + eg.Go(func() error { + settings := storetest.MakeSqlSettings(driverName, false) + sqlStore, err := New(*settings, logger, nil) + if err != nil { + return err + } + + mut.Lock() + logger.Info("Initializing test store in pool", mlog.String("datasource", *settings.DataSource)) + entries[*settings.DataSource] = &TestPoolEntry{ + Store: sqlStore, + Settings: settings, + } + mut.Unlock() + + return nil + }) + } + + if err := eg.Wait(); err != nil { + return nil, err + } + + return &TestPool{ + entries: entries, + logger: logger, + }, nil +} + +func (p *TestPool) Get(t testing.TB) *TestPoolEntry { + p.mut.Lock() + defer p.mut.Unlock() + + p.logger.Info("Getting from test store pool", mlog.Int("poolSize", len(p.entries))) + + var poolEntry *TestPoolEntry + for _, entry := range p.entries { + poolEntry = entry + delete(p.entries, *entry.Settings.DataSource) + break + } + + // No more stores available in the pool + if poolEntry == nil { + return nil + } + + p.logger.Info("Got store from pool", mlog.String("datasource", *poolEntry.Settings.DataSource), mlog.Int("poolSize", len(p.entries))) + + dataSource := *poolEntry.Settings.DataSource + + // Return store to pool on test cleanup + t.Cleanup(func() { + p.mut.Lock() + defer p.mut.Unlock() + p.logger.Info("Returning to test store pool", mlog.String("datasource", dataSource), mlog.Int("poolSize", len(p.entries))) + p.entries[dataSource] = poolEntry + }) + + return poolEntry +} + +func (p *TestPool) Close() { + p.mut.Lock() + defer p.mut.Unlock() + + var wg sync.WaitGroup + wg.Add(len(p.entries)) + for _, entry := range p.entries { + entry := entry + go func() { + defer wg.Done() + entry.Store.Close() + storetest.CleanupSqlSettings(entry.Settings) + }() + } + wg.Wait() +} diff --git a/server/channels/store/sqlstore/utils_test.go b/server/channels/store/sqlstore/utils_test.go index 1d3da07186..a3eeecdf42 100644 --- a/server/channels/store/sqlstore/utils_test.go +++ b/server/channels/store/sqlstore/utils_test.go @@ -14,6 +14,10 @@ import ( ) func TestMapStringsToQueryParams(t *testing.T) { + if enableFullyParallelTests { + t.Parallel() + } + t.Run("one item", func(t *testing.T) { input := []string{"apple"} @@ -37,8 +41,10 @@ func TestMapStringsToQueryParams(t *testing.T) { }) } -var keys string -var params map[string]any +var ( + keys string + params map[string]any +) func BenchmarkMapStringsToQueryParams(b *testing.B) { b.Run("one item", func(b *testing.B) { @@ -56,6 +62,10 @@ func BenchmarkMapStringsToQueryParams(b *testing.B) { } func TestSanitizeSearchTerm(t *testing.T) { + if enableFullyParallelTests { + t.Parallel() + } + term := "test" result := sanitizeSearchTerm(term, "\\") require.Equal(t, result, term) @@ -82,6 +92,10 @@ func TestSanitizeSearchTerm(t *testing.T) { } func TestRemoveNonAlphaNumericUnquotedTerms(t *testing.T) { + if enableFullyParallelTests { + t.Parallel() + } + const ( sep = " " chineseHello = "你好" @@ -109,6 +123,10 @@ func TestRemoveNonAlphaNumericUnquotedTerms(t *testing.T) { } func TestMySQLJSONArgs(t *testing.T) { + if enableFullyParallelTests { + t.Parallel() + } + tests := []struct { props map[string]string args []any diff --git a/server/channels/testlib/helper.go b/server/channels/testlib/helper.go index 8a29ca45b2..1ef584c7e3 100644 --- a/server/channels/testlib/helper.go +++ b/server/channels/testlib/helper.go @@ -31,16 +31,20 @@ type MainHelper struct { SQLStore *sqlstore.SqlStore ClusterInterface *FakeClusterInterface Logger *mlog.Logger + Options HelperOptions status int testResourcePath string replicas []string + storePool *sqlstore.TestPool } type HelperOptions struct { EnableStore bool EnableResources bool WithReadReplica bool + RunParallel bool + Parallelism int } func NewMainHelper() *MainHelper { @@ -85,6 +89,8 @@ func NewMainHelperWithOptions(options *HelperOptions) *MainHelper { } if options != nil { + mainHelper.Options = *options + if options.EnableStore && !testing.Short() { mainHelper.setupStore(options.WithReadReplica) } @@ -92,6 +98,20 @@ func NewMainHelperWithOptions(options *HelperOptions) *MainHelper { if options.EnableResources { mainHelper.setupResources() } + + if options.RunParallel && options.EnableStore { + driverName := os.Getenv("MM_SQLSETTINGS_DRIVERNAME") + if driverName == "" { + driverName = model.DatabaseDriverPostgres + } + // NOTE: we use a poolSize higher than the parallelism value (coming from -test.parallel flag) as we need a bit of extra buffer to cover + // for subtests that might also run in parallel and initialize a new store. + storePool, err := sqlstore.NewTestPool(mainHelper.Logger, driverName, options.Parallelism*2) + if err != nil { + panic(err) + } + mainHelper.storePool = storePool + } } return &mainHelper @@ -127,6 +147,36 @@ func (h *MainHelper) Main(m *testing.M) { h.status = m.Run() } +func (h *MainHelper) GetNewStores(tb testing.TB) (store.Store, *sqlstore.SqlStore, *model.SqlSettings, *searchengine.Broker) { + driverName := os.Getenv("MM_SQLSETTINGS_DRIVERNAME") + if driverName == "" { + driverName = model.DatabaseDriverPostgres + } + + config := &model.Config{} + config.SetDefaults() + + searchEngine := searchengine.NewBroker(config) + + storePoolEntry := h.storePool.Get(tb) + if storePoolEntry == nil { + panic("no store available in the pool") + } + settings := storePoolEntry.Settings + sqlStore := storePoolEntry.Store + sqlStore.DropAllTables() + + store := searchlayer.NewSearchLayer(&TestStore{ + sqlStore, + }, searchEngine, config) + + store.MarkSystemRanUnitTests() + + preloadMigrations(driverName, sqlStore) + + return store, sqlStore, settings, searchEngine +} + func (h *MainHelper) setupStore(withReadReplica bool) { driverName := os.Getenv("MM_SQLSETTINGS_DRIVERNAME") if driverName == "" { @@ -204,11 +254,11 @@ func (h *MainHelper) setupResources() { // pg_dump -a -h localhost -U mmuser -d <> --no-comments --inserts -t roles -t systems // mysqldump -u root -p <> --no-create-info --extended-insert=FALSE Systems Roles // And keep only the permission related rows in the systems table output. -func (h *MainHelper) PreloadMigrations() { +func preloadMigrations(driverName string, sqlStore *sqlstore.SqlStore) { var buf []byte var err error - switch *h.Settings.DriverName { + switch driverName { case model.DatabaseDriverPostgres: finalPath := filepath.Join(server.GetPackagePath(), "channels", "testlib", "testdata", "postgres_migration_warmup.sql") buf, err = os.ReadFile(finalPath) @@ -222,13 +272,17 @@ func (h *MainHelper) PreloadMigrations() { panic(fmt.Errorf("cannot read file: %v", err)) } } - handle := h.SQLStore.GetMaster() + handle := sqlStore.GetMaster() _, err = handle.Exec(string(buf)) if err != nil { panic(errors.Wrap(err, "Error preloading migrations. Check if you have &multiStatements=true in your DSN if you are using MySQL. Or perhaps the schema changed? If yes, then update the warmup files accordingly")) } } +func (h *MainHelper) PreloadMigrations() { + preloadMigrations(*h.Settings.DriverName, h.SQLStore) +} + func (h *MainHelper) Close() error { if h.SQLStore != nil { h.SQLStore.Close() @@ -240,6 +294,10 @@ func (h *MainHelper) Close() error { os.RemoveAll(h.testResourcePath) } + if h.storePool != nil { + h.storePool.Close() + } + if r := recover(); r != nil { log.Fatalln(r) } @@ -321,3 +379,9 @@ func (h *MainHelper) execOnEachReplica(query string, args ...any) error { } return nil } + +func (h *MainHelper) Parallel(t *testing.T) { + if h.Options.RunParallel { + t.Parallel() + } +} diff --git a/server/public/shared/i18n/i18n.go b/server/public/shared/i18n/i18n.go index 9f72a3d997..5b5c2d7dfb 100644 --- a/server/public/shared/i18n/i18n.go +++ b/server/public/shared/i18n/i18n.go @@ -11,6 +11,7 @@ import ( "path/filepath" "reflect" "strings" + "sync" "github.com/mattermost/go-i18n/i18n" "github.com/mattermost/go-i18n/i18n/bundle" @@ -18,6 +19,10 @@ import ( "github.com/mattermost/mattermost/server/public/shared/mlog" ) +// mut is used to protect other global variables from concurrent access. +// This should only be a concern in parallel tests. +var mut sync.Mutex + const defaultLocale = "en" // TranslateFunc is the type of the translate functions @@ -26,11 +31,34 @@ type TranslateFunc func(translationID string, args ...any) string // TranslationFuncByLocal is the type of function that takes local as a string and returns the translation function type TranslationFuncByLocal func(locale string) TranslateFunc +var ( + t TranslateFunc + tDefault TranslateFunc +) + // T is the translate function using the default server language as fallback language -var T TranslateFunc +var T TranslateFunc = func(translationID string, args ...any) string { + mut.Lock() + defer mut.Unlock() + + if t == nil { + return translationID + } + + return t(translationID, args...) +} // TDefault is the translate function using english as fallback language -var TDefault TranslateFunc +var TDefault TranslateFunc = func(translationID string, args ...any) string { + mut.Lock() + defer mut.Unlock() + + if tDefault == nil { + return translationID + } + + return t(translationID, args...) +} var locales = make(map[string]string) @@ -60,20 +88,25 @@ var supportedLocales = []string{ "zh-TW", "ja", } -var defaultServerLocale string -var defaultClientLocale string + +var ( + defaultServerLocale string + defaultClientLocale string +) // TranslationsPreInit loads translations from filesystem if they are not // loaded already and assigns english while loading server config func TranslationsPreInit(translationsDir string) error { - if T != nil { + mut.Lock() + defer mut.Unlock() + if t != nil { return nil } // Set T even if we fail to load the translations. Lots of shutdown handling code will // segfault trying to handle the error, and the untranslated IDs are strictly better. - T = tfuncWithFallback(defaultLocale) - TDefault = tfuncWithFallback(defaultLocale) + t = tfuncWithFallback(defaultLocale) + tDefault = tfuncWithFallback(defaultLocale) return initTranslationsWithDir(translationsDir) } @@ -81,14 +114,16 @@ func TranslationsPreInit(translationsDir string) error { // TranslationsPreInitFromFileBytes loads translations from a buffer -- useful if // we need to initialize i18n from an embedded i18n file (e.g., from a CLI tool) func TranslationsPreInitFromFileBytes(filename string, buf []byte) error { - if T != nil { + mut.Lock() + defer mut.Unlock() + if t != nil { return nil } // Set T even if we fail to load the translations. Lots of shutdown handling code will // segfault trying to handle the error, and the untranslated IDs are strictly better. - T = tfuncWithFallback(defaultLocale) - TDefault = tfuncWithFallback(defaultLocale) + t = tfuncWithFallback(defaultLocale) + tDefault = tfuncWithFallback(defaultLocale) locale := strings.Split(filename, ".")[0] if !isSupportedLocale(locale) { @@ -103,11 +138,17 @@ func TranslationsPreInitFromFileBytes(filename string, buf []byte) error { // InitTranslations set the defaults configured in the server and initialize // the T function using the server default as fallback language func InitTranslations(serverLocale, clientLocale string) error { + mut.Lock() defaultServerLocale = serverLocale defaultClientLocale = clientLocale + mut.Unlock() + + tfn, err := GetTranslationsBySystemLocale() + + mut.Lock() + t = tfn + mut.Unlock() - var err error - T, err = GetTranslationsBySystemLocale() return err } @@ -136,7 +177,7 @@ func initTranslationsWithDir(dir string) error { // GetTranslationFuncForDir loads translations from the filesystem into a new instance of the bundle. // It returns a function to access loaded translations. func GetTranslationFuncForDir(dir string) (TranslationFuncByLocal, error) { - var availableLocals = make(map[string]string) + availableLocals := make(map[string]string) bundle := bundle.New() files, _ := os.ReadDir(dir) for _, f := range files { @@ -174,6 +215,8 @@ func GetTranslationFuncForDir(dir string) (TranslationFuncByLocal, error) { } func GetTranslationsBySystemLocale() (TranslateFunc, error) { + mut.Lock() + defer mut.Unlock() locale := defaultServerLocale if _, ok := locales[locale]; !ok { mlog.Warn("Failed to load system translations for selected locale, attempting to fall back to default", mlog.String("locale", locale), mlog.String("default_locale", defaultLocale)) @@ -200,6 +243,8 @@ func GetTranslationsBySystemLocale() (TranslateFunc, error) { // GetUserTranslations get the translation function for an specific locale func GetUserTranslations(locale string) TranslateFunc { + mut.Lock() + defer mut.Unlock() if _, ok := locales[locale]; !ok { locale = defaultLocale } @@ -211,6 +256,8 @@ func GetUserTranslations(locale string) TranslateFunc { // GetTranslationsAndLocaleFromRequest return the translation function and the // locale based on a request headers func GetTranslationsAndLocaleFromRequest(r *http.Request) (TranslateFunc, string) { + mut.Lock() + defer mut.Unlock() // This is for checking against locales like pt_BR or zn_CN headerLocaleFull := strings.Split(r.Header.Get("Accept-Language"), ",")[0] // This is for checking against locales like en, es @@ -234,6 +281,8 @@ func GetTranslationsAndLocaleFromRequest(r *http.Request) (TranslateFunc, string // GetSupportedLocales return a map of locale code and the file path with the // translations func GetSupportedLocales() map[string]string { + mut.Lock() + defer mut.Unlock() return locales }