diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-10-12 09:10:20 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-10-12 09:18:40 +0300 |
commit | 33e347036002456e32eb0edc8e146e1ce678e55b (patch) | |
tree | 175a4eaaf662b34af6d2bd7bb223fec96c3a223e | |
parent | b325cb9a60cbbbcd96d0a78e2b659558ef4b4482 (diff) |
testserver: Precreate socket to fix health check race with Praefect
When running the test-with-praefect target, then we're running the
Praefect executable as a transparent proxy in front of Gitaly servers.
We frequently observe test failures though because we fail to establish
the server's healthiness, where the error message typically indicates
that the server's socket path does not exist. This may have two root
causes: either we're really taking too long to spawn Praefect, or we
just fail to dial Praefect correctly in case the socket really hasn't
been created yet.
Plug one of these two potential races by precreating the Praefect socket
path. If this doesn't fix the issue, then the only thing left we can do
is to bump the three second timeout.
-rw-r--r-- | internal/testhelper/testserver/gitaly.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/internal/testhelper/testserver/gitaly.go b/internal/testhelper/testserver/gitaly.go index 6ac90f335..b8f5a6d1b 100644 --- a/internal/testhelper/testserver/gitaly.go +++ b/internal/testhelper/testserver/gitaly.go @@ -96,7 +96,14 @@ func runPraefectProxy(t testing.TB, cfg config.Cfg, gitalyAddr, praefectBinPath tempDir := testhelper.TempDir(t) - praefectServerSocketPath := "unix://" + testhelper.GetTemporaryGitalySocketFileName(t) + // We're precreating the Unix socket which we pass to Praefect. This closes a race where + // the Unix socket didn't yet exist when we tried to dial the Praefect server. + praefectServerSocket, err := net.Listen("unix", testhelper.GetTemporaryGitalySocketFileName(t)) + require.NoError(t, err) + testhelper.MustClose(t, praefectServerSocket) + t.Cleanup(func() { require.NoError(t, os.RemoveAll(praefectServerSocket.Addr().String())) }) + + praefectServerSocketPath := "unix://" + praefectServerSocket.Addr().String() dbName := createDatabase(t) |