diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
commit | d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch) | |
tree | 2341ef426af70ad1e289c38036737e04b0aa5007 /workhorse/gitaly_test.go | |
parent | d6e514dd13db8947884cd58fe2a9c2a063400a9b (diff) |
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'workhorse/gitaly_test.go')
-rw-r--r-- | workhorse/gitaly_test.go | 61 |
1 files changed, 56 insertions, 5 deletions
diff --git a/workhorse/gitaly_test.go b/workhorse/gitaly_test.go index 42aaad6e02d..4ace925001a 100644 --- a/workhorse/gitaly_test.go +++ b/workhorse/gitaly_test.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "io" "io/ioutil" "math/rand" "net" @@ -20,12 +21,16 @@ import ( "github.com/golang/protobuf/jsonpb" //lint:ignore SA1019 https://gitlab.com/gitlab-org/gitlab/-/issues/324868 "github.com/golang/protobuf/proto" //lint:ignore SA1019 https://gitlab.com/gitlab-org/gitlab/-/issues/324868 + "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials/insecure" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" + gitalyclient "gitlab.com/gitlab-org/gitaly/v14/client" + "gitlab.com/gitlab-org/gitlab/workhorse/internal/api" "gitlab.com/gitlab-org/gitlab/workhorse/internal/git" "gitlab.com/gitlab-org/gitlab/workhorse/internal/gitaly" @@ -375,12 +380,24 @@ func TestPostReceivePackRouting(t *testing.T) { } } +type gitalyServerStarter func(*testing.T, codes.Code) (*combinedServer, string) + // ReaderFunc is an adapter to turn a conforming function into an io.Reader. type ReaderFunc func(b []byte) (int, error) func (r ReaderFunc) Read(b []byte) (int, error) { return r(b) } func TestPostUploadPackProxiedToGitalySuccessfully(t *testing.T) { + testPostUploadPackProxiedToGitalySuccessfully(t, startGitalyServer, gitOkBody(t)) +} + +func TestPostUploadPackWithSidechannelProxiedToGitalySuccessfully(t *testing.T) { + testPostUploadPackProxiedToGitalySuccessfully( + t, startGitalyServerWithSideChannel(testhelper.PostUploadPackWithSidechannel), gitOkBodyWithSidechannel(t), + ) +} + +func testPostUploadPackProxiedToGitalySuccessfully(t *testing.T, startGitaly gitalyServerStarter, apiResponse *api.Response) { for i, tc := range []struct { showAllRefs bool code codes.Code @@ -391,10 +408,9 @@ func TestPostUploadPackProxiedToGitalySuccessfully(t *testing.T) { {false, codes.Unavailable}, } { t.Run(fmt.Sprintf("Case %d", i), func(t *testing.T) { - apiResponse := gitOkBody(t) apiResponse.ShowAllRefs = tc.showAllRefs - gitalyServer, socketPath := startGitalyServer(t, tc.code) + gitalyServer, socketPath := startGitaly(t, tc.code) defer gitalyServer.GracefulStop() apiResponse.GitalyServer.Address = "unix:" + socketPath @@ -460,8 +476,16 @@ func TestPostUploadPackProxiedToGitalySuccessfully(t *testing.T) { func TestPostUploadPackProxiedToGitalyInterrupted(t *testing.T) { apiResponse := gitOkBody(t) + testPostUploadPackProxiedToGitalyInterrupted(t, startGitalyServer, apiResponse) +} - gitalyServer, socketPath := startGitalyServer(t, codes.OK) +func TestPostUploadPackWithSidechannelProxiedToGitalyInterrupted(t *testing.T) { + apiResponse := gitOkBodyWithSidechannel(t) + testPostUploadPackProxiedToGitalyInterrupted(t, startGitalyServerWithSideChannel(testhelper.PostUploadPackWithSidechannel), apiResponse) +} + +func testPostUploadPackProxiedToGitalyInterrupted(t *testing.T, startGitaly gitalyServerStarter, apiResponse *api.Response) { + gitalyServer, socketPath := startGitaly(t, codes.OK) defer gitalyServer.GracefulStop() apiResponse.GitalyServer.Address = "unix:" + socketPath @@ -493,10 +517,19 @@ func TestPostUploadPackProxiedToGitalyInterrupted(t *testing.T) { } func TestPostUploadPackRouting(t *testing.T) { - gitalyServer, socketPath := startGitalyServer(t, codes.OK) + apiResponse := gitOkBody(t) + testPostUploadPackRouting(t, startGitalyServer, apiResponse) +} + +func TestPostUploadPackWithSidechannelRouting(t *testing.T) { + apiResponse := gitOkBodyWithSidechannel(t) + testPostUploadPackRouting(t, startGitalyServerWithSideChannel(testhelper.PostUploadPackWithSidechannel), apiResponse) +} + +func testPostUploadPackRouting(t *testing.T, startGitaly gitalyServerStarter, apiResponse *api.Response) { + gitalyServer, socketPath := startGitaly(t, codes.OK) defer gitalyServer.GracefulStop() - apiResponse := gitOkBody(t) apiResponse.GitalyServer.Address = "unix:" + socketPath ts := testAuthServer(t, nil, nil, 200, apiResponse) defer ts.Close() @@ -869,3 +902,21 @@ func startGitalyServer(t *testing.T, finalMessageCode codes.Code) (*combinedServ return &combinedServer{Server: server, GitalyTestServer: gitalyServer}, socketPath } + +func startGitalyServerWithSideChannel(handler func(interface{}, grpc.ServerStream, io.ReadWriteCloser) error) gitalyServerStarter { + return func(t *testing.T, finalMessageCode codes.Code) (*combinedServer, string) { + socketPath := path.Join(scratchDir, fmt.Sprintf("gitaly-%d.sock", rand.Int())) + if err := os.Remove(socketPath); err != nil && !os.IsNotExist(err) { + t.Fatal(err) + } + server := grpc.NewServer(gitalyclient.TestSidechannelServer(logrus.NewEntry(logrus.StandardLogger()), insecure.NewCredentials(), handler)...) + listener, err := net.Listen("unix", socketPath) + require.NoError(t, err) + + gitalyServer := testhelper.NewGitalyServer(finalMessageCode) + + go server.Serve(listener) + + return &combinedServer{Server: server, GitalyTestServer: gitalyServer}, socketPath + } +} |