Skip to content

Commit cf9433f

Browse files
author
Wiktor Starczewski
committed
fix(test): TestRunServer_FirstRunWithoutNameErrors hung on Ubuntu CI
The test passed 'nil' as the signal channel, assuming config.Resolve would error out before the signal wait. On the GitHub Actions runner that assumption didn't hold — something in the environment let config.Resolve succeed (likely a pre-populated XDG_CONFIG_HOME), the HTTP server booted for real, and <-nil blocks forever. Defensive fix: * clear XDG_CONFIG_HOME so Dir() resolves strictly under the scratch HOME * pre-signal the channel so the server shuts down even if Resolve regresses in the future * bind to an ephemeral port so parallel tests don't collide on :3456
1 parent 6d0a213 commit cf9433f

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

‎cmd/hearsay/main_test.go‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,24 @@ func TestRunServer_BadFlagArgs(t *testing.T) {
567567
func TestRunServer_FirstRunWithoutNameErrors(t *testing.T) {
568568
home := t.TempDir()
569569
t.Setenv("HOME", home)
570-
if code := runServerWithSignals([]string{"--bind", "127.0.0.1"}, nil); code != 1 {
570+
// Neutralize any inherited XDG_CONFIG_HOME so Dir() resolves strictly
571+
// under the scratch HOME. Without this, some CI images leave
572+
// XDG_CONFIG_HOME set to a populated path and Resolve finds a
573+
// pre-existing config there — the server then boots for real and,
574+
// with a nil signal channel, the test hangs on `<-nil`.
575+
t.Setenv("XDG_CONFIG_HOME", "")
576+
// Belt-and-suspenders: pre-signal the channel so that if the
577+
// no-name→error path ever regresses, the server shuts down instead
578+
// of hanging the test for 10 minutes.
579+
sigCh := make(chan os.Signal, 1)
580+
sigCh <- syscall.SIGTERM
581+
// Pick an ephemeral port so the default :3456 doesn't collide with
582+
// other tests running in parallel on the same runner.
583+
ln, _ := net.Listen("tcp", "127.0.0.1:0")
584+
port := ln.Addr().(*net.TCPAddr).Port
585+
ln.Close()
586+
args := []string{"--bind", "127.0.0.1", "--port", fmt.Sprint(port), "--data-dir", t.TempDir(), "--quiet"}
587+
if code := runServerWithSignals(args, sigCh); code != 1 {
571588
t.Errorf("expected exit=1 when --name is missing on first run, got %d", code)
572589
}
573590
}

0 commit comments

Comments
 (0)