Skip to content

Commit f1eec2d

Browse files
authored
fix(cli): scope context per subtest to fix flake test in prebuilt workspace delete (#18872)
## Description This PR fixes a flaky test in `TestDelete/Prebuilt_workspace_delete_permissions`: coder/internal#764 Previously, all subtests used the same context created at the top level. Since the subtests run in parallel, they could run for too long and cause the shared context to expire. This sometimes led to context deadline exceeded errors, especially during the `testutil.Eventually` check for running prebuilt workspaces. The fix is to create a fresh context per subtest, ensuring they are isolated and not prematurely cancelled due to other subtests' durations.
1 parent c643214 commit f1eec2d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

cli/delete_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,6 @@ func TestDelete(t *testing.T) {
233233
t.Skip("this test requires postgres")
234234
}
235235

236-
clock := quartz.NewMock(t)
237-
ctx := testutil.Context(t, testutil.WaitSuperLong)
238-
239236
// Setup
240237
db, pb := dbtestutil.NewDB(t, dbtestutil.WithDumpOnFailure())
241238
client, _ := coderdtest.NewWithProvisionerCloser(t, &coderdtest.Options{
@@ -301,6 +298,9 @@ func TestDelete(t *testing.T) {
301298
t.Run(tc.name, func(t *testing.T) {
302299
t.Parallel()
303300

301+
clock := quartz.NewMock(t)
302+
ctx := testutil.Context(t, testutil.WaitSuperLong)
303+
304304
// Create one prebuilt workspace (owned by system user) and one normal workspace (owned by a user)
305305
// Each workspace is persisted in the DB along with associated workspace jobs and builds.
306306
dbPrebuiltWorkspace := setupTestDBWorkspace(t, clock, db, pb, orgID, database.PrebuildsSystemUserID, template.ID, version.ID, preset.ID)

0 commit comments

Comments
 (0)