Skip to content

Commit 7f25f24

Browse files
refactor: don't fail test in a goroutine
1 parent 9f66169 commit 7f25f24

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

enterprise/coderd/prebuilds/claim_test.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ func TestClaimPrebuild(t *testing.T) {
175175
runningPrebuilds := make(map[uuid.UUID]database.GetRunningPrebuiltWorkspacesRow, desiredInstances*presetCount)
176176
require.Eventually(t, func() bool {
177177
rows, err := spy.GetRunningPrebuiltWorkspaces(ctx)
178-
require.NoError(t, err)
178+
if err != nil {
179+
return false
180+
}
179181

180182
for _, row := range rows {
181183
runningPrebuilds[row.CurrentPresetID.UUID] = row
@@ -185,16 +187,21 @@ func TestClaimPrebuild(t *testing.T) {
185187
}
186188

187189
agents, err := db.GetWorkspaceAgentsInLatestBuildByWorkspaceID(ctx, row.ID)
188-
require.NoError(t, err)
190+
if err != nil {
191+
return false
192+
}
189193

190194
// Workspaces are eligible once its agent is marked "ready".
191195
for _, agent := range agents {
192-
require.NoError(t, db.UpdateWorkspaceAgentLifecycleStateByID(ctx, database.UpdateWorkspaceAgentLifecycleStateByIDParams{
196+
err = db.UpdateWorkspaceAgentLifecycleStateByID(ctx, database.UpdateWorkspaceAgentLifecycleStateByIDParams{
193197
ID: agent.ID,
194198
LifecycleState: database.WorkspaceAgentLifecycleStateReady,
195199
StartedAt: sql.NullTime{Time: time.Now().Add(time.Hour), Valid: true},
196200
ReadyAt: sql.NullTime{Time: time.Now().Add(-1 * time.Hour), Valid: true},
197-
}))
201+
})
202+
if err != nil {
203+
return false
204+
}
198205
}
199206
}
200207

@@ -270,7 +277,9 @@ func TestClaimPrebuild(t *testing.T) {
270277

271278
require.Eventually(t, func() bool {
272279
rows, err := spy.GetRunningPrebuiltWorkspaces(ctx)
273-
require.NoError(t, err)
280+
if err != nil {
281+
return false
282+
}
274283

275284
t.Logf("found %d running prebuilds so far, want %d", len(rows), expectedPrebuildsCount)
276285

@@ -447,22 +456,29 @@ func TestClaimPrebuild_CheckDifferentErrors(t *testing.T) {
447456
runningPrebuilds := make(map[uuid.UUID]database.GetRunningPrebuiltWorkspacesRow, desiredInstances*presetCount)
448457
require.Eventually(t, func() bool {
449458
rows, err := errorStore.GetRunningPrebuiltWorkspaces(ctx)
450-
require.NoError(t, err)
459+
if err != nil {
460+
return false
461+
}
451462

452463
for _, row := range rows {
453464
runningPrebuilds[row.CurrentPresetID.UUID] = row
454465

455466
agents, err := db.GetWorkspaceAgentsInLatestBuildByWorkspaceID(ctx, row.ID)
456-
require.NoError(t, err)
467+
if err != nil {
468+
return false
469+
}
457470

458471
// Workspaces are eligible once its agent is marked "ready".
459472
for _, agent := range agents {
460-
require.NoError(t, db.UpdateWorkspaceAgentLifecycleStateByID(ctx, database.UpdateWorkspaceAgentLifecycleStateByIDParams{
473+
err = db.UpdateWorkspaceAgentLifecycleStateByID(ctx, database.UpdateWorkspaceAgentLifecycleStateByIDParams{
461474
ID: agent.ID,
462475
LifecycleState: database.WorkspaceAgentLifecycleStateReady,
463476
StartedAt: sql.NullTime{Time: time.Now().Add(time.Hour), Valid: true},
464477
ReadyAt: sql.NullTime{Time: time.Now().Add(-1 * time.Hour), Valid: true},
465-
}))
478+
})
479+
if err != nil {
480+
return false
481+
}
466482
}
467483
}
468484

0 commit comments

Comments
 (0)