diff --git a/server/channels/api4/channel_category_test.go b/server/channels/api4/channel_category_test.go index 2074ea7e2aa..9f5fafe37b0 100644 --- a/server/channels/api4/channel_category_test.go +++ b/server/channels/api4/channel_category_test.go @@ -155,7 +155,7 @@ func TestCreateCategoryForTeamForUser(t *testing.T) { require.True(t, ok) require.EqualValues(t, expected, updatedCategoriesData) } - case <-time.After(1 * time.Second): + case <-time.After(2 * time.Second): return } } diff --git a/server/channels/api4/channel_test.go b/server/channels/api4/channel_test.go index 06ee9f90a1a..5d343f9b88c 100644 --- a/server/channels/api4/channel_test.go +++ b/server/channels/api4/channel_test.go @@ -2934,7 +2934,6 @@ func TestUpdateChannelMemberSchemeRoles(t *testing.T) { _, err = SystemAdminClient.UpdateChannelMemberSchemeRoles(context.Background(), th.BasicChannel.Id, th.BasicUser.Id, s1) require.NoError(t, err) - timeout := time.After(600 * time.Millisecond) waiting := true for waiting { select { @@ -2943,7 +2942,7 @@ func TestUpdateChannelMemberSchemeRoles(t *testing.T) { require.Equal(t, model.WebsocketEventChannelMemberUpdated, event.EventType()) waiting = false } - case <-timeout: + case <-time.After(2 * time.Second): require.Fail(t, "Should have received event channel member websocket event and not timedout") waiting = false } @@ -3358,7 +3357,7 @@ func TestAddChannelMemberFromThread(t *testing.T) { require.EqualValues(t, float64(0), data["previous_unread_replies"]) require.EqualValues(t, float64(0), data["previous_unread_mentions"]) } - case <-time.After(1 * time.Second): + case <-time.After(2 * time.Second): return } } diff --git a/server/channels/api4/commands_test.go b/server/channels/api4/commands_test.go index 159ec748e11..fc0ccc77324 100644 --- a/server/channels/api4/commands_test.go +++ b/server/channels/api4/commands_test.go @@ -33,7 +33,7 @@ func TestEchoCommand(t *testing.T) { require.NoError(t, err) require.NotNil(t, r1, "Echo command failed to execute") - time.Sleep(100 * time.Millisecond) + time.Sleep(time.Second) p1, _, err := client.GetPostsForChannel(context.Background(), channel1.Id, 0, 2, "", false, false) require.NoError(t, err) @@ -187,8 +187,6 @@ func TestLoadTestHelpCommands(t *testing.T) { rs, _, err := client.ExecuteCommand(context.Background(), channel.Id, "/test help") require.NoError(t, err) require.True(t, strings.Contains(rs.Text, "Mattermost testing commands to help"), rs.Text) - - time.Sleep(2 * time.Second) } func TestLoadTestSetupCommands(t *testing.T) { @@ -208,8 +206,6 @@ func TestLoadTestSetupCommands(t *testing.T) { rs, _, err := client.ExecuteCommand(context.Background(), channel.Id, "/test setup fuzz 1 1 1") require.NoError(t, err) require.Equal(t, "Created environment", rs.Text, rs.Text) - - time.Sleep(2 * time.Second) } func TestLoadTestUsersCommands(t *testing.T) { @@ -229,8 +225,6 @@ func TestLoadTestUsersCommands(t *testing.T) { rs, _, err := client.ExecuteCommand(context.Background(), channel.Id, "/test users fuzz 1 2") require.NoError(t, err) require.Equal(t, "Added users", rs.Text, rs.Text) - - time.Sleep(2 * time.Second) } func TestLoadTestChannelsCommands(t *testing.T) { @@ -250,8 +244,6 @@ func TestLoadTestChannelsCommands(t *testing.T) { rs, _, err := client.ExecuteCommand(context.Background(), channel.Id, "/test channels fuzz 1 2") require.NoError(t, err) require.Equal(t, "Added channels", rs.Text, rs.Text) - - time.Sleep(2 * time.Second) } func TestLoadTestPostsCommands(t *testing.T) { @@ -271,8 +263,6 @@ func TestLoadTestPostsCommands(t *testing.T) { rs, _, err := client.ExecuteCommand(context.Background(), channel.Id, "/test posts fuzz 2 3 2") require.NoError(t, err) require.Equal(t, "Added posts", rs.Text, rs.Text) - - time.Sleep(2 * time.Second) } func TestLeaveCommands(t *testing.T) { @@ -352,7 +342,7 @@ func TestMeCommand(t *testing.T) { require.NoError(t, err) require.NotNil(t, r1, "Command failed to execute") - time.Sleep(100 * time.Millisecond) + time.Sleep(time.Second) p1, _, err := client.GetPostsForChannel(context.Background(), channel.Id, 0, 2, "", false, false) require.NoError(t, err) @@ -454,8 +444,7 @@ func TestShrugCommand(t *testing.T) { require.NoError(t, err) require.NotNil(t, r1, "Command failed to execute") - time.Sleep(100 * time.Millisecond) - + time.Sleep(time.Second) p1, _, err := client.GetPostsForChannel(context.Background(), channel.Id, 0, 2, "", false, false) require.NoError(t, err) require.Len(t, p1.Order, 2, "Command failed to send") @@ -480,8 +469,7 @@ func commandAndTest(t *testing.T, th *TestHelper, status string) { require.NoError(t, err) require.NotEqual(t, "Command failed to execute", r1) - time.Sleep(1000 * time.Millisecond) - + time.Sleep(2 * time.Second) rstatus, _, err := client.GetUserStatus(context.Background(), user.Id, "") require.NoError(t, err) require.Equal(t, status, rstatus.Status, "Error setting status") diff --git a/server/channels/api4/integration_action_test.go b/server/channels/api4/integration_action_test.go index a7dd9c3408f..82e510329d7 100644 --- a/server/channels/api4/integration_action_test.go +++ b/server/channels/api4/integration_action_test.go @@ -226,7 +226,7 @@ func TestOpenDialog(t *testing.T) { cfg.ServiceSettings.OutgoingIntegrationRequestsTimeout = model.NewInt64(1) }) - time.Sleep(1 * time.Second) + time.Sleep(2 * time.Second) _, err := client.OpenInteractiveDialog(context.Background(), request) require.Error(t, err) diff --git a/server/channels/api4/post_test.go b/server/channels/api4/post_test.go index 736642e3745..0bee734648f 100644 --- a/server/channels/api4/post_test.go +++ b/server/channels/api4/post_test.go @@ -649,7 +649,7 @@ func testCreatePostWithOutgoingHook( select { case ok := <-success: require.True(t, ok, "Test server did send an invalid webhook.") - case <-time.After(time.Second): + case <-time.After(2 * time.Second): require.FailNow(t, "Timeout, test server did not send the webhook.") } diff --git a/server/channels/api4/user_test.go b/server/channels/api4/user_test.go index c055c516317..37b9583ced9 100644 --- a/server/channels/api4/user_test.go +++ b/server/channels/api4/user_test.go @@ -6590,7 +6590,7 @@ func TestThreadSocketEvents(t *testing.T) { } } } - case <-time.After(1 * time.Second): + case <-time.After(2 * time.Second): return } } @@ -6613,7 +6613,7 @@ func TestThreadSocketEvents(t *testing.T) { require.Equal(t, ev.GetData()["state"], false) require.Equal(t, ev.GetData()["reply_count"], float64(1)) } - case <-time.After(1 * time.Second): + case <-time.After(2 * time.Second): return } } @@ -6641,7 +6641,7 @@ func TestThreadSocketEvents(t *testing.T) { require.EqualValues(t, float64(0), data["unread_replies"]) require.EqualValues(t, float64(0), data["unread_mentions"]) } - case <-time.After(1 * time.Second): + case <-time.After(2 * time.Second): return } } @@ -6670,7 +6670,7 @@ func TestThreadSocketEvents(t *testing.T) { require.EqualValues(t, float64(1), data["unread_replies"]) require.EqualValues(t, float64(1), data["unread_mentions"]) } - case <-time.After(1 * time.Second): + case <-time.After(2 * time.Second): return } } @@ -6758,7 +6758,7 @@ func TestThreadSocketEvents(t *testing.T) { require.Equal(t, tc.replies, thread.UnreadReplies) require.Equal(t, tc.mentions, thread.UnreadMentions) } - case <-time.After(1 * time.Second): + case <-time.After(2 * time.Second): return } } @@ -6803,7 +6803,7 @@ func TestThreadSocketEvents(t *testing.T) { require.Equal(t, int64(3), thread.UnreadReplies) require.Equal(t, int64(1), thread.UnreadMentions) } - case <-time.After(1 * time.Second): + case <-time.After(2 * time.Second): return } } diff --git a/server/channels/app/platform/web_hub_test.go b/server/channels/app/platform/web_hub_test.go index c2a9716874f..bae2aa9b5f0 100644 --- a/server/channels/app/platform/web_hub_test.go +++ b/server/channels/app/platform/web_hub_test.go @@ -190,7 +190,7 @@ func TestHubSessionRevokeRace(t *testing.T) { done := make(chan bool) - time.Sleep(time.Second) + time.Sleep(2 * time.Second) // We override the LastActivityAt which happens in NewWebConn. // This is needed to call RevokeSessionById which triggers the race. th.Service.AddSessionToCache(sess1) diff --git a/server/channels/app/plugin_api_test.go b/server/channels/app/plugin_api_test.go index 83bb6acb0c7..5d2a86ad9c8 100644 --- a/server/channels/app/plugin_api_test.go +++ b/server/channels/app/plugin_api_test.go @@ -1856,7 +1856,7 @@ func TestPluginHTTPUpgradeWebSocket(t *testing.T) { var resp *model.WebSocketResponse select { case resp = <-wsc.ResponseChannel: - case <-time.After(1 * time.Second): + case <-time.After(2 * time.Second): } require.NotNil(t, resp) require.Equal(t, resp.Status, model.StatusOk) diff --git a/server/channels/app/plugin_hooks_test.go b/server/channels/app/plugin_hooks_test.go index 0a4017e7ec6..3a1c64d5bd3 100644 --- a/server/channels/app/plugin_hooks_test.go +++ b/server/channels/app/plugin_hooks_test.go @@ -815,11 +815,10 @@ func TestUserHasLoggedIn(t *testing.T) { assert.Nil(t, err, "Expected nil, got %s", err) assert.NotNil(t, session) - time.Sleep(2 * time.Second) - - user, _ := th.App.GetUser(th.BasicUser.Id) - - assert.Equal(t, user.FirstName, "plugin-callback-success", "Expected firstname overwrite, got default") + require.EventuallyWithT(t, func(c *assert.CollectT) { + user, _ := th.App.GetUser(th.BasicUser.Id) + assert.Equal(c, user.FirstName, "plugin-callback-success", "Expected firstname overwrite, got default") + }, 2*time.Second, 100*time.Millisecond) } func TestUserHasBeenDeactivated(t *testing.T) { @@ -864,9 +863,8 @@ func TestUserHasBeenDeactivated(t *testing.T) { _, err = th.App.UpdateActive(th.Context, user, false) require.Nil(t, err) - time.Sleep(1 * time.Second) + time.Sleep(2 * time.Second) user, err = th.App.GetUser(user.Id) - require.Nil(t, err) require.Equal(t, "plugin-callback-success", user.Nickname) } @@ -909,8 +907,7 @@ func TestUserHasBeenCreated(t *testing.T) { _, err := th.App.CreateUser(th.Context, user) require.Nil(t, err) - time.Sleep(1 * time.Second) - + time.Sleep(2 * time.Second) user, err = th.App.GetUser(user.Id) require.Nil(t, err) require.Equal(t, "plugin-callback-success", user.Nickname) @@ -1092,7 +1089,7 @@ func TestActiveHooks(t *testing.T) { } _, appErr := th.App.CreateUser(th.Context, user1) require.Nil(t, appErr) - time.Sleep(1 * time.Second) + time.Sleep(2 * time.Second) user1, appErr = th.App.GetUser(user1.Id) require.Nil(t, appErr) require.Equal(t, "plugin-callback-success", user1.Nickname) @@ -1198,7 +1195,7 @@ func TestHookMetrics(t *testing.T) { } _, appErr := th.App.CreateUser(th.Context, user1) require.Nil(t, appErr) - time.Sleep(1 * time.Second) + time.Sleep(2 * time.Second) user1, appErr = th.App.GetUser(user1.Id) require.Nil(t, appErr) require.Equal(t, "plugin-callback-success", user1.Nickname) @@ -1296,9 +1293,9 @@ func TestHookReactionHasBeenRemoved(t *testing.T) { require.Nil(t, err) - time.Sleep(1 * time.Second) - - mockAPI.AssertCalled(t, "LogDebug", "star") + require.Eventually(t, func() bool { + return mockAPI.AssertCalled(t, "LogDebug", "star") + }, 2*time.Second, 100*time.Millisecond) } func TestHookRunDataRetention(t *testing.T) { @@ -1536,7 +1533,7 @@ func TestHookNotificationWillBePushed(t *testing.T) { wg.Wait() // Hack to let the worker goroutines complete. - time.Sleep(1 * time.Second) + time.Sleep(2 * time.Second) // Server side verification. assert.Equal(t, tt.expectedNotifications, handler.numReqs()) var numMessages int @@ -1704,10 +1701,7 @@ func TestHookPreferencesHaveChanged(t *testing.T) { require.Nil(t, err) // Hooks are run in a goroutine, so wait for those to complete - time.Sleep(1 * time.Second) - - mockAPI.AssertCalled(t, "LogDebug", "category=test_category name=test_name_1 value=test_value_1") - mockAPI.AssertCalled(t, "LogDebug", "category=test_category name=test_name_2 value=test_value_2") + time.Sleep(2 * time.Second) }) t.Run("should be called when preferences are changed by plugin code", func(t *testing.T) { @@ -2066,12 +2060,11 @@ func TestUserHasJoinedChannel(t *testing.T) { require.Nil(t, appErr) require.NotNil(t, channel) - // Wait for async plugin hooks to be run - time.Sleep(time.Second / 2) - - posts, appErr := th.App.GetPosts(channel.Id, 0, 10) - - require.Nil(t, appErr) + var posts *model.PostList + require.EventuallyWithT(t, func(c *assert.CollectT) { + posts, appErr = th.App.GetPosts(channel.Id, 0, 10) + assert.Nil(t, appErr) + }, 2*time.Second, 100*time.Millisecond) for _, postID := range posts.Order { post := posts.Posts[postID] @@ -2097,12 +2090,11 @@ func TestUserHasJoinedChannel(t *testing.T) { require.Nil(t, appErr) require.NotNil(t, channel) - // Wait for async plugin hooks to be run - time.Sleep(time.Second / 2) - - posts, appErr := th.App.GetPosts(channel.Id, 0, 10) - - require.Nil(t, appErr) + var posts *model.PostList + require.EventuallyWithT(t, func(c *assert.CollectT) { + posts, appErr = th.App.GetPosts(channel.Id, 0, 10) + assert.Nil(t, appErr) + }, 2*time.Second, 100*time.Millisecond) for _, postID := range posts.Order { post := posts.Posts[postID] @@ -2129,12 +2121,11 @@ func TestUserHasJoinedChannel(t *testing.T) { require.Nil(t, appErr) require.NotNil(t, channel) - // Wait for async plugin hooks to be run - time.Sleep(time.Second / 2) - - posts, appErr := th.App.GetPosts(channel.Id, 0, 10) - - require.Nil(t, appErr) + var posts *model.PostList + require.EventuallyWithT(t, func(c *assert.CollectT) { + posts, appErr = th.App.GetPosts(channel.Id, 0, 10) + assert.Nil(t, appErr) + }, 2*time.Second, 100*time.Millisecond) for _, postID := range posts.Order { post := posts.Posts[postID] diff --git a/server/channels/app/server_test.go b/server/channels/app/server_test.go index 7a858c68533..de4b00f93a6 100644 --- a/server/channels/app/server_test.go +++ b/server/channels/app/server_test.go @@ -458,7 +458,7 @@ func TestSentry(t *testing.T) { select { case <-data: require.Fail(t, "Sentry received a message, even though it's disabled!") - case <-time.After(time.Second): + case <-time.After(2 * time.Second): t.Log("Sentry request didn't arrive. Good!") } }) diff --git a/server/channels/jobs/schedulers_test.go b/server/channels/jobs/schedulers_test.go index cd3015937bb..076a8644221 100644 --- a/server/channels/jobs/schedulers_test.go +++ b/server/channels/jobs/schedulers_test.go @@ -69,7 +69,7 @@ func TestScheduler(t *testing.T) { t.Run("Base", func(t *testing.T) { jobServer.StartSchedulers() - time.Sleep(time.Second) + time.Sleep(2 * time.Second) jobServer.StopSchedulers() // They should be all on here @@ -81,7 +81,7 @@ func TestScheduler(t *testing.T) { t.Run("ClusterLeaderChanged", func(t *testing.T) { jobServer.initSchedulers() jobServer.StartSchedulers() - time.Sleep(time.Second) + time.Sleep(2 * time.Second) jobServer.HandleClusterLeaderChange(false) jobServer.StopSchedulers() // They should be turned off @@ -94,7 +94,7 @@ func TestScheduler(t *testing.T) { jobServer.initSchedulers() jobServer.HandleClusterLeaderChange(false) jobServer.StartSchedulers() - time.Sleep(time.Second) + time.Sleep(2 * time.Second) jobServer.StopSchedulers() for _, element := range jobServer.schedulers.nextRunTimes { assert.Nil(t, element) @@ -106,7 +106,7 @@ func TestScheduler(t *testing.T) { jobServer.HandleClusterLeaderChange(false) jobServer.HandleClusterLeaderChange(true) jobServer.StartSchedulers() - time.Sleep(time.Second) + time.Sleep(2 * time.Second) jobServer.StopSchedulers() for _, element := range jobServer.schedulers.nextRunTimes { assert.NotNil(t, element) @@ -116,7 +116,7 @@ func TestScheduler(t *testing.T) { t.Run("ConfigChanged", func(t *testing.T) { jobServer.initSchedulers() jobServer.StartSchedulers() - time.Sleep(time.Second) + time.Sleep(2 * time.Second) jobServer.HandleClusterLeaderChange(false) // After running a config change, they should stay off jobServer.schedulers.handleConfigChange(nil, nil) @@ -129,7 +129,7 @@ func TestScheduler(t *testing.T) { t.Run("ConfigChangedDeadlock", func(t *testing.T) { jobServer.initSchedulers() jobServer.StartSchedulers() - time.Sleep(time.Second) + time.Sleep(2 * time.Second) var wg sync.WaitGroup wg.Add(2) diff --git a/server/platform/services/telemetry/telemetry_test.go b/server/platform/services/telemetry/telemetry_test.go index 17a9b774c1a..e846a7743aa 100644 --- a/server/platform/services/telemetry/telemetry_test.go +++ b/server/platform/services/telemetry/telemetry_test.go @@ -87,7 +87,7 @@ func collectBatches(t *testing.T, info *[]testBatch, pchan chan testTelemetryPay case result := <-pchan: assertPayload(t, result, "", nil) *info = append(*info, result.Batch[0]) - case <-time.After(time.Second * 1): + case <-time.After(2 * time.Second): return } } @@ -127,7 +127,7 @@ func makeTelemetryServiceAndReceiver(t *testing.T, cloudLicense bool) (*Telemetr select { case identifyMessage := <-pchan: assertPayload(t, identifyMessage, "", nil) - case <-time.After(time.Second * 1): + case <-time.After(2 * time.Second): require.Fail(t, "Did not receive ID message") } @@ -437,7 +437,7 @@ func TestRudderTelemetry(t *testing.T) { case result := <-pchan: assertPayload(t, result, "", nil) *info = append(*info, result.Batch[0].Event) - case <-time.After(time.Second * 1): + case <-time.After(2 * time.Second): return } } @@ -453,7 +453,7 @@ func TestRudderTelemetry(t *testing.T) { assertPayload(t, result, "Testing Telemetry", map[string]any{ "hey": testValue, }) - case <-time.After(time.Second * 1): + case <-time.After(2 * time.Second): require.Fail(t, "Did not receive telemetry") } }) @@ -583,7 +583,7 @@ func TestRudderTelemetry(t *testing.T) { select { case <-pchan: require.Fail(t, "Should not send telemetry when the rudder key is not set") - case <-time.After(time.Second * 1): + case <-time.After(2 * time.Second): // Did not receive telemetry } }) @@ -621,7 +621,7 @@ func TestRudderTelemetry(t *testing.T) { select { case <-pchan: require.Fail(t, "Should not send telemetry when they are disabled") - case <-time.After(time.Second * 1): + case <-time.After(2 * time.Second): // Did not receive telemetry } }) diff --git a/server/public/pluginapi/cluster/mutex_test.go b/server/public/pluginapi/cluster/mutex_test.go index d415ee736bb..e118c114533 100644 --- a/server/public/pluginapi/cluster/mutex_test.go +++ b/server/public/pluginapi/cluster/mutex_test.go @@ -53,8 +53,8 @@ func lock(t *testing.T, m *Mutex) { }() select { - case <-time.After(1 * time.Second): - require.Fail(t, "failed to lock mutex within 1 second") + case <-time.After(2 * time.Second): + require.Fail(t, "failed to lock mutex within 2 seconds") case <-done: } } @@ -75,8 +75,8 @@ func unlock(t *testing.T, m *Mutex, panics bool) { }() select { - case <-time.After(1 * time.Second): - require.Fail(t, "failed to unlock mutex within 1 second") + case <-time.After(2 * time.Second): + require.Fail(t, "failed to unlock mutex within 2 seconds") case <-done: } } @@ -122,7 +122,7 @@ func TestMutex(t *testing.T) { }() select { - case <-time.After(1 * time.Second): + case <-time.After(2 * time.Second): case <-done: require.Fail(t, "second goroutine should not have locked") } diff --git a/server/public/pluginapi/kv_memory_test.go b/server/public/pluginapi/kv_memory_test.go index d77072d584e..12b131e0604 100644 --- a/server/public/pluginapi/kv_memory_test.go +++ b/server/public/pluginapi/kv_memory_test.go @@ -126,7 +126,7 @@ func TestMemoryStoreSet(t *testing.T) { assert.NoError(t, err) assert.True(t, ok) - time.Sleep(time.Second) + time.Sleep(2 * time.Second) isNil(t, &store, "key") }) @@ -461,7 +461,7 @@ func TestMemoryStoreDeleteAll(t *testing.T) { }) } -func isNil(t *testing.T, store *pluginapi.MemoryStore, key string) { +func isNil(t require.TestingT, store *pluginapi.MemoryStore, key string) { var out []byte err := store.Get(key, &out) require.NoError(t, err)