From 96225fb6159212a8851043a08d781aba721b4e78 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 4 Mar 2026 20:19:37 +0200 Subject: Fix Go mistake findings and stabilize integration timing --- internal/flags/flags_test.go | 4 ---- internal/flamegraph/liveserver.go | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'internal') diff --git a/internal/flags/flags_test.go b/internal/flags/flags_test.go index 81d01ad..54c65b8 100644 --- a/internal/flags/flags_test.go +++ b/internal/flags/flags_test.go @@ -5,7 +5,6 @@ import ( "io" "os" "strings" - "sync" "testing" "time" ) @@ -16,7 +15,6 @@ func parseForTest(t *testing.T, args ...string) (Flags, error) { oldCommandLine := flag.CommandLine oldArgs := os.Args oldSingleton := singleton - oldOnce := once oldParseErr := parseErr oldPID := pidFilter.Load() oldTID := tidFilter.Load() @@ -28,7 +26,6 @@ func parseForTest(t *testing.T, args ...string) (Flags, error) { os.Args = append([]string{"ior"}, args...) singleton = Flags{TUIExportEnable: true} - once = sync.Once{} parseErr = nil pidFilter.Store(-1) tidFilter.Store(-1) @@ -41,7 +38,6 @@ func parseForTest(t *testing.T, args ...string) (Flags, error) { flag.CommandLine = oldCommandLine os.Args = oldArgs singleton = oldSingleton - once = oldOnce parseErr = oldParseErr pidFilter.Store(oldPID) tidFilter.Store(oldTID) diff --git a/internal/flamegraph/liveserver.go b/internal/flamegraph/liveserver.go index 4cc5629..8ae2b82 100644 --- a/internal/flamegraph/liveserver.go +++ b/internal/flamegraph/liveserver.go @@ -71,16 +71,32 @@ func openBrowserURL(url, openCommand string) error { waitCh := make(chan error, 1) go func() { waitCh <- cmd.Wait() }() + timer := time.NewTimer(750 * time.Millisecond) + defer stopAndDrainTimer(timer) + select { case waitErr := <-waitCh: if waitErr != nil { return fmt.Errorf("browser command exited early: %w", waitErr) } - case <-time.After(750 * time.Millisecond): + case <-timer.C: } return nil } +func stopAndDrainTimer(timer *time.Timer) { + if timer == nil { + return + } + if timer.Stop() { + return + } + select { + case <-timer.C: + default: + } +} + func notifyLiveWarning(warningCb func(string), message string) { if message == "" { return -- cgit v1.2.3