diff options
author | Justin Tobler <jtobler@gitlab.com> | 2023-02-24 19:59:49 +0300 |
---|---|---|
committer | Justin Tobler <jtobler@gitlab.com> | 2023-02-24 19:59:49 +0300 |
commit | 770edd2d7f8324da646df478eb271544393316df (patch) | |
tree | 7dbbdb6518a1e4187ea0f494bf869a5950627b88 /internal | |
parent | b9057c53bbb3107f87e1286def5a1977a1521795 (diff) | |
parent | ba14537e5412e53695cc3f9c41068c60d03856d1 (diff) |
Merge branch 'wc/macos-hook-err' into 'master'qmnguyen0711/fix-find-changed-paths-rpc-performance
hooks: Fix flaky test on MacOS
Closes #4806
See merge request https://gitlab.com/gitlab-org/gitaly/-/merge_requests/5415
Merged-by: Justin Tobler <jtobler@gitlab.com>
Approved-by: Pavlo Strokov <pstrokov@gitlab.com>
Approved-by: Justin Tobler <jtobler@gitlab.com>
Co-authored-by: Will Chandler <wchandler@gitlab.com>
Diffstat (limited to 'internal')
-rw-r--r-- | internal/gitaly/service/hook/pack_objects_test.go | 20 | ||||
-rw-r--r-- | internal/testhelper/grpc.go | 11 |
2 files changed, 27 insertions, 4 deletions
diff --git a/internal/gitaly/service/hook/pack_objects_test.go b/internal/gitaly/service/hook/pack_objects_test.go index a4b562240..8d1344983 100644 --- a/internal/gitaly/service/hook/pack_objects_test.go +++ b/internal/gitaly/service/hook/pack_objects_test.go @@ -8,6 +8,7 @@ import ( "fmt" "io" "net" + "runtime" "strings" "sync" "testing" @@ -16,6 +17,7 @@ import ( "github.com/prometheus/client_golang/prometheus/testutil" "github.com/sirupsen/logrus" "github.com/sirupsen/logrus/hooks/test" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v15/internal/git" "gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest" @@ -149,8 +151,18 @@ func testServerPackObjectsHookSeparateContextWithRuntimeDir(t *testing.T, ctx co go func() { defer wg.Done() _, err := client1.PackObjectsHookWithSidechannel(ctx1, req) - testhelper.RequireGrpcCode(t, err, codes.Canceled) - require.NoError(t, wt1.Wait()) + + if runtime.GOOS == "darwin" { + assert.Contains(t, []codes.Code{codes.Canceled, codes.Internal}, status.Code(err)) + + if status.Code(err) == codes.Internal { + assert.Contains(t, err.Error(), "write: socket is not connected") + } + } else { + testhelper.AssertGrpcCode(t, err, codes.Canceled) + } + + assert.NoError(t, wt1.Wait()) }() // Call 2: this is a normal call with the same request as call 1 @@ -189,8 +201,8 @@ func testServerPackObjectsHookSeparateContextWithRuntimeDir(t *testing.T, ctx co go func() { defer wg.Done() _, err := client2.PackObjectsHookWithSidechannel(ctx2, req) - require.NoError(t, err) - require.NoError(t, wt2.Wait()) + assert.NoError(t, err) + assert.NoError(t, wt2.Wait()) }() close(start1) diff --git a/internal/testhelper/grpc.go b/internal/testhelper/grpc.go index 8cf96b326..3815bc6e3 100644 --- a/internal/testhelper/grpc.go +++ b/internal/testhelper/grpc.go @@ -6,6 +6,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -50,6 +51,16 @@ func RequireGrpcCode(tb testing.TB, err error, expectedCode codes.Code) { require.Equal(tb, expectedCode, status.Code()) } +// AssertGrpcCode asserts that the error has the expected gRPC status code. +func AssertGrpcCode(tb testing.TB, err error, expectedCode codes.Code) { + tb.Helper() + + assert.Error(tb, err) + status, ok := status.FromError(err) + assert.True(tb, ok) + assert.Equal(tb, expectedCode, status.Code()) +} + // RequireGrpcError asserts that expected and actual gRPC errors are equal. Comparing gRPC errors // directly with `require.Equal()` will not typically work correct. func RequireGrpcError(tb testing.TB, expected, actual error) { |