🚨 Test: race in session middleware tests (#2740)

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.
pull/2744/head
nickajacks1 2023-11-27 05:38:31 -08:00 committed by GitHub
parent 28be17f929
commit 8d5248bee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 4 deletions

View File

@ -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)))
})
}