mirror of
https://github.com/we-promise/sure.git
synced 2026-09-05 14:51:15 +00:00
Fix flaky sign_out teardown in six test suites (#3208)
Six suites (passkey, MFA, SnapTrade, categorize, onboarding and the Active Storage authorization integration tests) share a sign_out helper that deletes the user's sessions through the controller, one HTTP request per session, iterating in unspecified order. The moment the loop deletes the session the test itself is signed in with, every later request in the loop is unauthenticated and silently deletes nothing, so whichever sessions happen to sort after it survive. The sessions fixture belongs to the same user these suites use, so a surviving fixture row then fails every assertion that expects the user to have no sessions. Row order usually favors the fixture, which is why the suites usually pass. Under parallel CI they fail a few times a week, always in this file family, always with the fixture session as the leftover. Forcing newest-first order reproduces it deterministically on current main: ten of the fifteen passkey tests fail. Teardown hygiene is not the behavior under test, so the helpers now destroy the sessions directly, which no order can break. All six suites run green three times in a row.
This commit is contained in:
@@ -8,9 +8,12 @@ class MfaControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
def sign_out
|
||||
@user.sessions.each do |session|
|
||||
delete session_path(session)
|
||||
end
|
||||
# Deleting sessions through the controller de-authenticates the request the
|
||||
# moment our own session dies, so every later delete in the loop is a
|
||||
# silent no-op and whichever sessions sort after it survive. The order is
|
||||
# unspecified, which made every suite that signs out this way flaky.
|
||||
# Teardown hygiene is not the behavior under test, so destroy directly.
|
||||
@user.sessions.destroy_all
|
||||
end
|
||||
|
||||
test "redirects to root if MFA already enabled" do
|
||||
|
||||
Reference in New Issue
Block a user