Repository navigation
fix(adopt): handle CTRL+C cleanly during av adopt (#692) #749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mvanhorn
wants to merge
5
commits into
aviator-co:master
Choose a base branch
from
mvanhorn:fix/692-av-adopt-ctrl-c-cancellation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+197
−26
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d37bd32
fix(adopt): handle CTRL+C cleanly during av adopt (#692)
mvanhorn eaee61d
fix(adopt): route GetRemoteStackedPRModel state through Update()
mvanhorn ba7620b
test(adopt): SIGINT-exits-cleanly e2e for av adopt
mvanhorn 0e4190b
Merge remote-tracking branch 'upstream/master' into fix/692-av-adopt-…
mvanhorn 2ebc828
fix(adopt): run onDone in Update and share the terminal runner
mvanhorn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package e2e_tests | ||
|
|
||
| // TestAdoptExitsOnSIGINT lives outside the testscript harness because | ||
| // testscript v1.10.0 has no public API for sending arbitrary signals to a | ||
| // specifically named background process - it only sends os.Interrupt to | ||
| // every backgrounded command at end-of-test, which is not granular enough | ||
| // to verify that `av adopt` returns promptly after a single SIGINT while | ||
| // the merge-base step is still running. | ||
| // | ||
| // Once the project upgrades to a testscript version with a public | ||
| // signal-by-name primitive (or grows a custom command for it in | ||
| // testscript_test.go), this can move into testdata/script as a .txtar. | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/aviator-co/av/internal/git/gittest" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestAdoptExitsOnSIGINT(t *testing.T) { | ||
| if _, err := exec.LookPath("sh"); err != nil { | ||
| t.Skip("requires /bin/sh shim for the fake git binary") | ||
| } | ||
|
|
||
| repo := gittest.NewTempRepo(t) | ||
|
|
||
| repo.Git(t, "checkout", "-b", "stack-1") | ||
| repo.CommitFile(t, "my-file", "1a\n", gittest.WithMessage("Commit 1a")) | ||
| repo.Git(t, "switch", "main") | ||
|
|
||
| realGit, err := exec.LookPath("git") | ||
| require.NoError(t, err) | ||
|
|
||
| fakeGitDir := t.TempDir() | ||
| markerPath := filepath.Join(t.TempDir(), "merge-base-started") | ||
| fakeGitPath := filepath.Join(fakeGitDir, "git") | ||
| fakeGit := `#!/bin/sh | ||
| if [ "$1" = "merge-base" ]; then | ||
| if [ -n "$AV_TEST_GIT_MERGE_BASE_STARTED" ]; then | ||
| : > "$AV_TEST_GIT_MERGE_BASE_STARTED" | ||
| fi | ||
| exec sleep 30 | ||
| fi | ||
| exec "$REAL_GIT" "$@" | ||
| ` | ||
| require.NoError(t, os.WriteFile(fakeGitPath, []byte(fakeGit), 0o755)) | ||
|
|
||
| ctx, cancel := context.WithCancel(t.Context()) | ||
| defer cancel() | ||
| cmd := exec.CommandContext(ctx, avCmdPath, "--debug", "adopt", "--dry-run") | ||
| cmd.Dir = repo.RepoDir | ||
| cmd.Env = append( | ||
| os.Environ(), | ||
| "PATH="+fakeGitDir+string(os.PathListSeparator)+os.Getenv("PATH"), | ||
| "REAL_GIT="+realGit, | ||
| "AV_TEST_GIT_MERGE_BASE_STARTED="+markerPath, | ||
| ) | ||
| var stdout, stderr bytes.Buffer | ||
| cmd.Stdout = &stdout | ||
| cmd.Stderr = &stderr | ||
|
|
||
| require.NoError(t, cmd.Start()) | ||
| waitForFile(t, markerPath, 2*time.Second) | ||
|
|
||
| require.NoError(t, cmd.Process.Signal(os.Interrupt)) | ||
| done := make(chan error, 1) | ||
| go func() { | ||
| done <- cmd.Wait() | ||
| }() | ||
|
|
||
| select { | ||
| case <-done: | ||
| // av returned within the deadline; that's the success path. The exit | ||
| // code is non-zero because the run was cancelled, which is fine. | ||
| case <-time.After(5 * time.Second): | ||
| _ = cmd.Process.Kill() | ||
| t.Fatalf("av adopt did not exit within 5s of SIGINT\nstdout:\n%s\nstderr:\n%s", stdout.String(), stderr.String()) | ||
| } | ||
| } | ||
|
|
||
| func waitForFile(t *testing.T, path string, timeout time.Duration) { | ||
| t.Helper() | ||
| deadline := time.Now().Add(timeout) | ||
| for time.Now().Before(deadline) { | ||
| if _, err := os.Stat(path); err == nil { | ||
| return | ||
| } | ||
| time.Sleep(20 * time.Millisecond) | ||
| } | ||
| t.Fatalf("file %s did not appear within %s", path, timeout) | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.