From 8d5248bee605aa75b5053e6791e4f2a878072819 Mon Sep 17 00:00:00 2001 From: nickajacks1 <128185314+nickajacks1@users.noreply.github.com> Date: Mon, 27 Nov 2023 05:38:31 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A8=20Test:=20race=20in=20session=20mi?= =?UTF-8?q?ddleware=20tests=20(#2740)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A Session must not be accessed after Save() is called, but a unit test calls Session.ID() after Session.Save(), sometimes causing the test to fail when -race is enabled. The assertions that ID() was being used in were redundant with the previous two assertions (checking that the session name header is empty), so we can just remove the offending code. --- middleware/session/session_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/middleware/session/session_test.go b/middleware/session/session_test.go index 5fdad004..788a3c82 100644 --- a/middleware/session/session_test.go +++ b/middleware/session/session_test.go @@ -503,6 +503,7 @@ func Test_Session_Reset(t *testing.T) { utils.AssertEqual(t, nil, err) utils.AssertEqual(t, false, acquiredSession.ID() == originalSessionUUIDString) + utils.AssertEqual(t, false, acquiredSession.ID() == "") // acquiredSession.fresh should be true after resetting utils.AssertEqual(t, true, acquiredSession.Fresh()) @@ -523,10 +524,6 @@ func Test_Session_Reset(t *testing.T) { // Check that the session id is not in the header or cookie anymore utils.AssertEqual(t, "", string(ctx.Response().Header.Peek(store.sessionName))) utils.AssertEqual(t, "", string(ctx.Request().Header.Peek(store.sessionName))) - - // But the new session id should be in the header or cookie - utils.AssertEqual(t, acquiredSession.ID(), string(ctx.Response().Header.Peek(store.sessionName))) - utils.AssertEqual(t, acquiredSession.ID(), string(ctx.Request().Header.Peek(store.sessionName))) }) }