diff --git a/act/common/context_helpers_test.go b/act/common/context_helpers_test.go index c1779b9f..a3602894 100644 --- a/act/common/context_helpers_test.go +++ b/act/common/context_helpers_test.go @@ -4,7 +4,6 @@ package common import ( - "context" "errors" "testing" @@ -13,7 +12,7 @@ import ( ) func TestDryrunContext(t *testing.T) { - ctx := context.Background() + ctx := t.Context() if Dryrun(ctx) { t.Fatal("plain context should not be dryrun") } @@ -26,7 +25,7 @@ func TestDryrunContext(t *testing.T) { } func TestJobErrorContainer(t *testing.T) { - ctx := context.Background() + ctx := t.Context() err := errors.New("job failed") SetJobError(ctx, err) @@ -42,7 +41,7 @@ func TestJobErrorContainer(t *testing.T) { } func TestLoggerAndHandlerContext(t *testing.T) { - ctx := context.Background() + ctx := t.Context() if Logger(ctx) != logging.Default() { t.Fatal("plain context should use the default logger") } diff --git a/act/common/executor_test.go b/act/common/executor_test.go index c10a66c1..46c8efa2 100644 --- a/act/common/executor_test.go +++ b/act/common/executor_test.go @@ -20,7 +20,7 @@ import ( func TestNewWorkflow(t *testing.T) { assert := assert.New(t) - ctx := context.Background() + ctx := t.Context() // empty emptyWorkflow := NewPipelineExecutor() @@ -72,7 +72,7 @@ func concurrencyProbe(wantActive int32) (exec Executor, count, maxActive *atomic } func TestNewParallelExecutor(t *testing.T) { - ctx := context.Background() + ctx := t.Context() exec, count, maxActive := concurrencyProbe(2) require.NoError(t, NewParallelExecutor(2, exec, exec, exec)(ctx)) @@ -89,10 +89,10 @@ func TestNewParallelExecutor(t *testing.T) { func TestNewParallelExecutorEmpty(t *testing.T) { assert := assert.New(t) - ctx := context.Background() + ctx := t.Context() require.NoError(t, NewParallelExecutor(2)(ctx)) - canceledCtx, cancel := context.WithCancel(context.Background()) + canceledCtx, cancel := context.WithCancel(t.Context()) cancel() err := NewParallelExecutor(2)(canceledCtx) @@ -102,7 +102,7 @@ func TestNewParallelExecutorEmpty(t *testing.T) { func TestNewParallelExecutorFailed(t *testing.T) { assert := assert.New(t) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) cancel() count := 0 @@ -118,7 +118,7 @@ func TestNewParallelExecutorFailed(t *testing.T) { func TestNewParallelExecutorCanceled(t *testing.T) { assert := assert.New(t) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) cancel() errExpected := errors.New("fake error") @@ -150,12 +150,12 @@ func TestNewParallelExecutorRunsRemainingAfterFailure(t *testing.T) { } } - require.Error(t, NewParallelExecutor(2, executors...)(context.Background())) + require.Error(t, NewParallelExecutor(2, executors...)(t.Context())) assert.Equal(t, int32(4), successCount.Load(), "a failing executor must not stop the others") } func TestExecutorConditionalsAndFinally(t *testing.T) { - ctx := context.Background() + ctx := t.Context() var calls []string record := func(name string) Executor { return func(ctx context.Context) error { @@ -180,7 +180,7 @@ func TestExecutorFinallyReturnsFinallyErrorWithOriginal(t *testing.T) { mainErr := errors.New("main failed") finalErr := errors.New("cleanup failed") - err := NewErrorExecutor(mainErr).Finally(NewErrorExecutor(finalErr))(context.Background()) + err := NewErrorExecutor(mainErr).Finally(NewErrorExecutor(finalErr))(t.Context()) require.Error(t, err) if !strings.Contains(err.Error(), "cleanup failed") || !strings.Contains(err.Error(), "main failed") { t.Fatalf("finally error = %q, want both cleanup and original error", err) diff --git a/act/common/git/git_test.go b/act/common/git/git_test.go index 61a6879e..faf33aeb 100644 --- a/act/common/git/git_test.go +++ b/act/common/git/git_test.go @@ -99,21 +99,21 @@ func TestFindGitMetadataOfSHA256RepositoryUsesOrigin(t *testing.T) { require.NoError(t, gitCmd("-C", basedir, "remote", "add", "origin", remoteURL)) require.NoError(t, gitCmd("-C", basedir, "config", "--add", "remote.origin.url", "https://github.com/other/repo.git")) - shortSHA, sha, err := FindGitRevision(context.Background(), basedir) + shortSHA, sha, err := FindGitRevision(t.Context(), basedir) require.NoError(t, err) require.Equal(t, gitRevParse(t, basedir, "HEAD"), sha) require.Len(t, sha, 64) require.Equal(t, sha[:7], shortSHA) - ref, err := FindGitRef(context.Background(), basedir) + ref, err := FindGitRef(t.Context(), basedir) require.NoError(t, err) require.Equal(t, "refs/heads/main", ref) - url, err := findGitRemoteURL(context.Background(), basedir) + url, err := findGitRemoteURL(t.Context(), basedir) require.NoError(t, err) require.Equal(t, remoteURL, url) - slug, err := FindGithubRepo(context.Background(), basedir) + slug, err := FindGithubRepo(t.Context(), basedir) require.NoError(t, err) require.Equal(t, "owner/repo", slug) } @@ -190,7 +190,7 @@ func TestGitFindRef(t *testing.T) { require.NoError(t, gitCmd("-C", dir, "init", "--initial-branch=master")) require.NoError(t, cleanGitHooks(dir)) tt.Prepare(t, dir) - ref, err := FindGitRef(context.Background(), dir) + ref, err := FindGitRef(t.Context(), dir) tt.Assert(t, ref, err) }) } @@ -264,17 +264,17 @@ func TestGitCloneExecutor(t *testing.T) { Dir: dir, }) - err := clone(context.Background()) + err := clone(t.Context()) if tt.Err != nil { assert.Error(t, err) //nolint:testifylint // pre-existing issue from nektos/act assert.Equal(t, tt.Err, err) - assert.Equal(t, tt.Err, clone(context.Background()), "a retry on the cache keeps the error") + assert.Equal(t, tt.Err, clone(t.Context()), "a retry on the cache keeps the error") return } assert.Empty(t, err) //nolint:testifylint // pre-existing issue from nektos/act marker := filepath.Join(dir, "marker") require.NoError(t, os.WriteFile(marker, nil, 0o644)) - require.NoError(t, clone(context.Background())) + require.NoError(t, clone(t.Context())) assert.FileExists(t, marker, "an insteadOf rewrite must not evict the cache") script, err := os.ReadFile(filepath.Join(dir, "action.sh")) require.NoError(t, err) @@ -353,19 +353,19 @@ func TestGitCloneExecutorFollowsRemoteRefChanges(t *testing.T) { dir := t.TempDir() clone := NewGitCloneExecutor(NewGitCloneExecutorInput{URL: remoteDir, Ref: "main", Dir: dir}) - require.NoError(t, clone(context.Background())) + require.NoError(t, clone(t.Context())) require.NoError(t, gitCmd("-C", workDir, "reset", "--hard", "HEAD~1")) require.NoError(t, gitCmd("-C", workDir, "commit", "--allow-empty", "-m", "feature-rewritten")) require.NoError(t, gitCmd("-C", workDir, "push", "--force", "origin", "main")) - require.NoError(t, clone(context.Background()), "a non-fast-forward ref must update") + require.NoError(t, clone(t.Context()), "a non-fast-forward ref must update") assert.Equal(t, "feature-rewritten", gitHeadSubject(t, dir)) tagClone := NewGitCloneExecutor(NewGitCloneExecutorInput{URL: remoteDir, Ref: "v9", Dir: t.TempDir()}) - require.Error(t, tagClone(context.Background())) + require.Error(t, tagClone(t.Context())) require.NoError(t, gitCmd("-C", workDir, "tag", "v9")) require.NoError(t, gitCmd("-C", workDir, "push", "origin", "v9")) - require.NoError(t, tagClone(context.Background()), "a tag published after a failed lookup must be fetched") + require.NoError(t, tagClone(t.Context()), "a tag published after a failed lookup must be fetched") } func TestGitCloneExecutorOfflineMode(t *testing.T) { @@ -385,7 +385,7 @@ func TestGitCloneExecutorOfflineMode(t *testing.T) { URL: remoteDir, Ref: "main", Dir: cacheDir, - })(context.Background())) + })(t.Context())) t.Run("cached branch resolves without fetching", func(t *testing.T) { // Offline reuse of a cached branch must succeed even though ResolveRevision(input.Ref) @@ -395,7 +395,7 @@ func TestGitCloneExecutorOfflineMode(t *testing.T) { Ref: "main", Dir: cacheDir, OfflineMode: true, - })(context.Background()) + })(t.Context()) require.NoError(t, err) out, err := exec.Command("git", "-C", cacheDir, "log", "--oneline", "-1", "--format=%s").Output() @@ -410,7 +410,7 @@ func TestGitCloneExecutorOfflineMode(t *testing.T) { Ref: "never-fetched", Dir: cacheDir, OfflineMode: true, - })(context.Background()) + })(t.Context()) require.Error(t, err) }) } @@ -430,7 +430,7 @@ func TestGitCloneExecutorQuietDemotesCloneLine(t *testing.T) { t.Run(name, func(t *testing.T) { hook := logtest.New() logger := logging.New(logging.NewLevelHandler(hook, logging.LevelInfo)) - ctx := common.WithLogger(context.Background(), logger.With("job", "j1")) + ctx := common.WithLogger(t.Context(), logger.With("job", "j1")) require.NoError(t, NewGitCloneExecutor(NewGitCloneExecutorInput{ URL: remoteDir, diff --git a/act/container/docker_images_test.go b/act/container/docker_images_test.go index 0f9c93a1..233b5017 100644 --- a/act/container/docker_images_test.go +++ b/act/container/docker_images_test.go @@ -5,7 +5,6 @@ package container import ( - "context" "fmt" "os" "os/exec" @@ -42,7 +41,7 @@ func buildScratchImage(t *testing.T, platform string) string { func TestImageExistsLocally(t *testing.T) { requireDocker(t) - ctx := context.Background() + ctx := t.Context() // a non-existent image is reported absent missing, err := ImageExistsLocally(ctx, "library/alpine:this-random-tag-will-never-exist", "linux/amd64") diff --git a/act/container/docker_network_test.go b/act/container/docker_network_test.go index 9fc1f2ae..5f8a67df 100644 --- a/act/container/docker_network_test.go +++ b/act/container/docker_network_test.go @@ -19,7 +19,7 @@ import ( ) func TestIsolatedCacheContainer(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cache, lan := netip.MustParseAddr("172.18.0.3"), netip.MustParseAddr("192.168.1.20") client := &mockDockerClient{} client.On("ContainerList", ctx, mobyclient.ContainerListOptions{}).Return(mobyclient.ContainerListResult{Items: []container.Summary{{}, { @@ -58,7 +58,7 @@ func TestIsAddressPoolExhausted(t *testing.T) { } func TestCreateDockerNetworkInheritsDaemonMTU(t *testing.T) { - ctx := context.Background() + ctx := t.Context() for _, tc := range []struct { bridgeOptions, want map[string]string }{ @@ -87,7 +87,7 @@ func (m *mockDockerClient) NetworkDisconnect(ctx context.Context, id string, opt } func TestConnectAndDisconnectNetwork(t *testing.T) { - ctx := context.Background() + ctx := t.Context() connect := func(answer error) error { client := &mockDockerClient{} client.On("NetworkConnect", ctx, "jobs", mobyclient.NetworkConnectOptions{ @@ -117,7 +117,7 @@ func TestConnectAndDisconnectNetwork(t *testing.T) { // and old enough to predate any job now starting are the runner's to reclaim. An unexpected // NetworkRemove fails the test on its own, since testify has no expectation to match it against. func TestRemoveOrphanNetworks(t *testing.T) { - ctx := context.Background() + ctx := t.Context() cutoff := time.Date(2026, time.April, 29, 20, 0, 0, 0, time.UTC) client := &mockDockerClient{} client.On("NetworkList", ctx, mobyclient.NetworkListOptions{ diff --git a/act/container/docker_proxy_test.go b/act/container/docker_proxy_test.go index 6bc25695..880bad60 100644 --- a/act/container/docker_proxy_test.go +++ b/act/container/docker_proxy_test.go @@ -285,7 +285,7 @@ func TestRemoveLabelledRemovesContainersNetworksAndVolumes(t *testing.T) { containerFailure := errors.New("container removal failed") listFailure := errors.New("listing failed") volumeFailure := errors.New("volume removal failed") - ctx := context.Background() + ctx := t.Context() filters := make(mobyclient.Filters).Add("label", jobLabel+"=job-1") cli := &mockDockerClient{} cli.On("ContainerList", ctx, mobyclient.ContainerListOptions{All: true, Filters: filters}). @@ -312,7 +312,7 @@ func TestRemoveLabelledRemovesContainersNetworksAndVolumes(t *testing.T) { func TestDockerProxyWithDaemon(t *testing.T) { requireDocker(t) - ctx := context.Background() + ctx := t.Context() require.NoError(t, NewDockerPullExecutor(NewDockerPullExecutorInput{Image: "alpine"})(ctx)) direct, err := GetDockerClient(ctx) require.NoError(t, err) diff --git a/act/container/docker_pull_test.go b/act/container/docker_pull_test.go index ed17674f..0b778bca 100644 --- a/act/container/docker_pull_test.go +++ b/act/container/docker_pull_test.go @@ -5,7 +5,6 @@ package container import ( - "context" "io" "strings" "testing" @@ -37,13 +36,13 @@ func TestCleanImage(t *testing.T) { } for _, table := range tables { - imageOut := cleanImage(context.Background(), table.imageIn) + imageOut := cleanImage(t.Context(), table.imageIn) assert.Equal(t, table.imageOut, imageOut) } } func TestGetImagePullOptions(t *testing.T) { - ctx := context.Background() + ctx := t.Context() orig := config.Dir() t.Cleanup(func() { config.SetDir(orig) }) diff --git a/act/container/docker_run_test.go b/act/container/docker_run_test.go index 7dcd237d..4ba08d8d 100644 --- a/act/container/docker_run_test.go +++ b/act/container/docker_run_test.go @@ -166,7 +166,7 @@ func (m *mockConn) Close() (err error) { } func TestDockerExecAbort(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) reader := &interruptReader{started: make(chan struct{}), interrupted: make(chan struct{}), stopped: make(chan struct{})} conn := &mockConn{} @@ -207,7 +207,7 @@ func TestDockerExecAbort(t *testing.T) { } func TestDockerExecFailure(t *testing.T) { - ctx := context.Background() + ctx := t.Context() conn := &mockConn{} @@ -254,7 +254,7 @@ func stdcopyFrame(stream stdcopy.StdType, payload string) []byte { // attach() streaming goroutine has drained and flushed the container's output, // so a final line without a trailing newline is not lost. func TestDockerAttachFlushesTrailingLine(t *testing.T) { - ctx := context.Background() + ctx := t.Context() framed := bytes.NewBuffer(stdcopyFrame(stdcopy.Stdout, "line one\nlast line without newline")) @@ -303,7 +303,7 @@ func TestDockerAttachFlushesTrailingLine(t *testing.T) { } func TestDockerWaitFailure(t *testing.T) { - ctx := context.Background() + ctx := t.Context() statusCh := make(chan container.WaitResponse, 1) statusCh <- container.WaitResponse{StatusCode: 2} @@ -355,7 +355,7 @@ func TestRemoveIgnoresAutoRemoveRace(t *testing.T) { } { t.Run(tc.name, func(t *testing.T) { logger, hook := logtest.NewLogger() - ctx := common.WithLogger(context.Background(), logger) + ctx := common.WithLogger(t.Context(), logger) client := &mockDockerClient{} client.On("ContainerKill", ctx, "abc", killOpts).Return(mobyclient.ContainerKillResult{}, nil) client.On("ContainerRemove", ctx, "abc", removeOpts).Return(mobyclient.ContainerRemoveResult{}, tc.err) @@ -388,7 +388,7 @@ func TestRemoveIgnoresAutoRemoveRace(t *testing.T) { // create() lost its reply, must still be removed rather than leaking with its network. It // was never started here, so it is not worth a kill of its own. func TestRemoveWithoutIDUsesName(t *testing.T) { - ctx := context.Background() + ctx := t.Context() client := &mockDockerClient{} client.On("ContainerRemove", ctx, "job-1", mobyclient.ContainerRemoveOptions{RemoveVolumes: true, Force: true}). Return(mobyclient.ContainerRemoveResult{}, nil) @@ -401,7 +401,7 @@ func TestRemoveWithoutIDUsesName(t *testing.T) { // find() must drop a stale cached id so later Copy/Exec don't hit the // daemon with a torn-down container. func TestFindRevalidatesStaleID(t *testing.T) { - ctx := context.Background() + ctx := t.Context() notFound := cerrdefs.ErrNotFound.WithMessage("No such container") boom := errors.New("daemon unreachable") newCR := func(id string) (*containerReference, *mockDockerClient) { @@ -459,7 +459,7 @@ func TestFindRevalidatesStaleID(t *testing.T) { // Every daemon entry point fails fast with a clear, container-named // error when no live cr.id is known. func TestRejectsMissingContainer(t *testing.T) { - ctx := context.Background() + ctx := t.Context() client := &mockDockerClient{} client.On("ContainerList", ctx, mobyclient.ContainerListOptions{All: true}).Return(mobyclient.ContainerListResult{}, nil) cr := &containerReference{cli: client, input: &NewContainerInput{Name: "job-1"}} @@ -616,7 +616,7 @@ func TestCheckVolumes(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { logger, hook := logtest.NewLogger() - ctx := common.WithLogger(context.Background(), logger) + ctx := common.WithLogger(t.Context(), logger) cr := &containerReference{ input: &NewContainerInput{ ValidVolumes: tc.validVolumes, @@ -656,12 +656,12 @@ func TestMergeContainerConfigsKeepsTheRunnersFilesAndEnvToItself(t *testing.T) { logger := logging.New(logtest.New()) cr := &containerReference{input: &NewContainerInput{NetworkMode: "bridge", WorkflowOptions: option}} - _, _, err := cr.mergeContainerConfigs(common.WithLogger(context.Background(), logger), &container.Config{}, &container.HostConfig{}) + _, _, err := cr.mergeContainerConfigs(common.WithLogger(t.Context(), logger), &container.Config{}, &container.HostConfig{}) require.ErrorContains(t, err, "not allowed in a workflow") // the runner reading its own files is what those options are for cr = &containerReference{input: &NewContainerInput{NetworkMode: "bridge", RunnerOptions: option}} - _, _, err = cr.mergeContainerConfigs(common.WithLogger(context.Background(), logger), &container.Config{}, &container.HostConfig{}) + _, _, err = cr.mergeContainerConfigs(common.WithLogger(t.Context(), logger), &container.Config{}, &container.HostConfig{}) require.NoError(t, err) } @@ -673,7 +673,7 @@ func TestMergeContainerConfigsKeepsTheRunnersFilesAndEnvToItself(t *testing.T) { WorkflowOptions: "--env RUNNER_SECRET --env GIVEN=value", }} - config, _, err := cr.mergeContainerConfigs(common.WithLogger(context.Background(), logger), &container.Config{}, &container.HostConfig{}) + config, _, err := cr.mergeContainerConfigs(common.WithLogger(t.Context(), logger), &container.Config{}, &container.HostConfig{}) require.NoError(t, err) assert.Equal(t, []string{"RUNNER_SECRET", "RUNNER_SECRET", "GIVEN=value"}, config.Env) } @@ -723,7 +723,7 @@ func mergeOptions(t *testing.T, runnerOptions, workflowOptions string, privilege ValidVolumes: []string{"**"}, }} - _, hostConfig, err := cr.mergeContainerConfigs(common.WithLogger(context.Background(), logger), &container.Config{}, &container.HostConfig{ + _, hostConfig, err := cr.mergeContainerConfigs(common.WithLogger(t.Context(), logger), &container.Config{}, &container.HostConfig{ Privileged: privileged, UsernsMode: container.UsernsMode("private"), NetworkMode: container.NetworkMode("bridge"), @@ -767,7 +767,7 @@ func TestMergeContainerConfigsStripsDangerousOptionsWhenUnprivileged(t *testing. func TestCheckVolumesRejectsEscapingHostPaths(t *testing.T) { logger := logging.New(logtest.New()) - ctx := common.WithLogger(context.Background(), logger) + ctx := common.WithLogger(t.Context(), logger) base := t.TempDir() allowed := filepath.Join(base, "allowed") @@ -808,7 +808,7 @@ func TestSanitizeConfigKeepsTmpfsMounts(t *testing.T) { for _, validVolumes := range [][]string{nil, {"data"}, {"**:ro"}} { logger, hook := logtest.NewLogger() - _, sanitized := (&containerReference{input: &NewContainerInput{ValidVolumes: validVolumes}}).sanitizeConfig(common.WithLogger(context.Background(), logger), &container.Config{}, &container.HostConfig{Mounts: []mount.Mount{ + _, sanitized := (&containerReference{input: &NewContainerInput{ValidVolumes: validVolumes}}).sanitizeConfig(common.WithLogger(t.Context(), logger), &container.Config{}, &container.HostConfig{Mounts: []mount.Mount{ hostConfig.Mounts[0], {Type: mount.TypeVolume, Target: "/anonymous"}, {Type: mount.TypeTmpfs, Source: "/etc", Target: "/etc-copy"}, @@ -898,7 +898,7 @@ func TestContainerInfoFromInspect(t *testing.T) { func TestMergeContainerConfigsVolumesReplaceRunnerMounts(t *testing.T) { logger := logging.New(logtest.New()) - ctx := common.WithLogger(context.Background(), logger) + ctx := common.WithLogger(t.Context(), logger) cr := &containerReference{ input: &NewContainerInput{ NetworkMode: "bridge", diff --git a/act/container/helpers_test.go b/act/container/helpers_test.go index 0c660ae5..88e13ff6 100644 --- a/act/container/helpers_test.go +++ b/act/container/helpers_test.go @@ -4,7 +4,6 @@ package container import ( - "context" "testing" mobyclient "github.com/moby/moby/client" @@ -15,7 +14,7 @@ import ( // so the daemon has to be pinged explicitly here to decide whether to skip. func requireDocker(t *testing.T) { t.Helper() - ctx := context.Background() + ctx := t.Context() cli, err := GetDockerClient(ctx) if err != nil { t.Skipf("skipping: docker client unavailable: %v", err) diff --git a/act/container/host_environment_test.go b/act/container/host_environment_test.go index e179aaf9..b50dbb2c 100644 --- a/act/container/host_environment_test.go +++ b/act/container/host_environment_test.go @@ -62,7 +62,7 @@ func TestCopyDir(t *testing.T) { func TestGetContainerArchive(t *testing.T) { dir := t.TempDir() - ctx := context.Background() + ctx := t.Context() e := &HostEnvironment{ Path: filepath.Join(dir, "path"), TmpDir: filepath.Join(dir, "tmp"), @@ -97,7 +97,7 @@ func TestHostEnvironmentExecExitCode(t *testing.T) { t.Skip("uses POSIX shell") } dir := t.TempDir() - ctx := context.Background() + ctx := t.Context() e := &HostEnvironment{ Path: filepath.Join(dir, "path"), TmpDir: filepath.Join(dir, "tmp"), @@ -148,7 +148,7 @@ func TestHostEnvironmentAllocatePTY(t *testing.T) { err := e.Exec( []string{"sh", "-c", "[ -t 1 ] && printf TTY || printf NOTTY"}, map[string]string{"PATH": os.Getenv("PATH")}, "", "", - )(context.Background()) + )(t.Context()) require.NoError(t, err) got := strings.TrimSpace(strings.ReplaceAll(buf.String(), "\r", "")) assert.Equal(t, tc.expect, got) @@ -157,7 +157,7 @@ func TestHostEnvironmentAllocatePTY(t *testing.T) { } func TestHostEnvironmentRemovePreservesWorkdirByDefault(t *testing.T) { - ctx := common.WithLogger(context.Background(), logging.Default()) + ctx := common.WithLogger(t.Context(), logging.Default()) base := t.TempDir() miscRoot := filepath.Join(base, "misc") path := filepath.Join(miscRoot, "hostexecutor") @@ -179,7 +179,7 @@ func TestHostEnvironmentRemovePreservesWorkdirByDefault(t *testing.T) { } func TestHostEnvironmentRemoveCleansWorkdirWhenOwned(t *testing.T) { - ctx := common.WithLogger(context.Background(), logging.Default()) + ctx := common.WithLogger(t.Context(), logging.Default()) base := t.TempDir() miscRoot := filepath.Join(base, "misc") path := filepath.Join(miscRoot, "hostexecutor") @@ -220,7 +220,7 @@ func TestRemoveAllWithContextDoesNotHangOnStuckDelete(t *testing.T) { removeAll = orig }) - ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) + ctx, cancel := context.WithTimeout(t.Context(), 100*time.Millisecond) defer cancel() err := removeAllWithContext(ctx, t.TempDir()) @@ -237,7 +237,7 @@ func TestHostEnvironmentRemoveDoesNotHangOnStuckCleanUp(t *testing.T) { hostCleanupTimeout = 100 * time.Millisecond t.Cleanup(func() { hostCleanupTimeout = orig }) - ctx := common.WithLogger(context.Background(), logging.Default()) + ctx := common.WithLogger(t.Context(), logging.Default()) base := t.TempDir() path := filepath.Join(base, "misc", "hostexecutor") require.NoError(t, os.MkdirAll(path, 0o700)) @@ -290,7 +290,7 @@ func TestHostEnvironmentRemoveDoesNotHangOnStuckPathRemoval(t *testing.T) { removeAll = origRemoveAll }) - ctx := common.WithLogger(context.Background(), logging.Default()) + ctx := common.WithLogger(t.Context(), logging.Default()) base := t.TempDir() path := filepath.Join(base, "misc", "hostexecutor") require.NoError(t, os.MkdirAll(path, 0o700)) diff --git a/act/container/parse_env_file_test.go b/act/container/parse_env_file_test.go index c11831f2..28115b5e 100644 --- a/act/container/parse_env_file_test.go +++ b/act/container/parse_env_file_test.go @@ -5,7 +5,6 @@ package container import ( "bufio" - "context" "os" "path/filepath" "strings" @@ -28,7 +27,7 @@ func TestParseEnvFileSingleLine(t *testing.T) { require.NoError(t, os.WriteFile(envPath, []byte("FOO=bar\nBAZ=qux\n"), 0o600)) env := map[string]string{} - require.NoError(t, parseEnvFile(e, envPath, &env)(context.Background())) + require.NoError(t, parseEnvFile(e, envPath, &env)(t.Context())) assert.Equal(t, "bar", env["FOO"]) assert.Equal(t, "qux", env["BAZ"]) } @@ -39,7 +38,7 @@ func TestParseEnvFileMultiLine(t *testing.T) { require.NoError(t, os.WriteFile(envPath, []byte(content), 0o600)) env := map[string]string{} - require.NoError(t, parseEnvFile(e, envPath, &env)(context.Background())) + require.NoError(t, parseEnvFile(e, envPath, &env)(t.Context())) assert.Equal(t, "line1\nline2", env["FOO"]) } @@ -50,7 +49,7 @@ func TestParseEnvFileLargeValueWithinLimit(t *testing.T) { require.NoError(t, os.WriteFile(envPath, []byte(content), 0o600)) env := map[string]string{} - require.NoError(t, parseEnvFile(e, envPath, &env)(context.Background())) + require.NoError(t, parseEnvFile(e, envPath, &env)(t.Context())) assert.Equal(t, big, env["FOO"]) } @@ -61,7 +60,7 @@ func TestParseEnvFileLineExceedsBufferReportsScannerError(t *testing.T) { require.NoError(t, os.WriteFile(envPath, []byte(content), 0o600)) env := map[string]string{} - err := parseEnvFile(e, envPath, &env)(context.Background()) + err := parseEnvFile(e, envPath, &env)(t.Context()) require.ErrorIs(t, err, bufio.ErrTooLong) assert.Contains(t, err.Error(), "reading env file") } @@ -73,7 +72,7 @@ func TestParseEnvFileBlankLines(t *testing.T) { require.NoError(t, os.WriteFile(envPath, []byte("\nFOO=bar\n\n \nBAZ=qux\n\n"), 0o600)) env := map[string]string{} - require.NoError(t, parseEnvFile(e, envPath, &env)(context.Background())) + require.NoError(t, parseEnvFile(e, envPath, &env)(t.Context())) assert.Equal(t, "bar", env["FOO"]) assert.Equal(t, "qux", env["BAZ"]) } @@ -84,12 +83,12 @@ func TestParseEnvFileMultiLineKeepsBlankLines(t *testing.T) { require.NoError(t, os.WriteFile(envPath, []byte("FOO< 0 }, time.Second, 10*time.Millisecond, "polling should resume after local recovery") - shutdownCtx, cancel := context.WithTimeout(context.Background(), time.Second) + shutdownCtx, cancel := context.WithTimeout(t.Context(), time.Second) defer cancel() require.NoError(t, poller.Shutdown(shutdownCtx)) wg.Wait() @@ -280,7 +280,7 @@ func (m *mockRunner) Run(ctx context.Context, _ *runnerv1.Task) error { func TestPollerRunIdleMaintenance(t *testing.T) { runner := &idleAwareRunner{} - p := &Poller{runner: runner, jobsCtx: context.Background()} + p := &Poller{runner: runner, jobsCtx: t.Context()} p.runIdleMaintenance() @@ -315,7 +315,7 @@ func TestPollerPollCallsOnIdle(t *testing.T) { return runner.idleCalls.Load() > 0 }, time.Second, 10*time.Millisecond) - ctx, cancel := context.WithTimeout(context.Background(), time.Second) + ctx, cancel := context.WithTimeout(t.Context(), time.Second) defer cancel() require.NoError(t, poller.Shutdown(ctx)) wg.Wait() @@ -344,7 +344,7 @@ func TestPollerPollOnceCallsOnIdle(t *testing.T) { return runner.idleCalls.Load() > 0 }, time.Second, 10*time.Millisecond) - ctx, cancel := context.WithTimeout(context.Background(), time.Second) + ctx, cancel := context.WithTimeout(t.Context(), time.Second) defer cancel() require.NoError(t, poller.Shutdown(ctx)) wg.Wait() @@ -411,7 +411,7 @@ func TestPoller_ConcurrencyLimitedByCapacity(t *testing.T) { return runner.totalCompleted.Load() >= totalTasks }, 2*time.Second, 10*time.Millisecond, "all tasks should complete") - ctx, cancel := context.WithTimeout(context.Background(), time.Second) + ctx, cancel := context.WithTimeout(t.Context(), time.Second) defer cancel() err = poller.Shutdown(ctx) require.NoError(t, err) @@ -467,7 +467,7 @@ func TestPoller_ShutdownForcesJobsOnTimeout(t *testing.T) { return runner.running.Load() == 1 }, time.Second, 10*time.Millisecond, "task should start running") - ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond) + ctx, cancel := context.WithTimeout(t.Context(), 50*time.Millisecond) defer cancel() start := time.Now() err = poller.Shutdown(ctx) diff --git a/internal/app/run/post_task_script_test.go b/internal/app/run/post_task_script_test.go index 44a208d4..afde412f 100644 --- a/internal/app/run/post_task_script_test.go +++ b/internal/app/run/post_task_script_test.go @@ -25,7 +25,7 @@ func TestRunPostTaskScriptSkippedWhenEmpty(t *testing.T) { r := &Runner{ cfg: &config.Config{}, } - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() taskCtx, err := structpb.NewStruct(map[string]any{}) @@ -48,7 +48,7 @@ func TestRunPostTaskScriptNonZeroExitDoesNotPanic(t *testing.T) { cfg.Runner.PostTaskScript = scriptPath r := &Runner{cfg: cfg} - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() taskCtx, err := structpb.NewStruct(map[string]any{}) @@ -66,7 +66,7 @@ func TestPostTaskScriptContextUsesFullTimeout(t *testing.T) { // A task context that finished close to its own deadline must not truncate the // script's budget: the script should still get its full configured timeout. - near, cancelNear := context.WithTimeout(context.Background(), time.Second) + near, cancelNear := context.WithTimeout(t.Context(), time.Second) defer cancelNear() scriptCtx, cancel := postTaskScriptContext(near, timeout) defer cancel() @@ -75,7 +75,7 @@ func TestPostTaskScriptContextUsesFullTimeout(t *testing.T) { assert.Greater(t, time.Until(deadline), time.Minute, "script timeout truncated to task deadline") // An already-cancelled task context must not cancel the script either. - cancelledCtx, cancelIt := context.WithCancel(context.Background()) + cancelledCtx, cancelIt := context.WithCancel(t.Context()) cancelIt() scriptCtx2, cancel2 := postTaskScriptContext(cancelledCtx, timeout) defer cancel2() @@ -91,7 +91,7 @@ func TestPostTaskScriptEnv(t *testing.T) { envs: map[string]string{"BASE": "1"}, } - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() taskCtx, err := structpb.NewStruct(map[string]any{ @@ -128,7 +128,7 @@ func TestRunPostTaskScriptIntegration(t *testing.T) { envs: map[string]string{"CUSTOM": "runner-env"}, } - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() taskCtx, err := structpb.NewStruct(map[string]any{}) diff --git a/internal/app/run/runner_idle_cleanup_test.go b/internal/app/run/runner_idle_cleanup_test.go index 0247ea34..d92c774d 100644 --- a/internal/app/run/runner_idle_cleanup_test.go +++ b/internal/app/run/runner_idle_cleanup_test.go @@ -46,7 +46,7 @@ func TestRunnerCleanupStaleTaskDirs(t *testing.T) { now: func() time.Time { return now }, } - r.cleanupStaleDirs(context.Background(), workdirRoot, isTaskIDDir) + r.cleanupStaleDirs(t.Context(), workdirRoot, isTaskIDDir) assert.NoDirExists(t, oldTask) assert.DirExists(t, freshTask) @@ -85,7 +85,7 @@ func TestRunnerOnIdleCleansStaleHostScratchDirs(t *testing.T) { now: func() time.Time { return now }, } - r.OnIdle(context.Background()) + r.OnIdle(t.Context()) assert.NoDirExists(t, staleScratch) // stale scratch reclaimed assert.DirExists(t, freshScratch) // within cleanup age, kept @@ -113,7 +113,7 @@ func TestRunnerCleanupStaleTaskDirsMissingRoot(t *testing.T) { // Must be a silent no-op rather than a warning or panic when the root // has not yet been created (e.g. the runner has never executed a task). - r.cleanupStaleDirs(context.Background(), filepath.Join(t.TempDir(), "missing"), isTaskIDDir) + r.cleanupStaleDirs(t.Context(), filepath.Join(t.TempDir(), "missing"), isTaskIDDir) } func TestRunnerCleanupStaleTaskDirsHonorsContext(t *testing.T) { @@ -127,7 +127,7 @@ func TestRunnerCleanupStaleTaskDirsHonorsContext(t *testing.T) { require.NoError(t, os.Chtimes(dir, now.Add(-3*time.Hour), now.Add(-3*time.Hour))) } - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) cancel() r := &Runner{ @@ -265,7 +265,7 @@ func TestRunnerOnIdleIntegratesCleanup(t *testing.T) { now: func() time.Time { return now }, } - r.OnIdle(context.Background()) + r.OnIdle(t.Context()) assert.NoDirExists(t, stale) } @@ -293,7 +293,7 @@ func TestRunnerOnIdleSkipsWhenAlreadyCancelled(t *testing.T) { now: func() time.Time { return now }, } - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) cancel() r.OnIdle(ctx) @@ -346,7 +346,7 @@ func TestRunnerOnIdleRemovesOrphanNetworks(t *testing.T) { r := &Runner{uuid: "runner-1", cfg: cfg, labels: labels.Labels{kubernetesLabel}, now: func() time.Time { return now }} r.isolatedCacheContainer = func() string { return "a1b2c3d4e5f6" } - r.OnIdle(context.Background()) + r.OnIdle(t.Context()) assert.Equal(t, []string{"runner-1"}, swept) assert.Equal(t, swept, sweptVolumes) // a network of a job starting during the pass is younger than this and so out of scope @@ -358,13 +358,13 @@ func TestRunnerOnIdleRemovesOrphanNetworks(t *testing.T) { t.Cleanup(func() { dockerReachable = origDockerReachable }) hostOnly := &Runner{uuid: "runner-2", cfg: &config.Config{Runner: cfg.Runner}, now: func() time.Time { return now }} hostOnly.isolatedCacheContainer = func() string { return "" } - hostOnly.OnIdle(context.Background()) + hostOnly.OnIdle(t.Context()) assert.Equal(t, []string{"runner-1"}, swept) assert.Equal(t, swept, sweptVolumes) dockerReachable = func(context.Context) bool { return true } now = now.Add(time.Minute) - hostOnly.OnIdle(context.Background()) + hostOnly.OnIdle(t.Context()) assert.Equal(t, []string{"runner-1", "runner-2"}, sweptVolumes) assert.Equal(t, []string{"a1b2c3d4e5f6", ""}, detached) assert.Equal(t, []string{"runner-1"}, sweptPods) diff --git a/internal/app/run/runner_test.go b/internal/app/run/runner_test.go index de497707..1ab34541 100644 --- a/internal/app/run/runner_test.go +++ b/internal/app/run/runner_test.go @@ -47,7 +47,7 @@ func TestRunnerCapabilitiesAndDeclare(t *testing.T) { })).Return(connect.NewResponse(&runnerv1.DeclareResponse{}), nil) r := &Runner{client: cli} - _, err := r.Declare(context.Background(), []string{"ubuntu"}) + _, err := r.Declare(t.Context(), []string{"ubuntu"}) require.NoError(t, err) } diff --git a/internal/pkg/envcheck/docker_test.go b/internal/pkg/envcheck/docker_test.go index e762e542..07c87369 100644 --- a/internal/pkg/envcheck/docker_test.go +++ b/internal/pkg/envcheck/docker_test.go @@ -11,7 +11,7 @@ import ( ) func TestCheckIfDockerRunningReturnsPingError(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) cancel() err := CheckIfDockerRunning(ctx, "unix:///definitely/missing/docker.sock") diff --git a/internal/pkg/metrics/metrics_test.go b/internal/pkg/metrics/metrics_test.go index 535307fb..5b590c72 100644 --- a/internal/pkg/metrics/metrics_test.go +++ b/internal/pkg/metrics/metrics_test.go @@ -96,7 +96,7 @@ func TestRegisterRunningJobsFuncZeroCapacity(t *testing.T) { } func TestStartServerCanBeCancelled(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) StartServer(ctx, "127.0.0.1:0", nil) cancel() } diff --git a/internal/pkg/process/leftover_windows_test.go b/internal/pkg/process/leftover_windows_test.go index 9748024a..5f899244 100644 --- a/internal/pkg/process/leftover_windows_test.go +++ b/internal/pkg/process/leftover_windows_test.go @@ -4,7 +4,6 @@ package process import ( - "context" "os" "os/exec" "path/filepath" @@ -70,7 +69,7 @@ func TestKillProcessesWithCWDUnderTerminatesMatch(t *testing.T) { cmd := startSleeperIn(t, dir) awaitCWD(t, cmd.Process.Pid) - killed, err := KillProcessesWithCWDUnder(context.Background(), []string{dir}) + killed, err := KillProcessesWithCWDUnder(t.Context(), []string{dir}) require.NoError(t, err) require.GreaterOrEqual(t, killed, 1) @@ -85,7 +84,7 @@ func TestKillProcessesWithCWDUnderSparesUnrelated(t *testing.T) { cmd := startSleeperIn(t, elsewhere) awaitCWD(t, cmd.Process.Pid) - _, err := KillProcessesWithCWDUnder(context.Background(), []string{workspace}) + _, err := KillProcessesWithCWDUnder(t.Context(), []string{workspace}) require.NoError(t, err) require.True(t, processAlive(cmd.Process.Pid), "process outside owned dirs must be spared") } diff --git a/internal/pkg/process/treekill_test.go b/internal/pkg/process/treekill_test.go index 8f5dde15..53b99251 100644 --- a/internal/pkg/process/treekill_test.go +++ b/internal/pkg/process/treekill_test.go @@ -4,7 +4,6 @@ package process import ( - "context" "os/exec" "testing" @@ -12,7 +11,7 @@ import ( ) func TestNewTreeKillConfiguresCommand(t *testing.T) { - cmd := exec.CommandContext(context.Background(), "sleep", "1") + cmd := exec.CommandContext(t.Context(), "sleep", "1") tk := NewTreeKill(cmd) require.NotNil(t, tk) @@ -22,7 +21,7 @@ func TestNewTreeKillConfiguresCommand(t *testing.T) { } func TestTreeKillCaptureStoresKiller(t *testing.T) { - cmd := exec.CommandContext(context.Background(), "sleep", "10") + cmd := exec.CommandContext(t.Context(), "sleep", "10") cmd.SysProcAttr = SysProcAttr("", false) tk := NewTreeKill(cmd) require.NoError(t, cmd.Start()) diff --git a/internal/pkg/report/joblog_test.go b/internal/pkg/report/joblog_test.go index d65fe7ed..0bab3184 100644 --- a/internal/pkg/report/joblog_test.go +++ b/internal/pkg/report/joblog_test.go @@ -43,7 +43,7 @@ func TestJobLog_MirrorsUploadedRows(t *testing.T) { require.NoError(t, err) cfg.Log.Job.Dir = t.TempDir() - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) t.Cleanup(cancel) task := &runnerv1.Task{Id: 41, Context: &structpb.Struct{}, Secrets: map[string]string{"TOKEN": "s3cret-value"}} reporter := NewReporter(ctx, cancel, client, task, cfg) diff --git a/internal/pkg/report/reporter_test.go b/internal/pkg/report/reporter_test.go index 62bf0c81..442c48c9 100644 --- a/internal/pkg/report/reporter_test.go +++ b/internal/pkg/report/reporter_test.go @@ -244,7 +244,7 @@ func TestReporter_Handle(t *testing.T) { t.Logf("Received UpdateTask: %s", req.Msg.String()) return connect_go.NewResponse(&runnerv1.UpdateTaskResponse{}), nil }) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err) cfg, _ := config.LoadDefault("") @@ -305,7 +305,7 @@ func TestReporter_LogLevelFiltering(t *testing.T) { return connect_go.NewResponse(&runnerv1.UpdateTaskResponse{}), nil }) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err) cfg, _ := config.LoadDefault("") @@ -374,7 +374,7 @@ func TestReporter_EphemeralRunnerDeletion(t *testing.T) { }, ) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err) @@ -439,7 +439,7 @@ func TestReporter_RunDaemonClose_Race(t *testing.T) { }, ) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err) cfg, _ := config.LoadDefault("") @@ -481,7 +481,7 @@ func TestReporter_MaxLatencyTimer(t *testing.T) { }, ) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err) @@ -532,7 +532,7 @@ func TestReporter_BatchSizeFlush(t *testing.T) { }, ) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err) @@ -585,7 +585,7 @@ func TestReporter_StateChangedNotLostDuringReport(t *testing.T) { }, ) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err) @@ -646,7 +646,7 @@ func TestReporter_StateChangedRestoredOnError(t *testing.T) { }, ) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err) @@ -691,7 +691,7 @@ func TestReporter_StateNotifyFlush(t *testing.T) { }, ) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err) @@ -748,7 +748,7 @@ func TestReporter_CloseAlwaysSendsRowsWithNoMore(t *testing.T) { }, ) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err) @@ -799,7 +799,7 @@ func TestReporter_StateHeartbeat(t *testing.T) { }, ) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err) @@ -871,7 +871,7 @@ func TestReporter_ServerCancelStillFlushesFinal(t *testing.T) { }, ) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err) @@ -940,7 +940,7 @@ func TestReporter_CloseReportsCancelledOnCanceledCtx(t *testing.T) { }, ) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err) cfg, _ := config.LoadDefault("") @@ -999,7 +999,7 @@ func TestReporter_StopHeartbeats(t *testing.T) { }, ) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err) @@ -1112,7 +1112,7 @@ func TestReporter_DebugSettingsAreNotMasked(t *testing.T) { taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err) - reporter := NewReporter(context.Background(), nil, nil, &runnerv1.Task{ + reporter := NewReporter(t.Context(), nil, nil, &runnerv1.Task{ Context: taskCtx, Secrets: map[string]string{"ACTIONS_STEP_DEBUG": "true", "ACTIONS_RUNNER_DEBUG": "true", "TOKEN": "s3cr3t"}, }, &config.Config{}) @@ -1136,7 +1136,7 @@ func TestReporter_OutputsSentOnce(t *testing.T) { return connect_go.NewResponse(&runnerv1.UpdateTaskResponse{SentOutputs: slices.Collect(maps.Keys(req.Msg.Outputs))}), nil }) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err) @@ -1210,7 +1210,7 @@ func TestReporter_AckIndexBeyondBuffer(t *testing.T) { return connect_go.NewResponse(&runnerv1.UpdateLogResponse{AckIndex: 1000}), nil }) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err) @@ -1247,7 +1247,7 @@ func TestReporter_CloseWithStuckDaemon(t *testing.T) { return connect_go.NewResponse(&runnerv1.UpdateTaskResponse{}), nil }).Maybe() - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err) @@ -1294,7 +1294,7 @@ func TestReporter_ServerFailureResultIsReportedAsFailure(t *testing.T) { }), nil }).Maybe() - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err) @@ -1351,7 +1351,7 @@ func TestReporter_CloseMasksLastWords(t *testing.T) { }, ) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() const idToken = "id-token-request-secret" taskCtx, err := structpb.NewStruct(map[string]any{"actions_id_token_request_token": idToken}) @@ -1420,7 +1420,7 @@ func TestReporter_StepRangeCoversAckedRows(t *testing.T) { }, ) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err) @@ -1466,7 +1466,7 @@ func TestReporter_StepRangeCoversAckedRows(t *testing.T) { // A flush the server took no rows for describes nothing new, so it must not spend an // UpdateTask. UpdateTask is never registered on the client, so calling it fails the test. func TestReporter_FlushWithoutAckedRowsSkipsState(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() taskCtx, err := structpb.NewStruct(map[string]any{}) require.NoError(t, err)