Skip to content

test: stabilize TestRebase_interactiveRetryPreservesTerminal on Windows#1227

Merged
abhinav merged 1 commit into
mainfrom
ed-irl/fix-windows-rebase-flake
Jun 7, 2026
Merged

test: stabilize TestRebase_interactiveRetryPreservesTerminal on Windows#1227
abhinav merged 1 commit into
mainfrom
ed-irl/fix-windows-rebase-flake

Conversation

@ed-irl

@ed-irl ed-irl commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • TestRebase_interactiveRetryPreservesTerminal flakes on Windows because the test relies on a goroutine sleeping 20ms before removing a fake .git/index.lock. On Windows runners the scheduler doesn't always release the goroutine before the retry path runs — when it doesn't, the test sees the lock still present and fails.
  • Replace the goroutine + sleep with atomic lock removal in the first mock call. The lock is removed before the mock returns the lock-conflict error, so when the retry path executes there is no timing dependency to lose.

Before

go func() {
    time.Sleep(20 * time.Millisecond)
    _ = os.Remove(lockPath)
}()

mockExec.EXPECT().
    Run(gomock.Any()).
    DoAndReturn(func(cmd *exec.Cmd) error {
        _, _ = fmt.Fprintln(cmd.Stderr, "fatal: Unable to create '.git/index.lock'")
        return &exec.ExitError{}
    })

After

mockExec.EXPECT().
    Run(gomock.Any()).
    DoAndReturn(func(cmd *exec.Cmd) error {
        // Remove the lock before returning the lock-conflict
        // error so the retry path observes a clean state.
        _ = os.Remove(lockPath)
        _, _ = fmt.Fprintln(cmd.Stderr, "fatal: Unable to create '.git/index.lock'")
        return &exec.ExitError{}
    })

No sleep, no goroutine, no race.

Why this matters

The flake masked CI on multiple unrelated PRs in the current stack (e.g. #1221), wasting workflow runs and obscuring real failures. Fix is independent of any feature work.

Test plan

  • go test -run TestRebase_interactiveRetryPreservesTerminal -count=10 ./internal/git/ — 10/10 passing locally
  • Verify on Windows CI runner once this lands

@ed-irl

ed-irl commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator Author

removing the lock. On Windows runners the scheduler occasionally
didn't release the goroutine in time, so the retry path observed
the lock still present and the test failed.

Remove the goroutine entirely. The first mock call (which
simulates git's lock-conflict failure) now removes the lock
atomically before returning the error, so by the time the retry
path runs there is no timing dependency. No sleep, no goroutine,
no race.
@ed-irl ed-irl force-pushed the ed-irl/fix-windows-rebase-flake branch from a96fc2a to b4ac703 Compare June 7, 2026 09:58
@ed-irl ed-irl marked this pull request as ready for review June 7, 2026 12:28
@abhinav abhinav merged commit 5ec60f0 into main Jun 7, 2026
25 of 31 checks passed
@abhinav abhinav deleted the ed-irl/fix-windows-rebase-flake branch June 7, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip changelog PRs that don't need a changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants