jesseduffield.lazygit/pkg/gui/test_mode.go
Stefan Haller 7fce58b09b Scale the integration test watchdog up under the race detector
The integration test watchdog fails a test if its recording takes longer
than 40 seconds. Under the race detector everything runs several times
slower, so legitimately slow tests (e.g. a conflicting interactive
rebase) blow that budget and fail even though nothing is actually stuck.

Key the timeout off a build-tag constant: the `race` tag is set
automatically when the binary is built with -race, so a race build gets
a 5x-longer budget while a normal build is unchanged, and the two can't
drift apart the way a runtime flag would. The base 40s stays in one
place; only the multiplier varies by build.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-20 14:26:25 +02:00

60 lines
1.3 KiB
Go

package gui
import (
"log"
"os"
"time"
"github.com/jesseduffield/lazygit/pkg/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/popup"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/integration/components"
"github.com/jesseduffield/lazygit/pkg/utils"
)
type IntegrationTest interface {
Run(*GuiDriver)
}
func (gui *Gui) handleTestMode() {
test := gui.integrationTest
if os.Getenv(components.SANDBOX_ENV_VAR) == "true" {
return
}
if test != nil {
waitUntilIdle := func() {
gui.c.GocuiGui().WaitUntilIdle()
}
go func() {
waitUntilIdle()
toastChan := make(chan string, 100)
gui.PopupHandler.(*popup.PopupHandler).SetToastFunc(
func(message string, kind types.ToastKind) { toastChan <- message })
test.Run(&GuiDriver{gui: gui, toastChan: toastChan, headless: Headless()})
gui.g.Update(func(*gocui.Gui) error {
return gocui.ErrQuit
})
// Wait for the event loop to actually exit.
<-gui.g.LoopExited()
}()
if os.Getenv(components.WAIT_FOR_DEBUGGER_ENV_VAR) == "" {
timeout := 40 * time.Second * testTimeoutMultiplier
go utils.Safe(func() {
time.Sleep(timeout)
log.Fatalf("%v is up, lazygit integration test took too long to complete", timeout)
})
}
}
}
func Headless() bool {
return os.Getenv("LAZYGIT_HEADLESS") != ""
}