From d20dbc3b88b1347b4a016be5c0dc924d32291794 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Thu, 12 Dec 2024 18:55:44 +0530 Subject: [PATCH] MM-61698: Fix TestWebHubCloseConnOnDBFail properly (#29577) Finally I figured out why the log message for /api/v4/websocket does not appear. It is because the log gets generated only when the request returns, and for websockets, the request doesn't return until the client closes. And because we were closing the client in a defer clause, the flushing of the logger would happen before closing the client, therefore leading to a race condition of the log not appearing from time to time. https://mattermost.atlassian.net/browse/MM-61698 ```release-note NONE ``` --- server/channels/api4/post_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/channels/api4/post_test.go b/server/channels/api4/post_test.go index 0603a55dc4..3cc142bf29 100644 --- a/server/channels/api4/post_test.go +++ b/server/channels/api4/post_test.go @@ -3147,7 +3147,7 @@ func TestWebHubCloseConnOnDBFail(t *testing.T) { wsClient, err := th.CreateWebSocketClientWithClient(cli) require.NoError(t, err) - defer wsClient.Close() + wsClient.Close() require.NoError(t, th.TestLogger.Flush()) }