From 42e2a4150c419ec1b2656b25e32f6c2de0c99836 Mon Sep 17 00:00:00 2001 From: Vincent Vielle Date: Tue, 15 Oct 2024 16:30:38 +0200 Subject: [PATCH] fix(coderd): improve workspace tests (#15069) With [a recent PR](https://github.com/coder/coder/pull/14923) we introduced [new tests](https://github.com/coder/coder/pull/14923/files#diff-81081239b93aaa61eb8d180a5f9870fda8f0ab5cb4c6727d9d1636aa933e597b) that - while running in parallel to the existing ones - are failing. This PR is a quick proposal to fix it - tested in local and in the CI to unblock the situation. We can ignore it to work on a longer term solution if preferred. --- coderd/workspacebuilds_test.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/coderd/workspacebuilds_test.go b/coderd/workspacebuilds_test.go index 87c0dfe6b4..ec20556a7b 100644 --- a/coderd/workspacebuilds_test.go +++ b/coderd/workspacebuilds_test.go @@ -1183,9 +1183,8 @@ func TestPostWorkspaceBuild(t *testing.T) { }) } +//nolint:paralleltest func TestWorkspaceBuildTimings(t *testing.T) { - t.Parallel() - // Setup the test environment with a template and version db, pubsub := dbtestutil.NewDB(t) client := coderdtest.New(t, &coderdtest.Options{ @@ -1238,9 +1237,8 @@ func TestWorkspaceBuildTimings(t *testing.T) { }) } + //nolint:paralleltest t.Run("NonExistentBuild", func(t *testing.T) { - t.Parallel() - // When: fetching an inexistent build buildID := uuid.New() ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) @@ -1252,9 +1250,8 @@ func TestWorkspaceBuildTimings(t *testing.T) { require.Contains(t, err.Error(), "not found") }) + //nolint:paralleltest t.Run("EmptyTimings", func(t *testing.T) { - t.Parallel() - // When: fetching timings for a build with no timings build := makeBuild() ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) @@ -1267,9 +1264,8 @@ func TestWorkspaceBuildTimings(t *testing.T) { require.Empty(t, res.AgentScriptTimings) }) + //nolint:paralleltest t.Run("ProvisionerTimings", func(t *testing.T) { - t.Parallel() - // When: fetching timings for a build with provisioner timings build := makeBuild() provisionerTimings := dbgen.ProvisionerJobTimings(t, db, build, 5) @@ -1294,9 +1290,8 @@ func TestWorkspaceBuildTimings(t *testing.T) { } }) + //nolint:paralleltest t.Run("AgentScriptTimings", func(t *testing.T) { - t.Parallel() - // When: fetching timings for a build with agent script timings build := makeBuild() resource := dbgen.WorkspaceResource(t, db, database.WorkspaceResource{ @@ -1328,9 +1323,8 @@ func TestWorkspaceBuildTimings(t *testing.T) { } }) + //nolint:paralleltest t.Run("NoAgentScripts", func(t *testing.T) { - t.Parallel() - // When: fetching timings for a build with no agent scripts build := makeBuild() resource := dbgen.WorkspaceResource(t, db, database.WorkspaceResource{ @@ -1349,9 +1343,8 @@ func TestWorkspaceBuildTimings(t *testing.T) { }) // Some workspaces might not have agents. It is improbable, but possible. + //nolint:paralleltest t.Run("NoAgents", func(t *testing.T) { - t.Parallel() - // When: fetching timings for a build with no agents build := makeBuild() dbgen.WorkspaceResource(t, db, database.WorkspaceResource{ @@ -1359,6 +1352,7 @@ func TestWorkspaceBuildTimings(t *testing.T) { }) // Then: return a response with empty agent script timings + // trigger build ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) t.Cleanup(cancel) res, err := client.WorkspaceBuildTimings(ctx, build.ID)