From f1ddeec2f6101d34a2ca19cfb884607c03a5a3df Mon Sep 17 00:00:00 2001 From: Ben Schumacher Date: Tue, 29 Apr 2025 10:23:53 +0200 Subject: [PATCH] [MM-61778] Fix errcheck issues in web_hub_test.go (#30676) Co-authored-by: Claude --- server/.golangci.yml | 1 - server/channels/app/platform/web_hub_test.go | 79 +++++++++++++------- 2 files changed, 53 insertions(+), 27 deletions(-) diff --git a/server/.golangci.yml b/server/.golangci.yml index 8575d37ee0..52a52f5959 100644 --- a/server/.golangci.yml +++ b/server/.golangci.yml @@ -98,7 +98,6 @@ issues: channels/app/platform/license.go|\ channels/app/platform/session.go|\ channels/app/platform/status.go|\ - channels/app/platform/web_hub_test.go|\ channels/app/slashcommands/command_test.go|\ channels/app/slashcommands/helper_test.go|\ channels/app/team_test.go|\ diff --git a/server/channels/app/platform/web_hub_test.go b/server/channels/app/platform/web_hub_test.go index bd931646db..d3512b5600 100644 --- a/server/channels/app/platform/web_hub_test.go +++ b/server/channels/app/platform/web_hub_test.go @@ -69,7 +69,8 @@ func TestHubStopWithMultipleConnections(t *testing.T) { }) require.NoError(t, err) - th.Service.Start(nil) + err = th.Service.Start(nil) + require.NoError(t, err) wc1 := registerDummyWebConn(t, th, s.Listener.Addr(), session) wc2 := registerDummyWebConn(t, th, s.Listener.Addr(), session) wc3 := registerDummyWebConn(t, th, s.Listener.Addr(), session) @@ -93,7 +94,8 @@ func TestHubStopRaceCondition(t *testing.T) { }) require.NoError(t, err) - th.Service.Start(nil) + err = th.Service.Start(nil) + require.NoError(t, err) wc1 := registerDummyWebConn(t, th, s.Listener.Addr(), session) defer wc1.Close() @@ -237,10 +239,14 @@ func TestHubConnIndex(t *testing.T) { wc4.SetConnectionID(model.NewId()) wc4.SetSession(&model.Session{}) - connIndex.Add(wc1) - connIndex.Add(wc2) - connIndex.Add(wc3) - connIndex.Add(wc4) + errAdd := connIndex.Add(wc1) + require.NoError(t, errAdd) + err = connIndex.Add(wc2) + require.NoError(t, err) + err = connIndex.Add(wc3) + require.NoError(t, err) + err = connIndex.Add(wc4) + require.NoError(t, err) t.Run("Basic", func(t *testing.T) { assert.True(t, connIndex.Has(wc1)) @@ -327,8 +333,10 @@ func TestHubConnIndex(t *testing.T) { }) t.Run("adding", func(t *testing.T) { - connIndex.Add(wc1) - connIndex.Add(wc3) + err = connIndex.Add(wc1) + require.NoError(t, err) + err = connIndex.Add(wc3) + require.NoError(t, err) assert.Len(t, connIndex.byConnectionId, 2) assert.Equal(t, wc1, connIndex.ForConnection(wc1ID)) @@ -380,9 +388,12 @@ func TestHubConnIndex(t *testing.T) { wc3.SetConnectionID(wc3ID) wc3.SetSession(&model.Session{}) - connIndex.Add(wc1) - connIndex.Add(wc2) - connIndex.Add(wc3) + err = connIndex.Add(wc1) + require.NoError(t, err) + err = connIndex.Add(wc2) + require.NoError(t, err) + err = connIndex.Add(wc3) + require.NoError(t, err) t.Run("ForChannel", func(t *testing.T) { require.Len(t, connIndex.byChannelID, 1) @@ -450,9 +461,12 @@ func TestHubConnIndexIncorrectRemoval(t *testing.T) { wc4.SetConnectionID("last") wc4.SetSession(&model.Session{}) - connIndex.Add(wc2) - connIndex.Add(wc3) - connIndex.Add(wc4) + err := connIndex.Add(wc2) + require.NoError(t, err) + err = connIndex.Add(wc3) + require.NoError(t, err) + err = connIndex.Add(wc4) + require.NoError(t, err) for _, wc := range connIndex.ForUser(wc2.UserId) { if !connIndex.Has(wc) { @@ -498,9 +512,12 @@ func TestHubConnIndexInactive(t *testing.T) { wc3.SetConnectionID("conn3") wc3.SetSession(&model.Session{}) - connIndex.Add(wc1) - connIndex.Add(wc2) - connIndex.Add(wc3) + err := connIndex.Add(wc1) + require.NoError(t, err) + err = connIndex.Add(wc2) + require.NoError(t, err) + err = connIndex.Add(wc3) + require.NoError(t, err) assert.Nil(t, connIndex.RemoveInactiveByConnectionID(wc2.UserId, "conn2")) assert.Equal(t, connIndex.ForUserActiveCount(wc2.UserId), 1) @@ -511,7 +528,8 @@ func TestHubConnIndexInactive(t *testing.T) { assert.Len(t, connIndex.ForUser(wc2.UserId), 1) wc3.lastUserActivityAt = model.GetMillis() - connIndex.Add(wc3) + err = connIndex.Add(wc3) + require.NoError(t, err) connIndex.RemoveInactiveConnections() assert.True(t, connIndex.Has(wc3)) assert.Len(t, connIndex.ForUser(wc2.UserId), 2) @@ -577,7 +595,8 @@ func TestHubIsRegistered(t *testing.T) { s := httptest.NewServer(dummyWebsocketHandler(t)) defer s.Close() - th.Service.Start(nil) + err = th.Service.Start(nil) + require.NoError(t, err) wc1 := registerDummyWebConn(t, th, s.Listener.Addr(), session) wc2 := registerDummyWebConn(t, th, s.Listener.Addr(), session) wc3 := registerDummyWebConn(t, th, s.Listener.Addr(), session) @@ -612,7 +631,8 @@ func TestHubWebConnCount(t *testing.T) { s := httptest.NewServer(dummyWebsocketHandler(t)) defer s.Close() - th.Service.Start(nil) + err = th.Service.Start(nil) + require.NoError(t, err) wc1 := registerDummyWebConn(t, th, s.Listener.Addr(), session) wc2 := registerDummyWebConn(t, th, s.Listener.Addr(), session) defer wc1.Close() @@ -648,8 +668,10 @@ func BenchmarkHubConnIndex(b *testing.B) { b.ResetTimer() b.Run("Add", func(b *testing.B) { for i := 0; i < b.N; i++ { - connIndex.Add(wc1) - connIndex.Add(wc2) + err := connIndex.Add(wc1) + require.NoError(b, err) + err = connIndex.Add(wc2) + require.NoError(b, err) b.StopTimer() connIndex.Remove(wc1) @@ -661,8 +683,11 @@ func BenchmarkHubConnIndex(b *testing.B) { b.Run("Remove", func(b *testing.B) { for i := 0; i < b.N; i++ { b.StopTimer() - connIndex.Add(wc1) - connIndex.Add(wc2) + err := connIndex.Add(wc1) + require.NoError(b, err) + err = connIndex.Add(wc2) + require.NoError(b, err) + b.Error(err) b.StartTimer() connIndex.Remove(wc1) @@ -690,7 +715,8 @@ func TestHubConnIndexRemoveMemLeak(t *testing.T) { close(ch) }) - connIndex.Add(wc) + err := connIndex.Add(wc) + require.NoError(t, err) connIndex.Remove(wc) runtime.GC() @@ -713,7 +739,8 @@ func BenchmarkGetHubForUserId(b *testing.B) { th := Setup(b).InitBasic() defer th.TearDown() - th.Service.Start(nil) + err := th.Service.Start(nil) + require.NoError(b, err) b.ResetTimer() for i := 0; i < b.N; i++ {