Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-04-28 15:09:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-04-28 15:09:06 +0300
commit77031895573384d40d631ac215ff2a99a4740094 (patch)
tree0aea73aaa1acf377a95beca7c5061264b204f33e /workhorse/gitaly_test.go
parent4a372de7753b16d254dc319a6bad08ecac0273af (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'workhorse/gitaly_test.go')
-rw-r--r--workhorse/gitaly_test.go60
1 files changed, 5 insertions, 55 deletions
diff --git a/workhorse/gitaly_test.go b/workhorse/gitaly_test.go
index 4ace925001a..7e89f3bf0f5 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,16 +20,12 @@ 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"
@@ -380,24 +375,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 +395,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 +461,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 +495,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 +856,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 +870,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
- }
-}