[PR #30] Fixing the Login Concurrency Test That Sometimes Failed
- What changed: A login test that sometimes failed was fixed. The test relied on execution order, not the server.
- Decision: The test was changed so that it moves on only after both requests pass the lock check. Server code was not changed.
- Still unknown: Other tests that rely on order were not checked separately.
One login test failed sometimes. The code did not change, but the result differed from run to run. Tests like this are usually called flaky. PR #30 fixed that test. The server code was not changed.
What was done and why
- The failing test checked that after four wrong passwords, two more wrong passwords sent at the same time both return 401, and the next request returns 429 with a 120-second wait.
- When it failed, the two responses were
[401, 429]instead of[401, 401]. - The test assumed that both requests would pass the lock check. But one request finishes in about 50 ms. When the machine is busy from the full test run, one request can finish checking, comparing and recording its failure before the other request checks. By then the account is locked, so the second request gets 429.
- The server was not wrong. The test depended on timing.
- Claude made a temporary test to confirm the cause. It delayed the second request’s lock check until the first request’s failure record was saved. The result was
[401, 429]every time, which matched the guess. The temporary file was deleted after the check.
Options chosen and rejected
- Chosen: hold each request until both have passed the lock check. Inside the test, the lock-check function is wrapped. It runs the original check, then waits until both requests have passed before going on. This creates the situation the test name describes, every time. Six failures are recorded, so the next request correctly gets 429 and 120 seconds. This is the same approach as another delay test in the same file.
- Rejected: order-independent checks (each 401 or 429). If one request gets 429, only five failures are recorded and the next wait is 60 seconds. The final check would then vary by case, and the “two overlapping failures lead to 120 seconds” behavior would no longer be verified every time.
- The server code was not changed.
How it was checked
- This test alone was run 20 times in a row, and all 20 runs passed.
- The full check command (
npm run verify) passes. - ChatGPT (Codex, model gpt-6-luna) statically reviewed the same commit without running tests. The review said it was fine to merge. It also raised one low-severity gap: if one lock check throws an error, the other request can wait until the test times out. It does not pass silently, so it was not changed this time. Claude checked the points against the code, and they were correct.
- The review model is the same as in PR #28.
Lessons
- A test that sends requests “at the same time” does not guarantee that they overlap. When overlap is required, the order has to be forced with a signal.
- The situation the test name describes has to match the real conditions of the run. When they differ, the test fails only sometimes.