Skip to content

Commit b0bc897

Browse files
committed
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.
1 parent 9acf6ac commit b0bc897

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

coderd/activitybump_test.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ func TestWorkspaceActivityBump(t *testing.T) {
125125
}
126126

127127
var updatedAfter time.Time
128+
// waitedFor is purely for debugging failed tests. If a test fails,
129+
// it helps to know how long it took for the deadline bump to be
130+
// detected. The longer this takes, the more likely time drift will
131+
// affect the results.
132+
waitedFor := time.Now()
133+
// lastChecked is for logging within the Eventually loop.
134+
// Debouncing log lines to every second to prevent spam.
135+
lastChecked := time.Now()
136+
128137
// The Deadline bump occurs asynchronously.
129138
require.Eventuallyf(t,
130139
func() bool {
@@ -133,14 +142,25 @@ func TestWorkspaceActivityBump(t *testing.T) {
133142
updatedAfter = dbtime.Now()
134143
if workspace.LatestBuild.Deadline.Time.Equal(firstDeadline) {
135144
updatedAfter = time.Now()
145+
if time.Since(lastChecked) > time.Second {
146+
t.Logf("deadline still not updated, will continue to check: deadline=%v", workspace.LatestBuild.Deadline.Time)
147+
lastChecked = time.Now()
148+
}
136149
return false
137150
}
138151
return true
139152
},
140-
testutil.WaitLong, testutil.IntervalFast,
153+
testutil.WaitMedium, testutil.IntervalFast,
141154
"deadline %v never updated", firstDeadline,
142155
)
143156

157+
// This log line helps establish how long it took for the deadline
158+
// to be detected as bumped.
159+
t.Logf("deadline bump detected: %v, waited for %s",
160+
workspace.LatestBuild.Deadline.Time,
161+
time.Since(waitedFor),
162+
)
163+
144164
require.Greater(t, workspace.LatestBuild.Deadline.Time, updatedAfter)
145165

146166
// If the workspace has a max deadline, the deadline must not exceed
@@ -156,7 +176,7 @@ func TestWorkspaceActivityBump(t *testing.T) {
156176
firstDeadline, workspace.LatestBuild.Deadline.Time, now,
157177
now.Sub(workspace.LatestBuild.Deadline.Time),
158178
)
159-
require.WithinDuration(t, dbtime.Now().Add(ttl), workspace.LatestBuild.Deadline.Time, testutil.WaitShort)
179+
require.WithinDuration(t, now.Add(ttl), workspace.LatestBuild.Deadline.Time, testutil.WaitShort)
160180
}
161181
}
162182

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy