Skip to content

Commit ab15c66

Browse files
committed
Fix admin run status test timing
1 parent 164f824 commit ab15c66

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

admin_run_integration_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ func TestAdminRuns_List(t *testing.T) {
112112
require.NoError(t, err)
113113
require.NotEmpty(t, rl.Items)
114114

115-
assert.Equal(t, r1.Status, RunPlanning)
116115
assert.Equal(t, adminRunItemsContainsID(rl.Items, r1.ID), false)
117-
assert.Equal(t, r2.Status, RunPending)
118116
assert.Equal(t, adminRunItemsContainsID(rl.Items, r2.ID), true)
119117
})
120118

@@ -189,7 +187,10 @@ func TestAdminRuns_ForceCancel(t *testing.T) {
189187
t.Run("with can force cancel", func(t *testing.T) {
190188
rTestPlanning, err := client.Runs.Read(ctx, rTest1.ID)
191189
require.NoError(t, err)
192-
assert.Equal(t, RunPlanning, rTestPlanning.Status)
190+
191+
ctxPollRunStatus, cancelPollPlanned := context.WithTimeout(ctx, 2*time.Minute)
192+
defer cancelPollPlanned()
193+
pollRunStatus(t, client, ctxPollRunStatus, rTestPlanning, []RunStatus{RunPlanning, RunPlanned, RunCostEstimated})
193194

194195
require.NotNil(t, rTestPlanning.Actions)
195196
require.NotNil(t, rTestPlanning.Permissions)
@@ -198,7 +199,8 @@ func TestAdminRuns_ForceCancel(t *testing.T) {
198199

199200
rTestPending, err := client.Runs.Read(ctx, rTest2.ID)
200201
require.NoError(t, err)
201-
assert.Equal(t, RunPending, rTestPending.Status)
202+
203+
pollRunStatus(t, client, ctxPollRunStatus, rTest2, []RunStatus{RunPending})
202204

203205
require.NotNil(t, rTestPlanning.Actions)
204206
require.NotNil(t, rTestPlanning.Permissions)
@@ -240,15 +242,23 @@ func TestAdminRuns_ListFilterByDates(t *testing.T) {
240242
defer wTestCleanup()
241243

242244
timestamp1 := time.Now().Format(time.RFC3339)
245+
// Sleeping helps ensure that the timestamps on client and server don't
246+
// need to be exactly in sync
247+
time.Sleep(2 * time.Second)
248+
243249
rTest1, rCleanup1 := createRun(t, client, wTest)
244250
defer rCleanup1()
245251

246252
rTest2, rCleanup2 := createRun(t, client, wTest)
247253
defer rCleanup2()
254+
255+
time.Sleep(2 * time.Second)
248256
timestamp2 := time.Now().Format(time.RFC3339)
249257

250258
_, rCleanup3 := createRun(t, client, wTest)
251259
defer rCleanup3()
260+
261+
time.Sleep(2 * time.Second)
252262
timestamp3 := time.Now().Format(time.RFC3339)
253263

254264
t.Run("has valid date ranges", func(t *testing.T) {

0 commit comments

Comments
 (0)