Skip to content

Fix flaky testUsernameStatistics timing assertion - #229

Open
codeling wants to merge 1 commit into
mainfrom
fix/flaky-username-statistics-test
Open

codeling wants to merge 1 commit into
mainfrom
fix/flaky-username-statistics-test

Conversation

@codeling

@codeling codeling commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Problem

DatabaseHelperTest::testUsernameStatistics failed intermittently in CI, with first_attempt off by one second (21:11:29 expected, 21:11:28 actual).

Cause

The failed-login timestamps are generated from time() when the rows are inserted. The assertions then compared them against a second time() reading taken at assertion time. If a second boundary passed between the two reads, the values differed by one second.

Fix

The test now records time() before and after the inserts. It asserts that the stored first_attempt and last_attempt fall within that window, shifted by 30 and 10 minutes. This holds no matter when the clock ticks over.

Only the test changes; there is no production code change.

Testing

I couldn't run PHPUnit in my environment, only a PHP syntax check (php -l). CI will run the full suite.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Qy73oCK2ZQyvqMP9DKoFkN


Generated by Claude Code

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qy73oCK2ZQyvqMP9DKoFkN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants