From 5db2d849c611be73e12927da8addb28dc31e111c Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Tue, 28 Jan 2025 13:20:30 +0000 Subject: [PATCH 1/2] chore(scaletest/createworkspaces): address context usage --- scaletest/createworkspaces/run_test.go | 59 ++++++++++++-------------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/scaletest/createworkspaces/run_test.go b/scaletest/createworkspaces/run_test.go index d1d4073a935fe..0c0f1a51d78b3 100644 --- a/scaletest/createworkspaces/run_test.go +++ b/scaletest/createworkspaces/run_test.go @@ -263,6 +263,7 @@ func Test_Runner(t *testing.T) { }() // Wait for the workspace build job to be picked up. + jobCh := make(chan codersdk.ProvisionerJob, 1) require.Eventually(t, func() bool { workspaces, err := client.Workspaces(ctx, codersdk.WorkspaceFilter{}) if err != nil { @@ -273,23 +274,32 @@ func Test_Runner(t *testing.T) { } ws := workspaces.Workspaces[0] - t.Logf("checking build: %s | %s", ws.LatestBuild.Transition, ws.LatestBuild.Job.Status) + t.Logf("checking build: %s | %s | %s", ws.ID, ws.LatestBuild.Transition, ws.LatestBuild.Job.Status) // There should be only one build at present. if ws.LatestBuild.Transition != codersdk.WorkspaceTransitionStart { t.Errorf("expected build transition %s, got %s", codersdk.WorkspaceTransitionStart, ws.LatestBuild.Transition) return false } - return ws.LatestBuild.Job.Status == codersdk.ProvisionerJobRunning - }, testutil.WaitShort, testutil.IntervalMedium) + if ws.LatestBuild.Job.Status != codersdk.ProvisionerJobRunning { + return false + } + jobCh <- ws.LatestBuild.Job + return true + }, testutil.WaitLong, testutil.IntervalSlow) + + t.Log("canceling scaletest workspace creation") cancelFunc() <-done - - ctx = testutil.Context(t, testutil.WaitLong) // Reset ctx to avoid timeouts. + t.Log("canceled scaletest workspace creation") + // Ensure we have a job to interrogate + runningJob := testutil.RequireRecvCtx(testutil.Context(t, testutil.WaitShort), t, jobCh) + require.NotZero(t, runningJob.ID) // When we run the cleanup, it should be canceled cleanupLogs := bytes.NewBuffer(nil) - cancelCtx, cancelFunc = context.WithCancel(ctx) + // Reset ctx to avoid timeouts. + cancelCtx, cancelFunc = context.WithTimeout(context.Background(), testutil.WaitLong) done = make(chan struct{}) go func() { // This will return an error as the "delete" operation will never complete. @@ -297,40 +307,23 @@ func Test_Runner(t *testing.T) { close(done) }() - // Ensure the job has been marked as deleted + // Ensure the job has been marked as canceled require.Eventually(t, func() bool { - workspaces, err := client.Workspaces(ctx, codersdk.WorkspaceFilter{}) - if err != nil { + pj, err := client.OrganizationProvisionerJob(ctx, runningJob.OrganizationID, runningJob.ID) + if !assert.NoError(t, err) { return false } - if len(workspaces.Workspaces) == 0 { - return false - } + t.Logf("provisioner job id:%s status:%s", pj.ID, pj.Status) - // There should be two builds - builds, err := client.WorkspaceBuilds(ctx, codersdk.WorkspaceBuildsRequest{ - WorkspaceID: workspaces.Workspaces[0].ID, - }) - if err != nil { + if pj.Status != codersdk.ProvisionerJobFailed && + pj.Status != codersdk.ProvisionerJobCanceling && + pj.Status != codersdk.ProvisionerJobCanceled { return false } - for i, build := range builds { - t.Logf("checking build #%d: %s | %s", i, build.Transition, build.Job.Status) - // One of the builds should be for creating the workspace, - if build.Transition != codersdk.WorkspaceTransitionStart { - continue - } - - // And it should be either failed (Echo returns an error when job is canceled), canceling, or canceled. - if build.Job.Status == codersdk.ProvisionerJobFailed || - build.Job.Status == codersdk.ProvisionerJobCanceling || - build.Job.Status == codersdk.ProvisionerJobCanceled { - return true - } - } - return false - }, testutil.WaitShort, testutil.IntervalMedium) + + return true + }, testutil.WaitLong, testutil.IntervalSlow) cancelFunc() <-done cleanupLogsStr := cleanupLogs.String() From 9e0eb5fa6a8b0bbbcb423d9aafe567dc6a96fe3b Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Tue, 28 Jan 2025 13:39:28 +0000 Subject: [PATCH 2/2] fixup! chore(scaletest/createworkspaces): address context usage --- scaletest/createworkspaces/run_test.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/scaletest/createworkspaces/run_test.go b/scaletest/createworkspaces/run_test.go index 0c0f1a51d78b3..b47ee73548b4f 100644 --- a/scaletest/createworkspaces/run_test.go +++ b/scaletest/createworkspaces/run_test.go @@ -249,13 +249,12 @@ func Test_Runner(t *testing.T) { }, }) - ctx := testutil.Context(t, testutil.WaitLong) - cancelCtx, cancelFunc := context.WithCancel(ctx) + runnerCtx, runnerCancel := context.WithTimeout(context.Background(), testutil.WaitLong) done := make(chan struct{}) logs := bytes.NewBuffer(nil) go func() { - err := runner.Run(cancelCtx, "1", logs) + err := runner.Run(runnerCtx, "1", logs) logsStr := logs.String() t.Log("Runner logs:\n\n" + logsStr) require.ErrorIs(t, err, context.Canceled) @@ -263,9 +262,10 @@ func Test_Runner(t *testing.T) { }() // Wait for the workspace build job to be picked up. + checkJobStartedCtx := testutil.Context(t, testutil.WaitLong) jobCh := make(chan codersdk.ProvisionerJob, 1) require.Eventually(t, func() bool { - workspaces, err := client.Workspaces(ctx, codersdk.WorkspaceFilter{}) + workspaces, err := client.Workspaces(checkJobStartedCtx, codersdk.WorkspaceFilter{}) if err != nil { return false } @@ -289,7 +289,7 @@ func Test_Runner(t *testing.T) { }, testutil.WaitLong, testutil.IntervalSlow) t.Log("canceling scaletest workspace creation") - cancelFunc() + runnerCancel() <-done t.Log("canceled scaletest workspace creation") // Ensure we have a job to interrogate @@ -299,17 +299,18 @@ func Test_Runner(t *testing.T) { // When we run the cleanup, it should be canceled cleanupLogs := bytes.NewBuffer(nil) // Reset ctx to avoid timeouts. - cancelCtx, cancelFunc = context.WithTimeout(context.Background(), testutil.WaitLong) + cleanupCtx, cleanupCancel := context.WithTimeout(context.Background(), testutil.WaitLong) done = make(chan struct{}) go func() { // This will return an error as the "delete" operation will never complete. - _ = runner.Cleanup(cancelCtx, "1", cleanupLogs) + _ = runner.Cleanup(cleanupCtx, "1", cleanupLogs) close(done) }() // Ensure the job has been marked as canceled + checkJobCanceledCtx := testutil.Context(t, testutil.WaitLong) require.Eventually(t, func() bool { - pj, err := client.OrganizationProvisionerJob(ctx, runningJob.OrganizationID, runningJob.ID) + pj, err := client.OrganizationProvisionerJob(checkJobCanceledCtx, runningJob.OrganizationID, runningJob.ID) if !assert.NoError(t, err) { return false } @@ -324,7 +325,7 @@ func Test_Runner(t *testing.T) { return true }, testutil.WaitLong, testutil.IntervalSlow) - cancelFunc() + cleanupCancel() <-done cleanupLogsStr := cleanupLogs.String() require.Contains(t, cleanupLogsStr, "canceling workspace build") pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy