fix: respect signal cancellation in waza run#279
Merged
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Updates waza run to propagate OS signal cancellation into the long-running benchmark execution so Ctrl+C / termination signals can stop work promptly, and adds a regression test to verify cancellation is observed by the run path.
Changes:
- Wrap the benchmark execution context in
signal.NotifyContext(cmd.Context(), os.Interrupt, syscall.SIGTERM)and pass it intoRunBenchmark. - Add an injectable
newBenchmarkRunner(via a smallbenchmarkRunnerinterface) to allow test substitution. - Add a subprocess-based regression test that sends a signal and asserts the benchmark path exits via context cancellation.
Show a summary per file
| File | Description |
|---|---|
| cmd/waza/cmd_run.go | Introduces a cancellable signal-aware context for RunBenchmark and adds a test hook for runner construction. |
| cmd/waza/cmd_run_test.go | Resets the new runner-construction global in resetRunGlobals to avoid cross-test leakage. |
| cmd/waza/cmd_run_signal_test.go | Adds a regression test that validates signal-driven cancellation behavior using a blocking fake runner. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 2
- Use context.Background() when cmd is nil (test path) to prevent nil pointer dereference in signal.NotifyContext - Skip TestRunCommand_CancelsOnInterrupt on Windows where Process.Signal(SIGTERM) is not supported Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment on lines
+69
to
+81
| cmd := exec.CommandContext(ctx, os.Args[0], "-test.run=TestRunCommand_SignalCancelsBenchmarkHelperProcess") | ||
| cmd.Env = append(os.Environ(), | ||
| runSignalHelperEnv+"=1", | ||
| runSignalSpecEnv+"="+specPath, | ||
| ) | ||
| var stdout, stderr bytes.Buffer | ||
| cmd.Stdout = &stdout | ||
| cmd.Stderr = &stderr | ||
|
|
||
| require.NoError(t, cmd.Start()) | ||
| time.Sleep(200 * time.Millisecond) | ||
| require.NoError(t, cmd.Process.Signal(syscall.SIGTERM)) | ||
| require.NoError(t, cmd.Wait(), "run should exit cleanly after SIGTERM; stdout=%s stderr=%s", stdout.String(), stderr.String()) |
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #23
Summary
signal.NotifyContextfor the long-running benchmark path inwaza run.Validation
go test ./cmd/waza -run TestRunCommand_CancelsOnInterrupt -count=1make buildmake testcurrently fails inweb/node_modules/flatted/golang/pkg/flattedafternpm ci(unrelated repo issue)Documentation impact