From c9029f1dae7a5d74e219e8f398284490c3c87336 Mon Sep 17 00:00:00 2001 From: rkoster Date: Mon, 20 Apr 2026 09:36:37 +0000 Subject: [PATCH] fix: stop router before NATS in integration test cleanup This prevents the subscriber's ClosedCB from firing log.Fatal when NATS is stopped first, which was causing the test process to exit prematurely and leading to port binding conflicts in parallel test runs. The cleanup order is now: 1. Terminate gorouter session 2. Stop NATS server 3. Clean up test files This matches the fix from upstream PR #555 (commit b2bf830e9) which resolved similar issues in router/router_test.go. --- .../gorouter/integration/common_integration_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/code.cloudfoundry.org/gorouter/integration/common_integration_test.go b/src/code.cloudfoundry.org/gorouter/integration/common_integration_test.go index 74ec5d238..b206735fe 100644 --- a/src/code.cloudfoundry.org/gorouter/integration/common_integration_test.go +++ b/src/code.cloudfoundry.org/gorouter/integration/common_integration_test.go @@ -297,6 +297,12 @@ func (s *testState) StartGorouterOrFail() { } func (s *testState) StopAndCleanup() { + // Stop router before NATS to prevent subscriber's ClosedCB from + // firing log.Fatal → os.Exit(1), which kills the test proc + if s.gorouterSession != nil && s.gorouterSession.ExitCode() == -1 { + Eventually(s.gorouterSession.Terminate(), 5).Should(Exit(0)) + } + if s.natsRunner != nil { s.natsRunner.Stop() } @@ -308,10 +314,6 @@ func (s *testState) StopAndCleanup() { os.RemoveAll(s.tmpdir) - if s.gorouterSession != nil && s.gorouterSession.ExitCode() == -1 { - Eventually(s.gorouterSession.Terminate(), 5).Should(Exit(0)) - } - if s.fakeMetron != nil { s.StopMetron() }