Skip to content

feat(coderd/database/dbtestutil): set default database timezone to non-UTC in unit tests #9672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Sep 15, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
replace conditional sleep with a slower unconditional sleep that shou…
…ld hopefully be greater than win32 max timer resolution
  • Loading branch information
johnstcn committed Sep 14, 2023
commit f18c6b503448e9ae5d5d761375b9bba54ece2e55
14 changes: 4 additions & 10 deletions coderd/activitybump_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package coderd

import (
"database/sql"
"runtime"
"testing"
"time"

Expand Down Expand Up @@ -188,7 +187,10 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
require.Equal(t, maxDeadline.UTC(), bld.MaxDeadline.UTC(), "unexpected max deadline before bump")
require.Equal(t, tt.workspaceTTL, time.Duration(ws.Ttl.Int64), "unexpected workspace TTL before bump")

workaroundWindowsTimeResolution(t)
// Wait a bit before bumping as dbtime is rounded to the nearest millisecond.
// This should also hopefully be enough for Windows time resolution to register
// a tick (win32 max timer resolution is apparently between 0.5 and 15.6ms)
<-time.After(testutil.IntervalFast)

// Bump duration is measured from the time of the bump, so we measure from here.
start := dbtime.Now()
Expand Down Expand Up @@ -237,11 +239,3 @@ func insertPrevWorkspaceBuild(t *testing.T, db database.Store, orgID, tvID, work
Transition: transition,
})
}

func workaroundWindowsTimeResolution(t *testing.T) {
t.Helper()
if runtime.GOOS == "windows" {
t.Logf("workaround: sleeping for a short time to avoid time resolution issues on Windows")
<-time.After(testutil.IntervalSlow)
}
}