@@ -124,6 +124,10 @@ func TestWorkspaceActivityBump(t *testing.T) {
124124return
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+
127131var 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) {
132136waitedFor := 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.
138146require .Eventuallyf (t ,
139147func ()bool {
148+ checks ++
140149workspace ,err = client .Workspace (ctx ,workspace .ID )
141150require .NoError (t ,err )
142151updatedAfter = dbtime .Now ()
152+
143153if workspace .LatestBuild .Deadline .Time .Equal (firstDeadline ) {
144154updatedAfter = time .Now ()
145155if 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 )
147158lastChecked = time .Now ()
148159}
149160return false
150161}
151162return 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) {
176187firstDeadline ,workspace .LatestBuild .Deadline .Time ,now ,
177188now .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