Skip to content

Commit 81b08ab

Browse files
committed
chore: include avg check time in eventually loop
If the hypothesis of a 10s time drift is true, this loop might be acting slow.
1 parent b0bc897 commit 81b08ab

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

coderd/activitybump_test.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ func TestWorkspaceActivityBump(t *testing.T) {
124124
return
125125
}
126126

127+
// maxTimeDrift is how long we are willing wait for a deadline to
128+
// be increased. Since it could have been bumped at the intial
129+
maxTimeDrift := testutil.WaitMedium
130+
127131
var updatedAfter time.Time
128132
// waitedFor is purely for debugging failed tests. If a test fails,
129133
// it helps to know how long it took for the deadline bump to be
@@ -132,25 +136,32 @@ func TestWorkspaceActivityBump(t *testing.T) {
132136
waitedFor := time.Now()
133137
// lastChecked is for logging within the Eventually loop.
134138
// Debouncing log lines to every second to prevent spam.
135-
lastChecked := time.Now()
139+
lastChecked := time.Time{}
140+
// checks is for keeping track of the average check time.
141+
// If CI is running slow, this could be useful to know checks
142+
// are taking longer than expected.
143+
checks := 0
136144

137145
// The Deadline bump occurs asynchronously.
138146
require.Eventuallyf(t,
139147
func() bool {
148+
checks++
140149
workspace, err = client.Workspace(ctx, workspace.ID)
141150
require.NoError(t, err)
142151
updatedAfter = dbtime.Now()
152+
143153
if workspace.LatestBuild.Deadline.Time.Equal(firstDeadline) {
144154
updatedAfter = time.Now()
145155
if time.Since(lastChecked) > time.Second {
146-
t.Logf("deadline still not updated, will continue to check: deadline=%v", workspace.LatestBuild.Deadline.Time)
156+
avgCheckTime := time.Since(waitedFor) / time.Duration(checks)
157+
t.Logf("deadline still not updated, will continue to check: avg_check_dur=%s checks=%d deadline=%v", avgCheckTime, checks, workspace.LatestBuild.Deadline.Time)
147158
lastChecked = time.Now()
148159
}
149160
return false
150161
}
151162
return true
152163
},
153-
testutil.WaitMedium, testutil.IntervalFast,
164+
maxTimeDrift, testutil.IntervalFast,
154165
"deadline %v never updated", firstDeadline,
155166
)
156167

@@ -176,7 +187,7 @@ func TestWorkspaceActivityBump(t *testing.T) {
176187
firstDeadline, workspace.LatestBuild.Deadline.Time, now,
177188
now.Sub(workspace.LatestBuild.Deadline.Time),
178189
)
179-
require.WithinDuration(t, now.Add(ttl), workspace.LatestBuild.Deadline.Time, testutil.WaitShort)
190+
require.WithinDuration(t, now.Add(ttl), workspace.LatestBuild.Deadline.Time, maxTimeDrift)
180191
}
181192
}
182193

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