From 995a32aa8b6a4fba3bac2445318461ca607d0135 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Fri, 21 Apr 2023 14:03:48 +0000 Subject: [PATCH] test: Fix test timeouts due to contexts created too early --- coderd/workspacebuilds_test.go | 7 +++++-- enterprise/coderd/templates_test.go | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/coderd/workspacebuilds_test.go b/coderd/workspacebuilds_test.go index be91a94902b2a..48d02199b18bb 100644 --- a/coderd/workspacebuilds_test.go +++ b/coderd/workspacebuilds_test.go @@ -572,8 +572,7 @@ func TestWorkspaceBuildState(t *testing.T) { func TestWorkspaceBuildStatus(t *testing.T) { t.Parallel() - ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) - defer cancel() + auditor := audit.NewMock() numLogs := len(auditor.AuditLogs()) client, closeDaemon, api := coderdtest.NewWithAPI(t, &coderdtest.Options{IncludeProvisionerDaemon: true, Auditor: auditor}) @@ -597,6 +596,10 @@ func TestWorkspaceBuildStatus(t *testing.T) { closeDaemon = coderdtest.NewProvisionerDaemon(t, api) // after successful build is "running" _ = coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID) + + ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) + defer cancel() + workspace, err := client.Workspace(ctx, workspace.ID) require.NoError(t, err) require.EqualValues(t, codersdk.WorkspaceStatusRunning, workspace.LatestBuild.Status) diff --git a/enterprise/coderd/templates_test.go b/enterprise/coderd/templates_test.go index 948c5bf102f39..ca63cbc0801d1 100644 --- a/enterprise/coderd/templates_test.go +++ b/enterprise/coderd/templates_test.go @@ -980,7 +980,6 @@ func TestReadFileWithTemplateUpdate(t *testing.T) { t.Parallel() t.Run("HasTemplateUpdate", func(t *testing.T) { t.Parallel() - ctx := testutil.Context(t, testutil.WaitMedium) // Upload a file client := coderdenttest.New(t, nil) @@ -991,6 +990,8 @@ func TestReadFileWithTemplateUpdate(t *testing.T) { }, }) + ctx := testutil.Context(t, testutil.WaitLong) + resp, err := client.Upload(ctx, codersdk.ContentTypeTar, bytes.NewReader(make([]byte, 1024))) require.NoError(t, err)