Commit b4acd08e authored by Ahmad Sherif's avatar Ahmad Sherif

Use a separate Gitaly socket for every test

parent 2b604f62
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
"math/rand"
"net" "net"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
...@@ -38,7 +39,6 @@ const testProject = "group/test" ...@@ -38,7 +39,6 @@ const testProject = "group/test"
var checkoutDir = path.Join(scratchDir, "test") var checkoutDir = path.Join(scratchDir, "test")
var cacheDir = path.Join(scratchDir, "cache") var cacheDir = path.Join(scratchDir, "cache")
var gitalySocketPath = path.Join(scratchDir, "gitaly.sock")
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
source := "https://gitlab.com/gitlab-org/gitlab-test.git" source := "https://gitlab.com/gitlab-org/gitlab-test.git"
...@@ -60,6 +60,8 @@ func TestMain(m *testing.M) { ...@@ -60,6 +60,8 @@ func TestMain(m *testing.M) {
os.Exit(1) os.Exit(1)
} }
defer gitaly.CloseConnections()
os.Exit(func() int { os.Exit(func() int {
defer cleanup() defer cleanup()
return m.Run() return m.Run()
...@@ -594,15 +596,19 @@ func TestApiContentTypeBlock(t *testing.T) { ...@@ -594,15 +596,19 @@ func TestApiContentTypeBlock(t *testing.T) {
} }
func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) { func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) {
gitalyServer := startGitalyServer(t)
defer func() {
gitalyServer.Stop()
gitaly.CloseConnections()
}()
apiResponse := gitOkBody(t) apiResponse := gitOkBody(t)
repoPath := apiResponse.RepoPath repoPath := apiResponse.RepoPath
gitalyServer, socketPath := startGitalyServer(t)
defer gitalyServer.Stop()
apiResponse.GitalySocketPath = socketPath
ts := testAuthServer(nil, 200, apiResponse)
defer ts.Close()
ws := startWorkhorseServer(ts.URL)
defer ws.Close()
for _, testCase := range []struct { for _, testCase := range []struct {
repoPath string repoPath string
repository pb.Repository repository pb.Repository
...@@ -613,7 +619,7 @@ func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) { ...@@ -613,7 +619,7 @@ func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) {
func() { func() {
apiResponse.RepoPath = testCase.repoPath apiResponse.RepoPath = testCase.repoPath
apiResponse.Repository = testCase.repository apiResponse.Repository = testCase.repository
apiResponse.GitalySocketPath = gitalySocketPath apiResponse.GitalySocketPath = socketPath
ts := testAuthServer(nil, 200, apiResponse) ts := testAuthServer(nil, 200, apiResponse)
defer ts.Close() defer ts.Close()
...@@ -640,11 +646,8 @@ func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) { ...@@ -640,11 +646,8 @@ func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) {
} }
func TestGetInfoRefsHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) { func TestGetInfoRefsHandledLocallyDueToEmptyGitalySocketPath(t *testing.T) {
gitalyServer := startGitalyServer(t) gitalyServer, _ := startGitalyServer(t)
defer func() { defer gitalyServer.Stop()
gitalyServer.Stop()
gitaly.CloseConnections()
}()
apiResponse := gitOkBody(t) apiResponse := gitOkBody(t)
apiResponse.GitalySocketPath = "" apiResponse.GitalySocketPath = ""
...@@ -848,9 +851,10 @@ func startWorkhorseServerWithConfig(cfg *config.Config) *httptest.Server { ...@@ -848,9 +851,10 @@ func startWorkhorseServerWithConfig(cfg *config.Config) *httptest.Server {
return httptest.NewServer(u) return httptest.NewServer(u)
} }
func startGitalyServer(t *testing.T) *grpc.Server { func startGitalyServer(t *testing.T) (*grpc.Server, string) {
socketPath := path.Join(scratchDir, fmt.Sprintf("gitaly-%d.sock", rand.Int()))
server := grpc.NewServer() server := grpc.NewServer()
listener, err := net.Listen("unix", gitalySocketPath) listener, err := net.Listen("unix", socketPath)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -859,7 +863,7 @@ func startGitalyServer(t *testing.T) *grpc.Server { ...@@ -859,7 +863,7 @@ func startGitalyServer(t *testing.T) *grpc.Server {
go server.Serve(listener) go server.Serve(listener)
return server return server, socketPath
} }
func runOrFail(t *testing.T, cmd *exec.Cmd) { func runOrFail(t *testing.T, cmd *exec.Cmd) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment