From efac3296329877a7dd4d080dbdc9ab8ad64586dc Mon Sep 17 00:00:00 2001 From: Gabe Torres Date: Tue, 21 Nov 2023 18:38:55 -0800 Subject: [PATCH 1/6] add fail fast flag --- batch.yaml | 25 ++++++++++++++++++++ cmd/src/batch_apply.go | 17 +++++++++++--- cmd/src/batch_common.go | 29 ++++++++++++++++-------- cmd/src/batch_exec.go | 2 +- cmd/src/batch_preview.go | 14 ++++++++++-- cmd/src/cmd.go | 2 ++ hello.yaml | 20 ++++++++++++++++ internal/batches/executor/coordinator.go | 9 ++++++-- internal/batches/executor/executor.go | 5 +++- internal/batches/ui/tui.go | 4 ++++ 10 files changed, 108 insertions(+), 19 deletions(-) create mode 100644 batch.yaml create mode 100644 hello.yaml diff --git a/batch.yaml b/batch.yaml new file mode 100644 index 0000000000..7ab6d15e4b --- /dev/null +++ b/batch.yaml @@ -0,0 +1,25 @@ +name: failed-spec +description: testing failures + +on: + - repositoriesMatchingQuery: file:README.md + +steps: + - run: | + IFS=$'\n'; echo Hello World | tee -a $(find -name README.md) + sleep 5 + if: ${{ eq repository.name "github.com/sourcegraph-testing/markdowns" }} + container: alpine:3 + + - run: | + sleep 1 + exit 1 + if: ${{ eq repository.name "github.com/sourcegraph-testing/etcd" }} + container: alpine:3 + +changesetTemplate: + title: Hello World + body: My first batch change! + commit: + message: Append Hello World to all README.md files + branch: ${{ batch_change.name }} diff --git a/cmd/src/batch_apply.go b/cmd/src/batch_apply.go index 28f715656d..294be124c9 100644 --- a/cmd/src/batch_apply.go +++ b/cmd/src/batch_apply.go @@ -4,7 +4,7 @@ import ( "context" "flag" "fmt" - + "github.com/sourcegraph/src-cli/internal/batches/executor" "github.com/sourcegraph/src-cli/internal/cmderrors" ) @@ -42,9 +42,20 @@ Examples: } ctx, cancel := contextCancelOnInterrupt(context.Background()) - defer cancel() - if err = executeBatchSpec(ctx, executeBatchSpecOpts{ + defer cancel(nil) + + failFastCancel := func(error) {} + if flags.failFast { + failFastCancel = cancel + } + + cctx := executor.CancelableContext{ + Context: ctx, + Cancel: failFastCancel, + } + + if err = executeBatchSpec(cctx, executeBatchSpecOpts{ flags: flags, client: cfg.apiClient(flags.api, flagSet.Output()), file: file, diff --git a/cmd/src/batch_common.go b/cmd/src/batch_common.go index 57b248cf06..9b6ef886d5 100644 --- a/cmd/src/batch_common.go +++ b/cmd/src/batch_common.go @@ -91,6 +91,7 @@ type batchExecuteFlags struct { cleanArchives bool skipErrors bool runAsRoot bool + failFast bool // EXPERIMENTAL textOnly bool @@ -162,6 +163,10 @@ func newBatchExecuteFlags(flagSet *flag.FlagSet, cacheDir, tempDir string) *batc &caf.runAsRoot, "run-as-root", false, "If true, forces all step containers to run as root.", ) + flagSet.BoolVar( + &caf.failFast, "fail-fast", false, + "If true, deletes downloaded repository archives after executing batch spec steps. Note that only the archives related to the actual repositories matched by the batch spec will be cleaned up, and clean up will not occur if src exits unexpectedly.", + ) return caf } @@ -267,7 +272,7 @@ func createDockerWatchdog(ctx context.Context, execUI ui.ExecUI) *watchdog.Watch // executeBatchSpec performs all the steps required to upload the batch spec to // Sourcegraph, including execution as needed and applying the resulting batch // spec if specified. -func executeBatchSpec(ctx context.Context, opts executeBatchSpecOpts) (err error) { +func executeBatchSpec(ctx executor.CancelableContext, opts executeBatchSpecOpts) (err error) { var execUI ui.ExecUI if opts.flags.textOnly { execUI = &ui.JSONLines{} @@ -282,6 +287,9 @@ func executeBatchSpec(ctx context.Context, opts executeBatchSpecOpts) (err error defer func() { w.Stop() if err != nil { + if cerr := context.Cause(ctx); cerr != nil { + err = cerr + } execUI.ExecutionError(err) } }() @@ -463,6 +471,11 @@ func executeBatchSpec(ctx context.Context, opts executeBatchSpecOpts) (err error taskExecUI := execUI.ExecutingTasks(*verbose, parallelism) freshSpecs, logFiles, execErr := coord.ExecuteAndBuildSpecs(ctx, batchSpec, uncachedTasks, taskExecUI) + + if len(logFiles) > 0 && opts.flags.keepLogs { + execUI.LogFilesKept(logFiles) + } + // Add external changeset specs. importedSpecs, importErr := svc.CreateImportChangesetSpecs(ctx, batchSpec) if execErr != nil { @@ -487,10 +500,6 @@ func executeBatchSpec(ctx context.Context, opts executeBatchSpecOpts) (err error } } - if len(logFiles) > 0 && opts.flags.keepLogs { - execUI.LogFilesKept(logFiles) - } - specs = append(specs, freshSpecs...) specs = append(specs, importedSpecs...) @@ -628,22 +637,22 @@ func checkExecutable(cmd string, args ...string) error { return nil } -func contextCancelOnInterrupt(parent context.Context) (context.Context, func()) { - ctx, ctxCancel := context.WithCancel(parent) +func contextCancelOnInterrupt(parent context.Context) (context.Context, func(error)) { + ctx, ctxCancel := context.WithCancelCause(parent) c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt) go func() { select { case <-c: - ctxCancel() + ctxCancel(errors.New("Ctrl C hit")) case <-ctx.Done(): } }() - return ctx, func() { + return ctx, func(err error) { signal.Stop(c) - ctxCancel() + ctxCancel(err) } } diff --git a/cmd/src/batch_exec.go b/cmd/src/batch_exec.go index 11aadf39e3..6ab0e65919 100644 --- a/cmd/src/batch_exec.go +++ b/cmd/src/batch_exec.go @@ -101,7 +101,7 @@ Examples: } ctx, cancel := contextCancelOnInterrupt(context.Background()) - defer cancel() + defer cancel(errors.New("3")) err := executeBatchSpecInWorkspaces(ctx, flags) if err != nil { diff --git a/cmd/src/batch_preview.go b/cmd/src/batch_preview.go index 8226bb5459..5f69e44a98 100644 --- a/cmd/src/batch_preview.go +++ b/cmd/src/batch_preview.go @@ -4,6 +4,8 @@ import ( "context" "flag" "fmt" + "github.com/sourcegraph/sourcegraph/lib/errors" + "github.com/sourcegraph/src-cli/internal/batches/executor" "github.com/sourcegraph/src-cli/internal/cmderrors" ) @@ -40,9 +42,17 @@ Examples: } ctx, cancel := contextCancelOnInterrupt(context.Background()) - defer cancel() + defer cancel(errors.New("2")) + failFastCancel := func(error) {} + if flags.failFast { + failFastCancel = cancel + } + cctx := executor.CancelableContext{ + Context: ctx, + Cancel: failFastCancel, + } - if err = executeBatchSpec(ctx, executeBatchSpecOpts{ + if err = executeBatchSpec(cctx, executeBatchSpecOpts{ flags: flags, client: cfg.apiClient(flags.api, flagSet.Output()), file: file, diff --git a/cmd/src/cmd.go b/cmd/src/cmd.go index 96a6fcec9e..a39077ef4f 100644 --- a/cmd/src/cmd.go +++ b/cmd/src/cmd.go @@ -95,7 +95,9 @@ func (c commander) run(flagSet *flag.FlagSet, cmdName, usageText string, args [] // Execute the subcommand. if err := cmd.handler(flagSet.Args()[1:]); err != nil { + fmt.Println(2222, err) if _, ok := err.(*cmderrors.UsageError); ok { + fmt.Println(3333) log.Printf("error: %s\n\n", err) cmd.flagSet.Usage() os.Exit(2) diff --git a/hello.yaml b/hello.yaml new file mode 100644 index 0000000000..574eb9bbf6 --- /dev/null +++ b/hello.yaml @@ -0,0 +1,20 @@ +name: hello-world +description: Add Hello World to READMEs + +# Find all repositories that contain a README.md file. +on: + - repositoriesMatchingQuery: file:README.md + +# In each repository, run this command. Each repository's resulting diff is captured. +steps: + - run: IFS=$'\n'; echo Hello World | tee -a $(find -name README.md) + container: alpine:3 + +# Describe the changeset (e.g., GitHub pull request) you want for each repository. +changesetTemplate: + title: Hello World + body: My first batch change! + branch: hello-world # Push the commit to this branch. + commit: + message: Append Hello World to all README.md files + published: false # Do not publish any changes to the code hosts yet diff --git a/internal/batches/executor/coordinator.go b/internal/batches/executor/coordinator.go index 15855f5d37..322c8f004b 100644 --- a/internal/batches/executor/coordinator.go +++ b/internal/batches/executor/coordinator.go @@ -13,10 +13,15 @@ import ( ) type taskExecutor interface { - Start(context.Context, []*Task, TaskExecutionUI) + Start(CancelableContext, []*Task, TaskExecutionUI) Wait(context.Context) ([]taskResult, error) } +type CancelableContext struct { + context.Context + Cancel context.CancelCauseFunc +} + // Coordinator coordinates the execution of Tasks. It makes use of an executor, // checks the ExecutionCache whether execution is necessary, and builds // batcheslib.ChangesetSpecs out of the executionResults. @@ -177,7 +182,7 @@ func (c *Coordinator) buildSpecs(ctx context.Context, batchSpec *batcheslib.Batc // ExecuteAndBuildSpecs executes the given tasks and builds changeset specs for the results. // It calls the ui on updates. -func (c *Coordinator) ExecuteAndBuildSpecs(ctx context.Context, batchSpec *batcheslib.BatchSpec, tasks []*Task, ui TaskExecutionUI) ([]*batcheslib.ChangesetSpec, []string, error) { +func (c *Coordinator) ExecuteAndBuildSpecs(ctx CancelableContext, batchSpec *batcheslib.BatchSpec, tasks []*Task, ui TaskExecutionUI) ([]*batcheslib.ChangesetSpec, []string, error) { ui.Start(tasks) // Run executor. diff --git a/internal/batches/executor/executor.go b/internal/batches/executor/executor.go index 9ccb94a8fc..16254cbd24 100644 --- a/internal/batches/executor/executor.go +++ b/internal/batches/executor/executor.go @@ -92,9 +92,11 @@ func NewExecutor(opts NewExecutorOpts) *executor { } } +var ErrFastFail = errors.New("Canceled due to fast fail") + // Start starts the execution of the given Tasks in goroutines, calling the // given taskStatusHandler to update the progress of the tasks. -func (x *executor) Start(ctx context.Context, tasks []*Task, ui TaskExecutionUI) { +func (x *executor) Start(ctx CancelableContext, tasks []*Task, ui TaskExecutionUI) { defer func() { close(x.doneEnqueuing) }() for _, task := range tasks { @@ -115,6 +117,7 @@ func (x *executor) Start(ctx context.Context, tasks []*Task, ui TaskExecutionUI) default: err := x.do(ctx, task, ui) if err != nil { + ctx.Cancel(ErrFastFail) x.par.Error(err) } } diff --git a/internal/batches/ui/tui.go b/internal/batches/ui/tui.go index 94724909b1..b046327026 100644 --- a/internal/batches/ui/tui.go +++ b/internal/batches/ui/tui.go @@ -363,16 +363,20 @@ func printExecutionError(out *output.Output, err error) { if len(errs) > 1 { block = out.Block(output.Linef(output.EmojiFailure, output.StyleWarning, "%d errors:", len(errs))) } else { + //fmt.Println("errs", errs) block = out.Block(output.Line(output.EmojiFailure, output.StyleWarning, "Error:")) } for _, e := range errs { if taskErr, ok := e.(executor.TaskExecutionErr); ok { + //fmt.Println("HELLO") block.Write(formatTaskExecutionErr(taskErr)) } else { if err == context.Canceled { + //fmt.Println("HELLO 2") block.Writef("%sAborting", output.StyleBold) } else { + //fmt.Println("HELLO 3") block.Writef("%s%s", output.StyleBold, e.Error()) } } From 90cede42a7118466acceb9407f30eea5f44e81fb Mon Sep 17 00:00:00 2001 From: Gabe Torres Date: Tue, 21 Nov 2023 22:37:48 -0800 Subject: [PATCH 2/6] update flag description and errors --- batch.yaml | 25 ------------------------- cmd/src/batch_common.go | 6 +++--- cmd/src/batch_exec.go | 2 +- cmd/src/batch_preview.go | 6 ++++-- cmd/src/cmd.go | 2 -- hello.yaml | 20 -------------------- internal/batches/executor/executor.go | 2 +- internal/batches/ui/tui.go | 4 ---- 8 files changed, 9 insertions(+), 58 deletions(-) delete mode 100644 batch.yaml delete mode 100644 hello.yaml diff --git a/batch.yaml b/batch.yaml deleted file mode 100644 index 7ab6d15e4b..0000000000 --- a/batch.yaml +++ /dev/null @@ -1,25 +0,0 @@ -name: failed-spec -description: testing failures - -on: - - repositoriesMatchingQuery: file:README.md - -steps: - - run: | - IFS=$'\n'; echo Hello World | tee -a $(find -name README.md) - sleep 5 - if: ${{ eq repository.name "github.com/sourcegraph-testing/markdowns" }} - container: alpine:3 - - - run: | - sleep 1 - exit 1 - if: ${{ eq repository.name "github.com/sourcegraph-testing/etcd" }} - container: alpine:3 - -changesetTemplate: - title: Hello World - body: My first batch change! - commit: - message: Append Hello World to all README.md files - branch: ${{ batch_change.name }} diff --git a/cmd/src/batch_common.go b/cmd/src/batch_common.go index 9b6ef886d5..6d219e3da0 100644 --- a/cmd/src/batch_common.go +++ b/cmd/src/batch_common.go @@ -165,7 +165,7 @@ func newBatchExecuteFlags(flagSet *flag.FlagSet, cacheDir, tempDir string) *batc ) flagSet.BoolVar( &caf.failFast, "fail-fast", false, - "If true, deletes downloaded repository archives after executing batch spec steps. Note that only the archives related to the actual repositories matched by the batch spec will be cleaned up, and clean up will not occur if src exits unexpectedly.", + "If true, errors encountered while executing steps in a repository will stop the execution of the batch spec.", ) return caf @@ -475,7 +475,7 @@ func executeBatchSpec(ctx executor.CancelableContext, opts executeBatchSpecOpts) if len(logFiles) > 0 && opts.flags.keepLogs { execUI.LogFilesKept(logFiles) } - + // Add external changeset specs. importedSpecs, importErr := svc.CreateImportChangesetSpecs(ctx, batchSpec) if execErr != nil { @@ -645,7 +645,7 @@ func contextCancelOnInterrupt(parent context.Context) (context.Context, func(err go func() { select { case <-c: - ctxCancel(errors.New("Ctrl C hit")) + ctxCancel(errors.New("Ctrl-C hit")) case <-ctx.Done(): } }() diff --git a/cmd/src/batch_exec.go b/cmd/src/batch_exec.go index 6ab0e65919..4fa28ab02e 100644 --- a/cmd/src/batch_exec.go +++ b/cmd/src/batch_exec.go @@ -101,7 +101,7 @@ Examples: } ctx, cancel := contextCancelOnInterrupt(context.Background()) - defer cancel(errors.New("3")) + defer cancel(nil) err := executeBatchSpecInWorkspaces(ctx, flags) if err != nil { diff --git a/cmd/src/batch_preview.go b/cmd/src/batch_preview.go index 5f69e44a98..c216c02fa3 100644 --- a/cmd/src/batch_preview.go +++ b/cmd/src/batch_preview.go @@ -4,7 +4,6 @@ import ( "context" "flag" "fmt" - "github.com/sourcegraph/sourcegraph/lib/errors" "github.com/sourcegraph/src-cli/internal/batches/executor" "github.com/sourcegraph/src-cli/internal/cmderrors" @@ -42,11 +41,14 @@ Examples: } ctx, cancel := contextCancelOnInterrupt(context.Background()) - defer cancel(errors.New("2")) + + defer cancel(nil) + failFastCancel := func(error) {} if flags.failFast { failFastCancel = cancel } + cctx := executor.CancelableContext{ Context: ctx, Cancel: failFastCancel, diff --git a/cmd/src/cmd.go b/cmd/src/cmd.go index a39077ef4f..96a6fcec9e 100644 --- a/cmd/src/cmd.go +++ b/cmd/src/cmd.go @@ -95,9 +95,7 @@ func (c commander) run(flagSet *flag.FlagSet, cmdName, usageText string, args [] // Execute the subcommand. if err := cmd.handler(flagSet.Args()[1:]); err != nil { - fmt.Println(2222, err) if _, ok := err.(*cmderrors.UsageError); ok { - fmt.Println(3333) log.Printf("error: %s\n\n", err) cmd.flagSet.Usage() os.Exit(2) diff --git a/hello.yaml b/hello.yaml deleted file mode 100644 index 574eb9bbf6..0000000000 --- a/hello.yaml +++ /dev/null @@ -1,20 +0,0 @@ -name: hello-world -description: Add Hello World to READMEs - -# Find all repositories that contain a README.md file. -on: - - repositoriesMatchingQuery: file:README.md - -# In each repository, run this command. Each repository's resulting diff is captured. -steps: - - run: IFS=$'\n'; echo Hello World | tee -a $(find -name README.md) - container: alpine:3 - -# Describe the changeset (e.g., GitHub pull request) you want for each repository. -changesetTemplate: - title: Hello World - body: My first batch change! - branch: hello-world # Push the commit to this branch. - commit: - message: Append Hello World to all README.md files - published: false # Do not publish any changes to the code hosts yet diff --git a/internal/batches/executor/executor.go b/internal/batches/executor/executor.go index 16254cbd24..06c12c18ab 100644 --- a/internal/batches/executor/executor.go +++ b/internal/batches/executor/executor.go @@ -92,7 +92,7 @@ func NewExecutor(opts NewExecutorOpts) *executor { } } -var ErrFastFail = errors.New("Canceled due to fast fail") +var ErrFastFail = errors.New("Execution stopped due to fast-fail mode.") // Start starts the execution of the given Tasks in goroutines, calling the // given taskStatusHandler to update the progress of the tasks. diff --git a/internal/batches/ui/tui.go b/internal/batches/ui/tui.go index b046327026..94724909b1 100644 --- a/internal/batches/ui/tui.go +++ b/internal/batches/ui/tui.go @@ -363,20 +363,16 @@ func printExecutionError(out *output.Output, err error) { if len(errs) > 1 { block = out.Block(output.Linef(output.EmojiFailure, output.StyleWarning, "%d errors:", len(errs))) } else { - //fmt.Println("errs", errs) block = out.Block(output.Line(output.EmojiFailure, output.StyleWarning, "Error:")) } for _, e := range errs { if taskErr, ok := e.(executor.TaskExecutionErr); ok { - //fmt.Println("HELLO") block.Write(formatTaskExecutionErr(taskErr)) } else { if err == context.Canceled { - //fmt.Println("HELLO 2") block.Writef("%sAborting", output.StyleBold) } else { - //fmt.Println("HELLO 3") block.Writef("%s%s", output.StyleBold, e.Error()) } } From 46302c498ca63b0a186feca91980c303d0e702c9 Mon Sep 17 00:00:00 2001 From: Gabe Torres Date: Wed, 29 Nov 2023 16:30:39 -0800 Subject: [PATCH 3/6] fix tests --- internal/batches/executor/coordinator_test.go | 13 +++++++-- internal/batches/executor/executor.go | 2 +- internal/batches/executor/executor_test.go | 29 ++++++++++++++++--- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/internal/batches/executor/coordinator_test.go b/internal/batches/executor/coordinator_test.go index 9ce252cda3..eb862b1dfd 100644 --- a/internal/batches/executor/coordinator_test.go +++ b/internal/batches/executor/coordinator_test.go @@ -269,6 +269,9 @@ func TestCoordinator_Execute(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { ctx := context.Background() + cctx := CancelableContext{ + Context: ctx, + } // Set attributes on Task which would be set by the TaskBuilder for _, t := range tc.tasks { @@ -294,7 +297,7 @@ func TestCoordinator_Execute(t *testing.T) { // the batch spec. We'll run this multiple times to cover both the // cache and non-cache code paths. execute := func(t *testing.T) { - specs, _, err := coord.ExecuteAndBuildSpecs(ctx, tc.batchSpec, tc.tasks, newDummyTaskExecutionUI()) + specs, _, err := coord.ExecuteAndBuildSpecs(cctx, tc.batchSpec, tc.tasks, newDummyTaskExecutionUI()) if tc.wantErrInclude == "" { if err != nil { t.Fatalf("execution failed: %s", err) @@ -439,6 +442,10 @@ func TestCoordinator_Execute_StepCaching(t *testing.T) { // in a new Coordinator, setting cb as the startCallback on the executor. func execAndEnsure(t *testing.T, coord *Coordinator, exec *dummyExecutor, batchSpec *batcheslib.BatchSpec, task *Task, cb startCallback) { t.Helper() + ctx := context.Background() + cctx := CancelableContext{ + Context: ctx, + } // Setup the callback exec.startCb = cb @@ -450,7 +457,7 @@ func execAndEnsure(t *testing.T, coord *Coordinator, exec *dummyExecutor, batchS } // Execute - freshSpecs, _, err := coord.ExecuteAndBuildSpecs(context.Background(), batchSpec, uncached, newDummyTaskExecutionUI()) + freshSpecs, _, err := coord.ExecuteAndBuildSpecs(cctx, batchSpec, uncached, newDummyTaskExecutionUI()) if err != nil { t.Fatalf("execution of task failed: %s", err) } @@ -554,7 +561,7 @@ type dummyExecutor struct { waitErr error } -func (d *dummyExecutor) Start(ctx context.Context, ts []*Task, ui TaskExecutionUI) { +func (d *dummyExecutor) Start(ctx CancelableContext, ts []*Task, ui TaskExecutionUI) { if d.startCb != nil { d.startCb(ctx, ts, ui) d.startCbCalled = true diff --git a/internal/batches/executor/executor.go b/internal/batches/executor/executor.go index 06c12c18ab..08bccddac0 100644 --- a/internal/batches/executor/executor.go +++ b/internal/batches/executor/executor.go @@ -98,8 +98,8 @@ var ErrFastFail = errors.New("Execution stopped due to fast-fail mode.") // given taskStatusHandler to update the progress of the tasks. func (x *executor) Start(ctx CancelableContext, tasks []*Task, ui TaskExecutionUI) { defer func() { close(x.doneEnqueuing) }() - for _, task := range tasks { + fmt.Println(task.Repository) select { case <-ctx.Done(): return diff --git a/internal/batches/executor/executor_test.go b/internal/batches/executor/executor_test.go index c4accc0f87..8c93b03ca6 100644 --- a/internal/batches/executor/executor_test.go +++ b/internal/batches/executor/executor_test.go @@ -175,7 +175,6 @@ func TestExecutor_Integration(t *testing.T) { }, {Run: `touch output-${{ outputs.myOutput }}`}, }, - tasks: []*Task{ {Repository: testRepo1}, }, @@ -396,8 +395,26 @@ func TestExecutor_Integration(t *testing.T) { dummyUI := newDummyTaskExecutionUI() executor := NewExecutor(opts) + ctx := context.Background() + cctx := CancelableContext{ + Context: ctx, + } // Run executor - executor.Start(context.Background(), tc.tasks, dummyUI) + fmt.Println("HELLO FROM EXECUTOR") + fmt.Println("tc.tasks", tc.name) + fmt.Println("tc.tasks", tc.archives) + + fmt.Println("tc.tasks", tc.steps) + + fmt.Println("tc.tasks", tc.tasks) + fmt.Println("tc.tasks", tc.executorTimeout) + + fmt.Println("tc.tasks", tc.wantErrInclude) + fmt.Println("tc.tasks", tc.wantFinishedWithErr) + + fmt.Println("dummyUI", dummyUI) + + executor.Start(cctx, tc.tasks, dummyUI) results, err := executor.Wait(context.Background()) if tc.wantErrInclude == "" { @@ -809,8 +826,12 @@ func testExecuteTasks(t *testing.T, tasks []*Task, archives ...mock.RepoArchive) Parallelism: runtime.GOMAXPROCS(0), Timeout: 30 * time.Second, }) - - executor.Start(context.Background(), tasks, newDummyTaskExecutionUI()) + ctx := context.Background() + cctx := CancelableContext{ + Context: ctx, + } + fmt.Println("START HERE") + executor.Start(cctx, tasks, newDummyTaskExecutionUI()) return executor.Wait(context.Background()) } From 8c690e632601cde1968f0aecbb79717183345bc9 Mon Sep 17 00:00:00 2001 From: Gabe Torres Date: Wed, 29 Nov 2023 18:24:16 -0800 Subject: [PATCH 4/6] fix panic in test --- internal/batches/executor/executor_test.go | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/internal/batches/executor/executor_test.go b/internal/batches/executor/executor_test.go index 8c93b03ca6..88bbe38f41 100644 --- a/internal/batches/executor/executor_test.go +++ b/internal/batches/executor/executor_test.go @@ -396,24 +396,13 @@ func TestExecutor_Integration(t *testing.T) { executor := NewExecutor(opts) ctx := context.Background() + failFastCancel := func(error) {} cctx := CancelableContext{ Context: ctx, + Cancel: failFastCancel, } - // Run executor - fmt.Println("HELLO FROM EXECUTOR") - fmt.Println("tc.tasks", tc.name) - fmt.Println("tc.tasks", tc.archives) - - fmt.Println("tc.tasks", tc.steps) - - fmt.Println("tc.tasks", tc.tasks) - fmt.Println("tc.tasks", tc.executorTimeout) - - fmt.Println("tc.tasks", tc.wantErrInclude) - fmt.Println("tc.tasks", tc.wantFinishedWithErr) - - fmt.Println("dummyUI", dummyUI) + // Run executor executor.Start(cctx, tc.tasks, dummyUI) results, err := executor.Wait(context.Background()) From c0daa6d68bee446f800f6093dc98c88645a8bab1 Mon Sep 17 00:00:00 2001 From: Gabe Torres Date: Wed, 29 Nov 2023 19:48:37 -0800 Subject: [PATCH 5/6] lint fix --- cmd/src/batch_apply.go | 1 + cmd/src/batch_preview.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/src/batch_apply.go b/cmd/src/batch_apply.go index 294be124c9..0de796d3c9 100644 --- a/cmd/src/batch_apply.go +++ b/cmd/src/batch_apply.go @@ -4,6 +4,7 @@ import ( "context" "flag" "fmt" + "github.com/sourcegraph/src-cli/internal/batches/executor" "github.com/sourcegraph/src-cli/internal/cmderrors" ) diff --git a/cmd/src/batch_preview.go b/cmd/src/batch_preview.go index c216c02fa3..fc50982915 100644 --- a/cmd/src/batch_preview.go +++ b/cmd/src/batch_preview.go @@ -4,8 +4,8 @@ import ( "context" "flag" "fmt" - "github.com/sourcegraph/src-cli/internal/batches/executor" + "github.com/sourcegraph/src-cli/internal/batches/executor" "github.com/sourcegraph/src-cli/internal/cmderrors" ) From 60d0cf3c5f44ba9ef2927041e13a99ebdd3e42f1 Mon Sep 17 00:00:00 2001 From: Gabe Torres Date: Wed, 29 Nov 2023 21:07:46 -0800 Subject: [PATCH 6/6] remove debug log --- internal/batches/executor/executor_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/batches/executor/executor_test.go b/internal/batches/executor/executor_test.go index 88bbe38f41..730b0e9304 100644 --- a/internal/batches/executor/executor_test.go +++ b/internal/batches/executor/executor_test.go @@ -819,7 +819,6 @@ func testExecuteTasks(t *testing.T, tasks []*Task, archives ...mock.RepoArchive) cctx := CancelableContext{ Context: ctx, } - fmt.Println("START HERE") executor.Start(cctx, tasks, newDummyTaskExecutionUI()) return executor.Wait(context.Background()) }