Skip to content
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
Next Next commit
chore: add log statements to detect a slow test check
If a test is running slow, the workspace deadline check can be
slow. Since we use 'now' as a reference point, any time drift
will affect the results.
  • Loading branch information
Emyrk committed Oct 15, 2024
commit b0bc897773f08c6145b6295caad73edf2b3870e4
24 changes: 22 additions & 2 deletions coderd/activitybump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ func TestWorkspaceActivityBump(t *testing.T) {
}

var updatedAfter time.Time
// waitedFor is purely for debugging failed tests. If a test fails,
// it helps to know how long it took for the deadline bump to be
// detected. The longer this takes, the more likely time drift will
// affect the results.
waitedFor := time.Now()
// lastChecked is for logging within the Eventually loop.
// Debouncing log lines to every second to prevent spam.
lastChecked := time.Now()

// The Deadline bump occurs asynchronously.
require.Eventuallyf(t,
func() bool {
Expand All @@ -133,14 +142,25 @@ func TestWorkspaceActivityBump(t *testing.T) {
updatedAfter = dbtime.Now()
if workspace.LatestBuild.Deadline.Time.Equal(firstDeadline) {
updatedAfter = time.Now()
if time.Since(lastChecked) > time.Second {
t.Logf("deadline still not updated, will continue to check: deadline=%v", workspace.LatestBuild.Deadline.Time)
lastChecked = time.Now()
}
return false
}
return true
},
testutil.WaitLong, testutil.IntervalFast,
testutil.WaitMedium, testutil.IntervalFast,
"deadline %v never updated", firstDeadline,
)

// This log line helps establish how long it took for the deadline
// to be detected as bumped.
t.Logf("deadline bump detected: %v, waited for %s",
workspace.LatestBuild.Deadline.Time,
time.Since(waitedFor),
)

require.Greater(t, workspace.LatestBuild.Deadline.Time, updatedAfter)

// If the workspace has a max deadline, the deadline must not exceed
Expand All @@ -156,7 +176,7 @@ func TestWorkspaceActivityBump(t *testing.T) {
firstDeadline, workspace.LatestBuild.Deadline.Time, now,
now.Sub(workspace.LatestBuild.Deadline.Time),
)
require.WithinDuration(t, dbtime.Now().Add(ttl), workspace.LatestBuild.Deadline.Time, testutil.WaitShort)
require.WithinDuration(t, now.Add(ttl), workspace.LatestBuild.Deadline.Time, testutil.WaitShort)
}
}

Expand Down
Loading