mirror of
https://github.com/coder/coder.git
synced 2026-06-07 06:58:17 +00:00
d50fc374c5
## Problem `TestGetUserStatusCounts/OK_when_offset_is_provided_without_timezone` fails intermittently in CI: ``` Error: Should be zero, but was 1 Test: TestGetUserStatusCounts/OK_when_offset_is_provided_without_timezone ``` ## Root Cause The `happyResponseCheck` asserts `count=0` for all 61 dates. The test creates a first user, which inserts a `user_status_changes` row with `new_status=active` and `changed_at=now()`. The query computes its date range using the requested timezone/offset: ```go nextHourInLoc = dbtime.Now().Truncate(time.Hour).Add(time.Hour).In(loc) sixtyDaysAgo = dbtime.StartOfDay(nextHourInLoc).AddDate(0, 0, -60) ``` When the UTC time of day is earlier than the timezone offset (e.g. UTC 01:30 with offset `-2` means local time is 23:30 previous day), `StartOfDay(nextHourInLoc)` rounds forward to start-of-today in the target timezone, which is *after* the current UTC time. The last `date_of_interest` in the SQL query ends up ahead of `now()` in UTC, so the user's `changed_at` satisfies `changed_at <= date` — producing `count=1` on the last date. This happens ~8% of the time for offset `-2` (when UTC hour is 0 or 1) and ~15% for `America/St_Johns` (UTC-3:30). ## Fix Allow the last date entry to have count 0 or 1 (only 1 user exists) while keeping all earlier dates strictly zero. This correctly accounts for the timezone boundary without weakening the test's structural validation.