1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-10 22:42:00 +02:00

Improve debugging of integration tests (#3029)

Several improvements to make debugging integration tests work better.
This commit is contained in:
Stefan Haller
2023-09-28 10:04:23 +02:00
committed by GitHub
4 changed files with 20 additions and 9 deletions

View File

@@ -623,7 +623,10 @@ func (gui *Gui) Run(startArgs appTypes.StartArgs) error {
deadlock.Opts.LogBuf = utils.NewOnceWriter(os.Stderr, func() {
gui.g.Close()
})
deadlock.Opts.Disable = !gui.Debug
// disable deadlock reporting if we're not running in debug mode, or if
// we're debugging an integration test. In this latter case, stopping at
// breakpoints and stepping through code can easily take more than 30s.
deadlock.Opts.Disable = !gui.Debug || os.Getenv(components.WAIT_FOR_DEBUGGER_ENV_VAR) == ""
if err := gui.Config.ReloadUserConfig(); err != nil {
return nil

View File

@@ -45,10 +45,12 @@ func (gui *Gui) handleTestMode() {
log.Fatal("gocui should have already exited")
}()
go utils.Safe(func() {
time.Sleep(time.Second * 40)
log.Fatal("40 seconds is up, lazygit recording took too long to complete")
})
if os.Getenv(components.WAIT_FOR_DEBUGGER_ENV_VAR) == "" {
go utils.Safe(func() {
time.Sleep(time.Second * 40)
log.Fatal("40 seconds is up, lazygit recording took too long to complete")
})
}
}
}

View File

@@ -31,7 +31,7 @@ func main() {
integrationTest := getIntegrationTest()
if os.Getenv("WAIT_FOR_DEBUGGER") != "" {
if os.Getenv(components.WAIT_FOR_DEBUGGER_ENV_VAR) != "" {
println("Waiting for debugger to attach...")
for !isDebuggerAttached() {
time.Sleep(time.Millisecond * 100)

View File

@@ -16,6 +16,7 @@ import (
const (
TEST_NAME_ENV_VAR = "TEST_NAME"
SANDBOX_ENV_VAR = "SANDBOX"
WAIT_FOR_DEBUGGER_ENV_VAR = "WAIT_FOR_DEBUGGER"
GIT_CONFIG_GLOBAL_ENV_VAR = "GIT_CONFIG_GLOBAL"
)
@@ -42,7 +43,7 @@ func RunTests(
testDir := filepath.Join(projectRootDir, "test", "_results")
if err := buildLazygit(raceDetector); err != nil {
if err := buildLazygit(waitForDebugger, raceDetector); err != nil {
return err
}
@@ -138,12 +139,17 @@ func prepareTestDir(
return createFixture(test, paths, rootDir)
}
func buildLazygit(raceDetector bool) error {
func buildLazygit(debug bool, raceDetector bool) error {
// // TODO: remove this line!
// // skipping this because I'm not making changes to the app code atm.
// return nil
args := []string{"go", "build"}
if debug {
// Disable compiler optimizations (-N) and inlining (-l) because this
// makes debugging work better
args = append(args, "-gcflags=all=-N -l")
}
if raceDetector {
args = append(args, "-race")
}
@@ -210,7 +216,7 @@ func getLazygitCommand(test *IntegrationTest, paths Paths, rootDir string, sandb
cmdObj.AddEnvVars(fmt.Sprintf("%s=%s", SANDBOX_ENV_VAR, "true"))
}
if waitForDebugger {
cmdObj.AddEnvVars("WAIT_FOR_DEBUGGER=true")
cmdObj.AddEnvVars(fmt.Sprintf("%s=true", WAIT_FOR_DEBUGGER_ENV_VAR))
}
// Set a race detector log path only to avoid spamming the terminal with the
// logs. We are not showing this anywhere yet.