Skip to content

Commit 88f0131

Browse files
fix: use dbtime in dbmem query to fix flake (#16773)
Closes coder/internal#447. The test was failing 30% of the time on Windows without the rounding applied by `dbtime`. `dbtime` was used on the timestamps inserted into the DB, but not within the query. Once using `dbtime` within the query there were no failures in 200 runs.
1 parent 0f4f6bd commit 88f0131

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

coderd/database/dbmem/dbmem.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7014,7 +7014,7 @@ func (q *FakeQuerier) GetWorkspaceAgentUsageStatsAndLabels(_ context.Context, cr
70147014
}
70157015
// WHERE usage = true AND created_at > now() - '1 minute'::interval
70167016
// GROUP BY user_id, agent_id, workspace_id
7017-
if agentStat.Usage && agentStat.CreatedAt.After(time.Now().Add(-time.Minute)) {
7017+
if agentStat.Usage && agentStat.CreatedAt.After(dbtime.Now().Add(-time.Minute)) {
70187018
val, ok := latestAgentStats[key]
70197019
if !ok {
70207020
latestAgentStats[key] = agentStat

0 commit comments

Comments
 (0)