From ffb4a67946bae74997a3e7a3859aeea3e8707f75 Mon Sep 17 00:00:00 2001 From: Azim Sonawalla Date: Wed, 14 Jan 2026 14:16:53 -0500 Subject: [PATCH] fix: ensure embedded postgres cleanup in TestMain Remove os.Exit() calls from TestMain functions to allow deferred Stop() calls to execute. In Go, os.Exit() terminates immediately without running deferred functions, causing embedded postgres processes to leak after test runs. Go 1.15+ automatically handles the exit code when TestMain returns, making explicit os.Exit() unnecessary. Ref: https://github.com/golang/go/issues/34129 --- cmd/apply/apply_integration_test.go | 6 +----- cmd/migrate_integration_test.go | 6 +----- internal/diff/diff_test.go | 6 +----- internal/plan/plan_test.go | 6 +----- 4 files changed, 4 insertions(+), 20 deletions(-) diff --git a/cmd/apply/apply_integration_test.go b/cmd/apply/apply_integration_test.go index 77e03861..4e07a531 100644 --- a/cmd/apply/apply_integration_test.go +++ b/cmd/apply/apply_integration_test.go @@ -30,11 +30,7 @@ func TestMain(m *testing.M) { sharedEmbeddedPG = testutil.SetupPostgres(nil) defer sharedEmbeddedPG.Stop() - // Run tests - code := m.Run() - - // Exit with test result code - os.Exit(code) + m.Run() } // TestApplyCommand_TransactionRollback verifies that the apply command uses proper diff --git a/cmd/migrate_integration_test.go b/cmd/migrate_integration_test.go index de4d2210..778c9acf 100644 --- a/cmd/migrate_integration_test.go +++ b/cmd/migrate_integration_test.go @@ -37,11 +37,7 @@ func TestMain(m *testing.M) { sharedEmbeddedPG = testutil.SetupPostgres(nil) defer sharedEmbeddedPG.Stop() - // Run tests - code := m.Run() - - // Exit with test result code - os.Exit(code) + m.Run() } // TestPlanAndApply tests the complete CLI (plan and apply) workflow using test cases diff --git a/internal/diff/diff_test.go b/internal/diff/diff_test.go index 9ca88841..b1386d5a 100644 --- a/internal/diff/diff_test.go +++ b/internal/diff/diff_test.go @@ -19,11 +19,7 @@ func TestMain(m *testing.M) { sharedTestPostgres = testutil.SetupPostgres(nil) defer sharedTestPostgres.Stop() - // Run tests - code := m.Run() - - // Exit with test result code - os.Exit(code) + m.Run() } // buildSQLFromSteps builds a SQL string from collected plan diffs diff --git a/internal/plan/plan_test.go b/internal/plan/plan_test.go index 7b2d1239..628af849 100644 --- a/internal/plan/plan_test.go +++ b/internal/plan/plan_test.go @@ -26,11 +26,7 @@ func TestMain(m *testing.M) { sharedTestPostgres = testutil.SetupPostgres(nil) defer sharedTestPostgres.Stop() - // Run tests - code := m.Run() - - // Exit with test result code - os.Exit(code) + m.Run() } // discoverTestDataVersions discovers available test data versions in the testdata directory