From f15873eaf4ac7aa0e18be690a16f9c31fb16ad33 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Thu, 16 Jun 2022 14:17:01 +0530 Subject: [PATCH] MM-43871: Fix flaky TestCreatePostAsUser (#20484) We need to flush the logger before checking the log results. Without that, sometimes it would get logged after checking the line, as can be seen in the JIRA ticket. https://mattermost.atlassian.net/browse/MM-43871 ```release-note NONE ``` Co-authored-by: Mattermod --- app/post_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/post_test.go b/app/post_test.go index e3168a47c6..da87cc4539 100644 --- a/app/post_test.go +++ b/app/post_test.go @@ -1108,7 +1108,6 @@ func TestCreatePostAsUser(t *testing.T) { }) t.Run("logs warning for user not in channel", func(t *testing.T) { - t.Skip("MM-43871") th := Setup(t).InitBasic() defer th.TearDown() user := th.CreateUser() @@ -1123,6 +1122,8 @@ func TestCreatePostAsUser(t *testing.T) { _, appErr := th.App.CreatePostAsUser(th.Context, post, "", true) require.Nil(t, appErr) + require.NoError(t, th.TestLogger.Flush()) + testlib.AssertLog(t, th.LogBuffer, mlog.LvlWarn.Name, "Failed to get membership") }) @@ -1146,6 +1147,8 @@ func TestCreatePostAsUser(t *testing.T) { _, appErr = th.App.CreatePostAsUser(th.Context, post, "", true) require.Nil(t, appErr) + require.NoError(t, th.TestLogger.Flush()) + testlib.AssertNoLog(t, th.LogBuffer, mlog.LvlWarn.Name, "Failed to get membership") })