From 28b48aada9d891406464b11bbd05e4a1dc992688 Mon Sep 17 00:00:00 2001 From: Fedor Korotkiy Date: Thu, 31 Mar 2022 16:30:47 +0300 Subject: [PATCH] Fix flaky test --- pgfixture/pg.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pgfixture/pg.go b/pgfixture/pg.go index 8b2d3a2..3948539 100644 --- a/pgfixture/pg.go +++ b/pgfixture/pg.go @@ -8,6 +8,9 @@ import ( "path/filepath" "testing" "time" + + "github.com/stretchr/testify/require" + "gitlab.com/slon/shad-go/tools/testtool" ) func lookPath(t *testing.T, name string) string { @@ -50,9 +53,12 @@ func Start(t *testing.T) string { t.Fatalf("initdb failed: %v", err) } + port, err := testtool.GetFreePort() + require.NoError(t, err) + pgrun := t.TempDir() - cmd = exec.Command(lookPath(t, "postgres"), "-D", pgdata, "-k", pgrun, "-F") + cmd = exec.Command(lookPath(t, "postgres"), "-D", pgdata, "-k", pgrun, "-F", "-p", port) cmd.Stderr = os.Stderr cmd.Stdout = os.Stdout if err := cmd.Start(); err != nil { @@ -75,5 +81,5 @@ func Start(t *testing.T) string { _ = cmd.Process.Kill() }) - return fmt.Sprintf("host=%s database=postgres", pgrun) + return fmt.Sprintf("host=localhost port=%s database=postgres", port) }