@@ -124,6 +124,10 @@ func TestWorkspaceActivityBump(t *testing.T) {
124
124
return
125
125
}
126
126
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
+
127
131
var updatedAfter time.Time
128
132
// waitedFor is purely for debugging failed tests. If a test fails,
129
133
// it helps to know how long it took for the deadline bump to be
@@ -132,25 +136,32 @@ func TestWorkspaceActivityBump(t *testing.T) {
132
136
waitedFor := time .Now ()
133
137
// lastChecked is for logging within the Eventually loop.
134
138
// 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
136
144
137
145
// The Deadline bump occurs asynchronously.
138
146
require .Eventuallyf (t ,
139
147
func () bool {
148
+ checks ++
140
149
workspace , err = client .Workspace (ctx , workspace .ID )
141
150
require .NoError (t , err )
142
151
updatedAfter = dbtime .Now ()
152
+
143
153
if workspace .LatestBuild .Deadline .Time .Equal (firstDeadline ) {
144
154
updatedAfter = time .Now ()
145
155
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 )
147
158
lastChecked = time .Now ()
148
159
}
149
160
return false
150
161
}
151
162
return true
152
163
},
153
- testutil . WaitMedium , testutil .IntervalFast ,
164
+ maxTimeDrift , testutil .IntervalFast ,
154
165
"deadline %v never updated" , firstDeadline ,
155
166
)
156
167
@@ -176,7 +187,7 @@ func TestWorkspaceActivityBump(t *testing.T) {
176
187
firstDeadline , workspace .LatestBuild .Deadline .Time , now ,
177
188
now .Sub (workspace .LatestBuild .Deadline .Time ),
178
189
)
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 )
180
191
}
181
192
}
182
193
0 commit comments