diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /workhorse/gitaly_test.go | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'workhorse/gitaly_test.go')
-rw-r--r-- | workhorse/gitaly_test.go | 63 |
1 files changed, 6 insertions, 57 deletions
diff --git a/workhorse/gitaly_test.go b/workhorse/gitaly_test.go index 4ace925001a..38e807f45cc 100644 --- a/workhorse/gitaly_test.go +++ b/workhorse/gitaly_test.go @@ -5,7 +5,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "io" "io/ioutil" "math/rand" "net" @@ -21,19 +20,14 @@ 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" "gitlab.com/gitlab-org/gitlab/workhorse/internal/testhelper" ) @@ -45,7 +39,7 @@ func TestFailedCloneNoGitaly(t *testing.T) { GL_ID: "user-123", GL_USERNAME: "username", // This will create a failure to connect to Gitaly - GitalyServer: gitaly.Server{Address: "unix:/nonexistent"}, + GitalyServer: api.GitalyServer{Address: "unix:/nonexistent"}, } // Prepare test server and backend @@ -380,24 +374,14 @@ 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), - ) -} + apiResponse := gitOkBody(t) -func testPostUploadPackProxiedToGitalySuccessfully(t *testing.T, startGitaly gitalyServerStarter, apiResponse *api.Response) { for i, tc := range []struct { showAllRefs bool code codes.Code @@ -410,7 +394,7 @@ func testPostUploadPackProxiedToGitalySuccessfully(t *testing.T, startGitaly git t.Run(fmt.Sprintf("Case %d", i), func(t *testing.T) { apiResponse.ShowAllRefs = tc.showAllRefs - gitalyServer, socketPath := startGitaly(t, tc.code) + gitalyServer, socketPath := startGitalyServer(t, tc.code) defer gitalyServer.GracefulStop() apiResponse.GitalyServer.Address = "unix:" + socketPath @@ -476,16 +460,8 @@ func testPostUploadPackProxiedToGitalySuccessfully(t *testing.T, startGitaly git func TestPostUploadPackProxiedToGitalyInterrupted(t *testing.T) { apiResponse := gitOkBody(t) - testPostUploadPackProxiedToGitalyInterrupted(t, startGitalyServer, apiResponse) -} - -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) + gitalyServer, socketPath := startGitalyServer(t, codes.OK) defer gitalyServer.GracefulStop() apiResponse.GitalyServer.Address = "unix:" + socketPath @@ -518,16 +494,7 @@ func testPostUploadPackProxiedToGitalyInterrupted(t *testing.T, startGitaly gita func TestPostUploadPackRouting(t *testing.T) { 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) + gitalyServer, socketPath := startGitalyServer(t, codes.OK) defer gitalyServer.GracefulStop() apiResponse.GitalyServer.Address = "unix:" + socketPath @@ -888,7 +855,7 @@ func startGitalyServer(t *testing.T, finalMessageCode codes.Code) (*combinedServ if err := os.Remove(socketPath); err != nil && !os.IsNotExist(err) { t.Fatal(err) } - server := grpc.NewServer() + server := grpc.NewServer(testhelper.WithSidechannel()) listener, err := net.Listen("unix", socketPath) require.NoError(t, err) @@ -902,21 +869,3 @@ 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 - } -} |