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

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavlo Strokov <pstrokov@gitlab.com>2020-08-06 09:39:56 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2020-08-06 09:39:56 +0300
commit9e5dfd987388c905b584f58b48afede245721ec7 (patch)
tree4d2a1de5bf09e149c9f1242b1b7178803b4e2a43
parent0f3b4b0b121f611fac2a613ec0273864d5f38c8b (diff)
parenta1731804961b8a57610cb9251c0938b384cbaaf0 (diff)
Merge branch 'ps-enable-features' into 'master'
Feature flags enabling for tests. See merge request gitlab-org/gitaly!2425
-rw-r--r--client/dial_test.go9
-rw-r--r--client/pool_test.go3
-rw-r--r--cmd/gitaly-hooks/hooks_test.go8
-rw-r--r--internal/git/command_test.go4
-rw-r--r--internal/git/protocol_test.go7
-rw-r--r--internal/git/safecmd_test.go2
-rw-r--r--internal/gitalyssh/gitalyssh_test.go3
-rw-r--r--internal/helper/housekeeping/housekeeping_test.go11
-rw-r--r--internal/metadata/featureflag/context.go27
-rw-r--r--internal/metadata/featureflag/context_test.go10
-rw-r--r--internal/metadata/featureflag/feature_flags.go18
-rw-r--r--internal/middleware/cache/cache_test.go3
-rw-r--r--internal/middleware/sentryhandler/sentryhandler_test.go5
-rw-r--r--internal/praefect/consistencycheck_test.go3
-rw-r--r--internal/praefect/coordinator_test.go46
-rw-r--r--internal/praefect/grpc-proxy/proxy/peeker_test.go5
-rw-r--r--internal/praefect/info_service_test.go1
-rw-r--r--internal/praefect/nodes/manager_test.go8
-rw-r--r--internal/praefect/server_factory_test.go5
-rw-r--r--internal/praefect/server_test.go16
-rw-r--r--internal/praefect/transaction_test.go7
-rw-r--r--internal/rubyserver/concurrency_test.go4
-rw-r--r--internal/service/commit/between_test.go5
-rw-r--r--internal/service/commit/commits_by_message_test.go5
-rw-r--r--internal/service/commit/count_commits_test.go5
-rw-r--r--internal/service/commit/count_diverging_commits_test.go5
-rw-r--r--internal/service/commit/find_all_commits_test.go4
-rw-r--r--internal/service/commit/find_commit_test.go5
-rw-r--r--internal/service/commit/find_commits_test.go2
-rw-r--r--internal/service/commit/isancestor_test.go7
-rw-r--r--internal/service/commit/languages_test.go7
-rw-r--r--internal/service/commit/last_commit_for_path_test.go7
-rw-r--r--internal/service/commit/list_commits_by_oid_test.go3
-rw-r--r--internal/service/commit/list_files_test.go4
-rw-r--r--internal/service/commit/list_last_commits_for_tree_test.go5
-rw-r--r--internal/service/commit/raw_blame_test.go5
-rw-r--r--internal/service/commit/stats_test.go5
-rw-r--r--internal/service/commit/tree_entries_test.go9
-rw-r--r--internal/service/commit/tree_entry_test.go5
-rw-r--r--internal/service/diff/commit_test.go23
-rw-r--r--internal/service/diff/numstat_test.go3
-rw-r--r--internal/service/inspect/inspector_test.go8
-rw-r--r--internal/service/namespace/namespace_test.go11
-rw-r--r--internal/service/operations/branches_test.go10
-rw-r--r--internal/service/operations/rebase_test.go8
-rw-r--r--internal/service/operations/tags_test.go21
-rw-r--r--internal/service/operations/update_branches_test.go16
-rw-r--r--internal/service/ref/branches_test.go5
-rw-r--r--internal/service/ref/refname_test.go11
-rw-r--r--internal/service/ref/refs_test.go44
-rw-r--r--internal/service/ref/remote_branches_test.go3
-rw-r--r--internal/service/remote/fetch_internal_remote_test.go3
-rw-r--r--internal/service/remote/remotes_test.go13
-rw-r--r--internal/service/remote/update_remote_mirror_test.go3
-rw-r--r--internal/service/repository/fetch_test.go61
-rw-r--r--internal/service/repository/gc_test.go7
-rw-r--r--internal/service/repository/repack_test.go11
-rw-r--r--internal/service/repository/repository_test.go7
-rw-r--r--internal/service/repository/size_test.go7
-rw-r--r--internal/service/smarthttp/inforefs_test.go23
-rw-r--r--internal/service/smarthttp/receive_pack_test.go26
-rw-r--r--internal/service/ssh/receive_pack_test.go3
-rw-r--r--internal/service/ssh/upload_archive_test.go3
-rw-r--r--internal/service/ssh/upload_pack_test.go3
-rw-r--r--internal/supervisor/supervisor_test.go2
-rw-r--r--internal/testhelper/grpc_test.go7
-rw-r--r--internal/testhelper/testhelper.go109
-rw-r--r--internal/testhelper/testserver.go72
68 files changed, 476 insertions, 340 deletions
diff --git a/client/dial_test.go b/client/dial_test.go
index 2759e2dde..05015df62 100644
--- a/client/dial_test.go
+++ b/client/dial_test.go
@@ -21,7 +21,7 @@ import (
var proxyEnvironmentKeys = []string{"http_proxy", "https_proxy", "no_proxy"}
-func doDialAndExecuteCall(addr string) error {
+func doDialAndExecuteCall(ctx context.Context, addr string) error {
conn, err := Dial(addr, nil)
if err != nil {
return fmt.Errorf("dial: %v", err)
@@ -29,7 +29,7 @@ func doDialAndExecuteCall(addr string) error {
defer conn.Close()
client := healthpb.NewHealthClient(conn)
- _, err = client.Check(context.Background(), &healthpb.HealthCheckRequest{})
+ _, err = client.Check(ctx, &healthpb.HealthCheckRequest{})
return err
}
@@ -113,7 +113,10 @@ func TestDial(t *testing.T) {
defer testhelper.ModifyEnvironment(t, gitaly_x509.SSLCertFile, tt.envSSLCertFile)()
}
- err := doDialAndExecuteCall(tt.rawAddress)
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
+ err := doDialAndExecuteCall(ctx, tt.rawAddress)
if tt.expectFailure {
require.Error(t, err)
return
diff --git a/client/pool_test.go b/client/pool_test.go
index 99a3c3057..c7eab4fed 100644
--- a/client/pool_test.go
+++ b/client/pool_test.go
@@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/require"
gitaly_auth "gitlab.com/gitlab-org/gitaly/internal/config/auth"
"gitlab.com/gitlab-org/gitaly/internal/server/auth"
+ "gitlab.com/gitlab-org/gitaly/internal/testhelper"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/health"
@@ -130,7 +131,7 @@ func TestPoolDial(t *testing.T) {
require.NoError(t, pool.Close())
}()
- ctx, cancel := context.WithTimeout(context.Background(), time.Second)
+ ctx, cancel := testhelper.Context(testhelper.ContextWithTimeout(time.Second))
defer cancel()
tc.test(t, ctx, pool)
diff --git a/cmd/gitaly-hooks/hooks_test.go b/cmd/gitaly-hooks/hooks_test.go
index 214a8b091..901d6287a 100644
--- a/cmd/gitaly-hooks/hooks_test.go
+++ b/cmd/gitaly-hooks/hooks_test.go
@@ -142,7 +142,7 @@ func testHooksPrePostReceive(t *testing.T) {
for _, hookName := range hookNames {
for _, featureSet := range featureSets {
- t.Run(fmt.Sprintf("hookName: %s, feature flags: %s", hookName, featureSet), func(t *testing.T) {
+ t.Run(fmt.Sprintf("hookName: %s, disabled feature flags: %s", hookName, featureSet), func(t *testing.T) {
customHookOutputPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName)
defer cleanup()
@@ -187,7 +187,7 @@ func testHooksPrePostReceive(t *testing.T) {
gitPushOptions...,
)
- if featureSet.IsEnabled(featureflag.GoPreReceiveHook) {
+ if !featureSet.IsDisabled(featureflag.GoPreReceiveHook) {
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=true", featureflag.GoPreReceiveHookEnvVar))
}
@@ -256,7 +256,7 @@ func TestHooksUpdate(t *testing.T) {
require.NoError(t, err)
for _, featureSet := range featureSets {
- t.Run(fmt.Sprintf("enabled features: %v", featureSet), func(t *testing.T) {
+ t.Run(fmt.Sprintf("disabled %v", featureSet), func(t *testing.T) {
config.Config.Hooks.CustomHooksDir = customHooksDir
testHooksUpdate(t, tempGitlabShellDir, socket, token, testhelper.GlHookValues{
@@ -303,7 +303,7 @@ open('%s', 'w') { |f| f.puts(JSON.dump(ARGV)) }
var stdout, stderr bytes.Buffer
- if features.IsEnabled(featureflag.GoUpdateHook) {
+ if !features.IsDisabled(featureflag.GoUpdateHook) {
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=true", featureflag.GoUpdateHookEnvVar))
}
cmd.Stdout = &stdout
diff --git a/internal/git/command_test.go b/internal/git/command_test.go
index ee2859a55..746baf856 100644
--- a/internal/git/command_test.go
+++ b/internal/git/command_test.go
@@ -1,7 +1,6 @@
package git
import (
- "context"
"io/ioutil"
"net/http"
"net/http/httptest"
@@ -9,6 +8,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/testhelper"
)
func TestGitCommandProxy(t *testing.T) {
@@ -24,7 +24,7 @@ func TestGitCommandProxy(t *testing.T) {
os.Setenv("http_proxy", ts.URL)
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
dir, err := ioutil.TempDir("", "test-clone")
diff --git a/internal/git/protocol_test.go b/internal/git/protocol_test.go
index c0314dfa3..f5ec602db 100644
--- a/internal/git/protocol_test.go
+++ b/internal/git/protocol_test.go
@@ -1,10 +1,10 @@
package git
import (
- "context"
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/testhelper"
)
type fakeProtocolMessage struct {
@@ -34,7 +34,10 @@ func TestAddGitProtocolEnv(t *testing.T) {
},
} {
t.Run(tt.desc, func(t *testing.T) {
- actual := AddGitProtocolEnv(context.Background(), tt.msg, env)
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
+ actual := AddGitProtocolEnv(ctx, tt.msg, env)
require.Equal(t, tt.env, actual)
})
}
diff --git a/internal/git/safecmd_test.go b/internal/git/safecmd_test.go
index 6e5b767fa..62ca1bfdc 100644
--- a/internal/git/safecmd_test.go
+++ b/internal/git/safecmd_test.go
@@ -119,7 +119,7 @@ func TestSafeCmdValid(t *testing.T) {
testRepo, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
reenableGitCmd := disableGitCmd()
diff --git a/internal/gitalyssh/gitalyssh_test.go b/internal/gitalyssh/gitalyssh_test.go
index 3d4199c8b..5c7cb93c4 100644
--- a/internal/gitalyssh/gitalyssh_test.go
+++ b/internal/gitalyssh/gitalyssh_test.go
@@ -1,7 +1,6 @@
package gitalyssh
import (
- "context"
"encoding/base64"
"fmt"
"path/filepath"
@@ -19,7 +18,7 @@ func TestUploadPackEnv(t *testing.T) {
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
md := metadata.Pairs("gitaly-servers", base64.StdEncoding.EncodeToString([]byte(`{"default":{"address":"unix:///tmp/sock","token":"hunter1"}}`)))
diff --git a/internal/helper/housekeeping/housekeeping_test.go b/internal/helper/housekeeping/housekeeping_test.go
index 93f86046e..4077c9f9c 100644
--- a/internal/helper/housekeeping/housekeeping_test.go
+++ b/internal/helper/housekeeping/housekeeping_test.go
@@ -1,7 +1,6 @@
package housekeeping
import (
- "context"
"io/ioutil"
"os"
"path/filepath"
@@ -186,7 +185,10 @@ func TestPerform(t *testing.T) {
e.create(t, rootPath)
}
- if err = Perform(context.Background(), rootPath); (err != nil) != tt.wantErr {
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
+ if err = Perform(ctx, rootPath); (err != nil) != tt.wantErr {
t.Errorf("Perform() error = %v, wantErr %v", err, tt.wantErr)
}
@@ -298,7 +300,10 @@ func TestDeleteRootOwnerObjects(t *testing.T) {
t.Skip("skipping test; Only used for manual testing")
}
- err := Perform(context.Background(), rootPath)
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
+ err := Perform(ctx, rootPath)
assert.NoError(t, err, "Housekeeping failed")
_, err = os.Stat(filepath.Join(rootPath, "tmp_FILE"))
diff --git a/internal/metadata/featureflag/context.go b/internal/metadata/featureflag/context.go
index 6522b4018..0129c9e3b 100644
--- a/internal/metadata/featureflag/context.go
+++ b/internal/metadata/featureflag/context.go
@@ -70,6 +70,16 @@ func IncomingCtxWithFeatureFlag(ctx context.Context, flag FeatureFlag) context.C
return metadata.NewIncomingContext(ctx, md)
}
+// IncomingCtxWithDisabledFeatureFlag marks feature flag as disabled in the incoming context.
+func IncomingCtxWithDisabledFeatureFlag(ctx context.Context, flag FeatureFlag) context.Context {
+ md, ok := metadata.FromIncomingContext(ctx)
+ if !ok {
+ md = metadata.New(map[string]string{})
+ }
+ md.Set(HeaderKey(flag.Name), "false")
+ return metadata.NewIncomingContext(ctx, md)
+}
+
func OutgoingCtxWithRubyFeatureFlags(ctx context.Context, flags ...FeatureFlag) context.Context {
md, ok := metadata.FromOutgoingContext(ctx)
if !ok {
@@ -83,6 +93,23 @@ func OutgoingCtxWithRubyFeatureFlags(ctx context.Context, flags ...FeatureFlag)
return metadata.NewOutgoingContext(ctx, md)
}
+// OutgoingCtxWithRubyFeatureFlagValue returns context populated with outgoing metadata
+// that contains ruby feature flags passed in.
+func OutgoingCtxWithRubyFeatureFlagValue(ctx context.Context, flag FeatureFlag, val string) context.Context {
+ if val != "true" && val != "false" {
+ return ctx
+ }
+
+ md, ok := metadata.FromOutgoingContext(ctx)
+ if !ok {
+ md = metadata.New(map[string]string{})
+ }
+
+ md.Set(rubyHeaderKey(flag.Name), val)
+
+ return metadata.NewOutgoingContext(ctx, md)
+}
+
func rubyHeaderKey(flag string) string {
return fmt.Sprintf("gitaly-feature-ruby-%s", strings.ReplaceAll(flag, "_", "-"))
}
diff --git a/internal/metadata/featureflag/context_test.go b/internal/metadata/featureflag/context_test.go
index e184340f4..095198032 100644
--- a/internal/metadata/featureflag/context_test.go
+++ b/internal/metadata/featureflag/context_test.go
@@ -18,6 +18,16 @@ func TestIncomingCtxWithFeatureFlag(t *testing.T) {
require.True(t, IsEnabled(ctx, mockFeatureFlag))
}
+func TestIncomingCtxWithDisabledFeatureFlag(t *testing.T) {
+ ctx := context.Background()
+
+ require.False(t, IsEnabled(ctx, mockFeatureFlag))
+
+ ctx = IncomingCtxWithDisabledFeatureFlag(ctx, mockFeatureFlag)
+
+ require.True(t, IsDisabled(ctx, mockFeatureFlag))
+}
+
func TestOutgoingCtxWithFeatureFlag(t *testing.T) {
ctx := context.Background()
require.False(t, IsEnabled(ctx, mockFeatureFlag))
diff --git a/internal/metadata/featureflag/feature_flags.go b/internal/metadata/featureflag/feature_flags.go
index e98ea0bd1..7fd74a936 100644
--- a/internal/metadata/featureflag/feature_flags.go
+++ b/internal/metadata/featureflag/feature_flags.go
@@ -5,6 +5,9 @@ type FeatureFlag struct {
OnByDefault bool `json:"on_by_default"`
}
+// A set of feature flags used in Gitaly and Praefect.
+// In order to support coverage of combined features usage all feature flags should be marked as enabled for the test.
+// NOTE: if you add a new feature flag please add it to the `All` list defined below.
var (
// GoUpdateHook will bypass the ruby update hook and use the go implementation of custom hooks
GoUpdateHook = FeatureFlag{Name: "go_update_hook", OnByDefault: true}
@@ -32,6 +35,21 @@ var (
ReferenceTransactionHook = FeatureFlag{Name: "reference_transaction_hook", OnByDefault: false}
)
+// All includes all feature flags.
+var All = []FeatureFlag{
+ GoUpdateHook,
+ GoFetchSourceBranch,
+ DistributedReads,
+ GoPreReceiveHook,
+ GoPostReceiveHook,
+ ReferenceTransactions,
+ ReferenceTransactionsOperationService,
+ ReferenceTransactionsSmartHTTPService,
+ ReferenceTransactionsSSHService,
+ ReferenceTransactionsPrimaryWins,
+ ReferenceTransactionHook,
+}
+
const (
GoUpdateHookEnvVar = "GITALY_GO_UPDATE"
GoPreReceiveHookEnvVar = "GITALY_GO_PRERECEIVE"
diff --git a/internal/middleware/cache/cache_test.go b/internal/middleware/cache/cache_test.go
index 632dc3843..fe0f2e39e 100644
--- a/internal/middleware/cache/cache_test.go
+++ b/internal/middleware/cache/cache_test.go
@@ -16,6 +16,7 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/middleware/cache"
"gitlab.com/gitlab-org/gitaly/internal/middleware/cache/testdata"
"gitlab.com/gitlab-org/gitaly/internal/praefect/protoregistry"
+ "gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc"
"google.golang.org/grpc/health"
@@ -38,7 +39,7 @@ func TestInvalidators(t *testing.T) {
),
)
- ctx, cancel := context.WithTimeout(context.Background(), time.Second)
+ ctx, cancel := testhelper.Context(testhelper.ContextWithTimeout(time.Second))
defer cancel()
svc := &testSvc{}
diff --git a/internal/middleware/sentryhandler/sentryhandler_test.go b/internal/middleware/sentryhandler/sentryhandler_test.go
index dcc78e9d4..4aaca2c22 100644
--- a/internal/middleware/sentryhandler/sentryhandler_test.go
+++ b/internal/middleware/sentryhandler/sentryhandler_test.go
@@ -8,6 +8,7 @@ import (
grpc_ctxtags "github.com/grpc-ecosystem/go-grpc-middleware/tags"
"github.com/stretchr/testify/assert"
+ "gitlab.com/gitlab-org/gitaly/internal/testhelper"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
@@ -88,7 +89,9 @@ func Test_generateSentryEvent(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- ctx := context.Background()
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
if tt.ctx != nil {
ctx = tt.ctx
}
diff --git a/internal/praefect/consistencycheck_test.go b/internal/praefect/consistencycheck_test.go
index 078fbc658..944ccd8c7 100644
--- a/internal/praefect/consistencycheck_test.go
+++ b/internal/praefect/consistencycheck_test.go
@@ -1,7 +1,6 @@
package praefect
import (
- "context"
"io"
"os"
"testing"
@@ -72,7 +71,7 @@ func TestConsistencyCheck(t *testing.T) {
praefectCli := gitalypb.NewPraefectInfoServiceClient(cc)
- ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+ ctx, cancel := testhelper.Context(testhelper.ContextWithTimeout(10 * time.Second))
defer cancel()
disableReconcilliation := true
diff --git a/internal/praefect/coordinator_test.go b/internal/praefect/coordinator_test.go
index 588a529a8..63097d010 100644
--- a/internal/praefect/coordinator_test.go
+++ b/internal/praefect/coordinator_test.go
@@ -230,12 +230,13 @@ func TestStreamDirectorMutator_Transaction(t *testing.T) {
}
testcases := []struct {
- desc string
- features []featureflag.FeatureFlag
- nodes []node
+ desc string
+ disableFeatures []featureflag.FeatureFlag
+ nodes []node
}{
{
- desc: "successful vote should not create replication jobs",
+ desc: "successful vote should not create replication jobs",
+ disableFeatures: []featureflag.FeatureFlag{featureflag.ReferenceTransactionsPrimaryWins},
nodes: []node{
{primary: true, vote: "foobar", shouldSucceed: true, shouldGetRepl: false, shouldParticipate: true},
{primary: false, vote: "foobar", shouldSucceed: true, shouldGetRepl: false, shouldParticipate: true},
@@ -246,7 +247,8 @@ func TestStreamDirectorMutator_Transaction(t *testing.T) {
// Currently, transactions are created such that all nodes need to agree.
// This is going to change in the future, but for now let's just test that
// we don't get any replication jobs if any node disagrees.
- desc: "failing vote should not create replication jobs",
+ desc: "failing vote should not create replication jobs",
+ disableFeatures: []featureflag.FeatureFlag{featureflag.ReferenceTransactionsPrimaryWins},
nodes: []node{
{primary: true, vote: "foobar", shouldSucceed: false, shouldGetRepl: false, shouldParticipate: true},
{primary: false, vote: "foobar", shouldSucceed: false, shouldGetRepl: false, shouldParticipate: true},
@@ -254,7 +256,8 @@ func TestStreamDirectorMutator_Transaction(t *testing.T) {
},
},
{
- desc: "only consistent secondaries should participate",
+ desc: "only consistent secondaries should participate",
+ disableFeatures: []featureflag.FeatureFlag{featureflag.ReferenceTransactionsPrimaryWins},
nodes: []node{
{primary: true, vote: "foobar", shouldSucceed: true, shouldParticipate: true, generation: 1},
{primary: false, vote: "foobar", shouldSucceed: true, shouldParticipate: true, generation: 1},
@@ -263,15 +266,15 @@ func TestStreamDirectorMutator_Transaction(t *testing.T) {
},
},
{
- desc: "secondaries should not participate when primary's generation is unknown",
+ desc: "secondaries should not participate when primary's generation is unknown",
+ disableFeatures: []featureflag.FeatureFlag{featureflag.ReferenceTransactionsPrimaryWins},
nodes: []node{
{primary: true, vote: "foobar", shouldSucceed: true, shouldParticipate: true, generation: datastore.GenerationUnknown},
{shouldParticipate: false, generation: datastore.GenerationUnknown},
},
},
{
- desc: "primary succeeds with primary-wins strategy",
- features: []featureflag.FeatureFlag{featureflag.ReferenceTransactionsPrimaryWins},
+ desc: "primary succeeds with primary-wins strategy",
nodes: []node{
{primary: true, vote: "foo", shouldSucceed: true, shouldGetRepl: false, shouldParticipate: true},
{primary: false, vote: "qux", shouldSucceed: false, shouldGetRepl: true, shouldParticipate: true},
@@ -279,8 +282,7 @@ func TestStreamDirectorMutator_Transaction(t *testing.T) {
},
},
{
- desc: "only failing secondaries get replication jobs",
- features: []featureflag.FeatureFlag{featureflag.ReferenceTransactionsPrimaryWins},
+ desc: "only failing secondaries get replication jobs",
nodes: []node{
{primary: true, vote: "foo", shouldSucceed: true, shouldGetRepl: false, shouldParticipate: true},
{primary: false, vote: "qux", shouldSucceed: false, shouldGetRepl: true, shouldParticipate: true},
@@ -291,7 +293,8 @@ func TestStreamDirectorMutator_Transaction(t *testing.T) {
// If the transaction didn't receive any votes at all, we need to assume
// that the RPC wasn't aware of transactions and thus need to schedule
// replication jobs.
- desc: "unstarted transaction should create replication jobs",
+ desc: "unstarted transaction should create replication jobs",
+ disableFeatures: []featureflag.FeatureFlag{featureflag.ReferenceTransactionsPrimaryWins},
nodes: []node{
{primary: true, shouldSucceed: true, shouldGetRepl: false},
{primary: false, shouldSucceed: false, shouldGetRepl: true},
@@ -334,9 +337,8 @@ func TestStreamDirectorMutator_Transaction(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- ctx = featureflag.IncomingCtxWithFeatureFlag(ctx, featureflag.ReferenceTransactions)
- for _, feature := range tc.features {
- ctx = featureflag.IncomingCtxWithFeatureFlag(ctx, feature)
+ for _, feature := range tc.disableFeatures {
+ ctx = featureflag.IncomingCtxWithDisabledFeatureFlag(ctx, feature)
}
nodeMgr, err := nodes.NewManager(testhelper.DiscardTestEntry(t), conf, nil, nil, promtest.NewMockHistogramVec())
@@ -399,9 +401,9 @@ func TestStreamDirectorMutator_Transaction(t *testing.T) {
vote := sha1.Sum([]byte(node.vote))
err := txMgr.VoteTransaction(ctx, transaction.ID, fmt.Sprintf("node-%d", i), vote[:])
if node.shouldSucceed {
- require.NoError(t, err)
+ assert.NoError(t, err)
} else {
- require.True(t, errors.Is(err, transactions.ErrTransactionVoteFailed))
+ assert.True(t, errors.Is(err, transactions.ErrTransactionVoteFailed))
}
}()
}
@@ -480,6 +482,8 @@ func TestStreamDirectorAccessor(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
+ ctx = featureflag.IncomingCtxWithDisabledFeatureFlag(ctx, featureflag.DistributedReads)
+
entry := testhelper.DiscardTestEntry(t)
nodeMgr, err := nodes.NewManager(entry, conf, nil, nil, promtest.NewMockHistogramVec())
@@ -562,7 +566,6 @@ func TestCoordinatorStreamDirector_distributesReads(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- ctx = featureflag.IncomingCtxWithFeatureFlag(ctx, featureflag.DistributedReads)
entry := testhelper.DiscardTestEntry(t)
@@ -853,6 +856,9 @@ func TestCoordinatorEnqueueFailure(t *testing.T) {
})
defer cleanup()
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
mcli := mock.NewSimpleServiceClient(cc)
errQ <- nil
@@ -862,12 +868,12 @@ func TestCoordinatorEnqueueFailure(t *testing.T) {
StorageName: conf.VirtualStorages[0].Name,
},
}
- _, err = mcli.RepoMutatorUnary(context.Background(), repoReq)
+ _, err = mcli.RepoMutatorUnary(ctx, repoReq)
require.NoError(t, err)
expectErrMsg := "enqueue failed"
errQ <- errors.New(expectErrMsg)
- _, err = mcli.RepoMutatorUnary(context.Background(), repoReq)
+ _, err = mcli.RepoMutatorUnary(ctx, repoReq)
require.Error(t, err)
require.Equal(t, err.Error(), "rpc error: code = Unknown desc = enqueue replication event: "+expectErrMsg)
}
diff --git a/internal/praefect/grpc-proxy/proxy/peeker_test.go b/internal/praefect/grpc-proxy/proxy/peeker_test.go
index 823cb50f6..38565da00 100644
--- a/internal/praefect/grpc-proxy/proxy/peeker_test.go
+++ b/internal/praefect/grpc-proxy/proxy/peeker_test.go
@@ -12,13 +12,14 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/helper"
"gitlab.com/gitlab-org/gitaly/internal/praefect/grpc-proxy/proxy"
testservice "gitlab.com/gitlab-org/gitaly/internal/praefect/grpc-proxy/testdata"
+ "gitlab.com/gitlab-org/gitaly/internal/testhelper"
)
// TestStreamPeeking demonstrates that a director function is able to peek
// into a stream. Further more, it demonstrates that peeking into a stream
// will not disturb the stream sent from the proxy client to the backend.
func TestStreamPeeking(t *testing.T) {
- ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
+ ctx, cancel := testhelper.Context(testhelper.ContextWithTimeout(2 * time.Second))
defer cancel()
backendCC, backendSrvr, cleanupPinger := newBackendPinger(t, ctx)
@@ -76,7 +77,7 @@ func TestStreamPeeking(t *testing.T) {
}
func TestStreamInjecting(t *testing.T) {
- ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
+ ctx, cancel := testhelper.Context(testhelper.ContextWithTimeout(2 * time.Second))
defer cancel()
backendCC, backendSrvr, cleanupPinger := newBackendPinger(t, ctx)
diff --git a/internal/praefect/info_service_test.go b/internal/praefect/info_service_test.go
index 24221796f..8662fa4cc 100644
--- a/internal/praefect/info_service_test.go
+++ b/internal/praefect/info_service_test.go
@@ -30,6 +30,7 @@ func TestInfoService_RepositoryReplicas(t *testing.T) {
},
},
},
+ Failover: config.Failover{Enabled: true},
}
defer func(storages []gconfig.Storage) { gconfig.Config.Storages = storages }(gconfig.Config.Storages)
diff --git a/internal/praefect/nodes/manager_test.go b/internal/praefect/nodes/manager_test.go
index 62cf9add7..48b1eddb6 100644
--- a/internal/praefect/nodes/manager_test.go
+++ b/internal/praefect/nodes/manager_test.go
@@ -10,7 +10,6 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/client"
- "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag"
"gitlab.com/gitlab-org/gitaly/internal/praefect/config"
"gitlab.com/gitlab-org/gitaly/internal/praefect/datastore"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
@@ -72,9 +71,11 @@ func TestNodeStatus(t *testing.T) {
storageName := "default"
cs := newConnectionStatus(config.Node{Storage: storageName}, cc, testhelper.DiscardTestEntry(t), mockHistogramVec)
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
var expectedLabels [][]string
for i := 0; i < healthcheckThreshold; i++ {
- ctx := context.Background()
status, err := cs.CheckHealth(ctx)
require.NoError(t, err)
@@ -87,7 +88,6 @@ func TestNodeStatus(t *testing.T) {
healthSvr.SetServingStatus("", grpc_health_v1.HealthCheckResponse_NOT_SERVING)
- ctx := context.Background()
status, err := cs.CheckHealth(ctx)
require.NoError(t, err)
require.False(t, status)
@@ -380,8 +380,6 @@ func TestMgr_GetSyncedNode(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- ctx = featureflag.IncomingCtxWithFeatureFlag(ctx, featureflag.DistributedReads)
-
verify := func(scenario func(t *testing.T, nm Manager, rs datastore.RepositoryStore)) func(*testing.T) {
rs := datastore.NewMemoryRepositoryStore(conf.StorageNames())
diff --git a/internal/praefect/server_factory_test.go b/internal/praefect/server_factory_test.go
index 7d4939db4..293659c46 100644
--- a/internal/praefect/server_factory_test.go
+++ b/internal/praefect/server_factory_test.go
@@ -7,6 +7,7 @@ import (
"net"
"os"
"testing"
+ "time"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/client"
@@ -68,6 +69,7 @@ func TestServerFactory(t *testing.T) {
},
},
},
+ Failover: config.Failover{Enabled: true},
}
repo, repoPath, cleanup := testhelper.NewTestRepo(t)
@@ -77,8 +79,9 @@ func TestServerFactory(t *testing.T) {
logger := testhelper.DiscardTestEntry(t)
queue := datastore.NewMemoryReplicationEventQueue(conf)
- nodeMgr, err := nodes.NewManager(logger, conf, nil, nil, &promtest.MockHistogramVec{})
+ nodeMgr, err := nodes.NewManager(logger, conf, nil, datastore.NewMemoryRepositoryStore(conf.StorageNames()), &promtest.MockHistogramVec{})
require.NoError(t, err)
+ nodeMgr.Start(0, time.Second)
txMgr := transactions.NewManager()
registry := protoregistry.GitalyProtoPreregistered
rs := datastore.NewMemoryRepositoryStore(conf.StorageNames())
diff --git a/internal/praefect/server_test.go b/internal/praefect/server_test.go
index 246b9be50..64d0264cf 100644
--- a/internal/praefect/server_test.go
+++ b/internal/praefect/server_test.go
@@ -24,7 +24,6 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/helper"
"gitlab.com/gitlab-org/gitaly/internal/helper/text"
- "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag"
"gitlab.com/gitlab-org/gitaly/internal/praefect/config"
"gitlab.com/gitlab-org/gitaly/internal/praefect/datastore"
"gitlab.com/gitlab-org/gitaly/internal/praefect/grpc-proxy/proxy"
@@ -79,7 +78,7 @@ func TestServerRouteServerAccessor(t *testing.T) {
"received unexpected request value: %+v instead of %+v", actualReq, expectReq)
}()
- ctx, cancel := context.WithTimeout(context.Background(), time.Second)
+ ctx, cancel := testhelper.Context(testhelper.ContextWithTimeout(time.Second))
defer cancel()
actualResp, err := cli.ServerAccessor(ctx, expectReq)
@@ -223,7 +222,7 @@ func TestHealthCheck(t *testing.T) {
cc, _, cleanup := runPraefectServerWithGitaly(t, testConfig(1))
defer cleanup()
- ctx, cancel := context.WithTimeout(context.Background(), time.Second)
+ ctx, cancel := testhelper.Context(testhelper.ContextWithTimeout(time.Second))
defer cancel()
client := grpc_health_v1.NewHealthClient(cc)
@@ -474,11 +473,9 @@ func TestRepoRemoval(t *testing.T) {
})
require.NoError(t, err)
- resp, err := rClient.RepositoryExists(ctx, &gitalypb.RepositoryExistsRequest{
- Repository: &virtualRepo,
- })
- require.NoError(t, err)
- require.Equal(t, false, resp.GetExists())
+ storage, ok := gconfig.Config.Storage(conf.VirtualStorages[0].Nodes[0].Storage)
+ require.True(t, ok)
+ testhelper.AssertPathNotExists(t, filepath.Join(storage.Path, tRepo.RelativePath))
var jobsDone int
for {
@@ -533,6 +530,7 @@ func TestRepoRename(t *testing.T) {
},
},
},
+ Failover: config.Failover{Enabled: true},
}
virtualStorage := conf.VirtualStorages[0]
@@ -834,8 +832,6 @@ func TestProxyWrites(t *testing.T) {
waitNodeToChangeHealthStatus(ctx, t, node, true)
}
- ctx = featureflag.OutgoingCtxWithFeatureFlags(ctx, featureflag.ReferenceTransactions)
-
stream, err := client.PostReceivePack(ctx)
require.NoError(t, err)
diff --git a/internal/praefect/transaction_test.go b/internal/praefect/transaction_test.go
index 9f927cbd1..e997157a6 100644
--- a/internal/praefect/transaction_test.go
+++ b/internal/praefect/transaction_test.go
@@ -1,7 +1,6 @@
package praefect
import (
- "context"
"crypto/sha1"
"fmt"
"sync"
@@ -73,7 +72,7 @@ func TestTransactionSucceeds(t *testing.T) {
cc, txMgr, cleanup := runPraefectServerAndTxMgr(t, opts...)
defer cleanup()
- ctx, cancel := context.WithTimeout(context.Background(), time.Second)
+ ctx, cancel := testhelper.Context(testhelper.ContextWithTimeout(time.Second))
defer cancel()
client := gitalypb.NewRefTransactionClient(cc)
@@ -557,7 +556,7 @@ func TestTransactionFailures(t *testing.T) {
cc, _, cleanup := runPraefectServerAndTxMgr(t, opts...)
defer cleanup()
- ctx, cancel := context.WithTimeout(context.Background(), time.Second)
+ ctx, cancel := testhelper.Context(testhelper.ContextWithTimeout(time.Second))
defer cancel()
client := gitalypb.NewRefTransactionClient(cc)
@@ -628,7 +627,7 @@ func TestTransactionCancellation(t *testing.T) {
cc, txMgr, cleanup := runPraefectServerAndTxMgr(t, opts...)
defer cleanup()
- ctx, cancel := context.WithTimeout(context.Background(), time.Second)
+ ctx, cancel := testhelper.Context(testhelper.ContextWithTimeout(time.Second))
defer cancel()
client := gitalypb.NewRefTransactionClient(cc)
diff --git a/internal/rubyserver/concurrency_test.go b/internal/rubyserver/concurrency_test.go
index f9b50896d..37310c25f 100644
--- a/internal/rubyserver/concurrency_test.go
+++ b/internal/rubyserver/concurrency_test.go
@@ -1,7 +1,6 @@
package rubyserver
import (
- "context"
"fmt"
"sync"
"testing"
@@ -9,6 +8,7 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/config"
+ "gitlab.com/gitlab-org/gitaly/internal/testhelper"
"google.golang.org/grpc/codes"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/status"
@@ -84,7 +84,7 @@ func BenchmarkConcurrency(b *testing.B) {
}
func makeRequest(s *Server) error {
- ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
+ ctx, cancel := testhelper.Context(testhelper.ContextWithTimeout(time.Second))
defer cancel()
conn, err := s.getConnection(ctx)
diff --git a/internal/service/commit/between_test.go b/internal/service/commit/between_test.go
index 78f678aaf..14cdbd4c0 100644
--- a/internal/service/commit/between_test.go
+++ b/internal/service/commit/between_test.go
@@ -1,7 +1,6 @@
package commit
import (
- "context"
"io"
"testing"
@@ -173,7 +172,7 @@ func TestSuccessfulCommitsBetween(t *testing.T) {
Repository: testRepo, From: tc.from, To: tc.to,
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitsBetween(ctx, &rpcRequest)
if err != nil {
@@ -266,7 +265,7 @@ func TestFailedCommitsBetweenRequest(t *testing.T) {
Repository: tc.repository, From: tc.from, To: tc.to,
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitsBetween(ctx, &rpcRequest)
if err != nil {
diff --git a/internal/service/commit/commits_by_message_test.go b/internal/service/commit/commits_by_message_test.go
index 27edfb02a..1077d536d 100644
--- a/internal/service/commit/commits_by_message_test.go
+++ b/internal/service/commit/commits_by_message_test.go
@@ -1,7 +1,6 @@
package commit
import (
- "context"
"io"
"testing"
@@ -145,7 +144,7 @@ func TestSuccessfulCommitsByMessageRequest(t *testing.T) {
request := testCase.request
request.Repository = testRepo
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitsByMessage(ctx, request)
if err != nil {
@@ -214,7 +213,7 @@ func TestFailedCommitsByMessageRequest(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitsByMessage(ctx, testCase.request)
if err != nil {
diff --git a/internal/service/commit/count_commits_test.go b/internal/service/commit/count_commits_test.go
index 85c8189fc..3d840dc07 100644
--- a/internal/service/commit/count_commits_test.go
+++ b/internal/service/commit/count_commits_test.go
@@ -1,7 +1,6 @@
package commit
import (
- "context"
"fmt"
"testing"
"time"
@@ -172,7 +171,7 @@ func TestSuccessfulCountCommitsRequest(t *testing.T) {
request.Path = testCase.path
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
response, err := client.CountCommits(ctx, request)
if err != nil {
@@ -205,7 +204,7 @@ func TestFailedCountCommitsRequestDueToValidationError(t *testing.T) {
for _, rpcRequest := range rpcRequests {
t.Run(fmt.Sprintf("%v", rpcRequest), func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
_, err := client.CountCommits(ctx, &rpcRequest)
testhelper.RequireGrpcError(t, err, codes.InvalidArgument)
diff --git a/internal/service/commit/count_diverging_commits_test.go b/internal/service/commit/count_diverging_commits_test.go
index 928a9143a..c22b26ce4 100644
--- a/internal/service/commit/count_diverging_commits_test.go
+++ b/internal/service/commit/count_diverging_commits_test.go
@@ -1,7 +1,6 @@
package commit
import (
- "context"
"fmt"
"testing"
@@ -126,7 +125,7 @@ func TestSuccessfulCountDivergentCommitsRequest(t *testing.T) {
To: []byte(testCase.rightRevision),
MaxCount: int32(1000),
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
response, err := client.CountDivergingCommits(ctx, request)
require.NoError(t, err)
@@ -176,7 +175,7 @@ func TestSuccessfulCountDivergentCommitsRequestWithMaxCount(t *testing.T) {
To: []byte(testCase.rightRevision),
MaxCount: int32(testCase.maxCount),
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
response, err := client.CountDivergingCommits(ctx, request)
require.NoError(t, err)
diff --git a/internal/service/commit/find_all_commits_test.go b/internal/service/commit/find_all_commits_test.go
index e79b1ae45..e64685ab6 100644
--- a/internal/service/commit/find_all_commits_test.go
+++ b/internal/service/commit/find_all_commits_test.go
@@ -266,7 +266,7 @@ func TestSuccessfulFindAllCommitsRequest(t *testing.T) {
request := testCase.request
request.Repository = testRepo
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.FindAllCommits(ctx, request)
if err != nil {
@@ -323,7 +323,7 @@ func TestFailedFindAllCommitsRequest(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.FindAllCommits(ctx, testCase.request)
if err != nil {
diff --git a/internal/service/commit/find_commit_test.go b/internal/service/commit/find_commit_test.go
index 96367f559..9ada6c2b3 100644
--- a/internal/service/commit/find_commit_test.go
+++ b/internal/service/commit/find_commit_test.go
@@ -2,7 +2,6 @@ package commit
import (
"bufio"
- "context"
"io/ioutil"
"strings"
"testing"
@@ -257,7 +256,7 @@ func TestSuccessfulFindCommitRequest(t *testing.T) {
Revision: []byte(testCase.revision),
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
response, err := client.FindCommit(ctx, request)
require.NoError(t, err)
@@ -292,7 +291,7 @@ func TestFailedFindCommitRequest(t *testing.T) {
{repo: testRepo, revision: []byte("mas:ter"), description: "Invalid revision"},
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
for _, testCase := range testCases {
diff --git a/internal/service/commit/find_commits_test.go b/internal/service/commit/find_commits_test.go
index c268b8a27..8e906a3c9 100644
--- a/internal/service/commit/find_commits_test.go
+++ b/internal/service/commit/find_commits_test.go
@@ -159,7 +159,7 @@ func TestFindCommitsFields(t *testing.T) {
Limit: 1,
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
stream, err := client.FindCommits(ctx, request)
require.NoError(t, err)
diff --git a/internal/service/commit/isancestor_test.go b/internal/service/commit/isancestor_test.go
index b1d22eae9..48998d09a 100644
--- a/internal/service/commit/isancestor_test.go
+++ b/internal/service/commit/isancestor_test.go
@@ -1,7 +1,6 @@
package commit
import (
- "context"
"fmt"
"os/exec"
"testing"
@@ -68,7 +67,7 @@ func TestCommitIsAncestorFailure(t *testing.T) {
for _, v := range queries {
t.Run(fmt.Sprintf("%v", v.Request), func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
if _, err := client.CommitIsAncestor(ctx, v.Request); err == nil {
t.Error("Expected to throw an error")
@@ -161,7 +160,7 @@ func TestCommitIsAncestorSuccess(t *testing.T) {
for _, v := range queries {
t.Run(fmt.Sprintf("%v", v.Request), func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitIsAncestor(ctx, v.Request)
if err != nil {
@@ -224,7 +223,7 @@ func TestSuccessfulIsAncestorRequestWithAltGitObjectDirs(t *testing.T) {
ChildId: string(currentHead),
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
response, err := client.CommitIsAncestor(ctx, request)
if err != nil {
diff --git a/internal/service/commit/languages_test.go b/internal/service/commit/languages_test.go
index 3e7a79440..ce96393f7 100644
--- a/internal/service/commit/languages_test.go
+++ b/internal/service/commit/languages_test.go
@@ -1,7 +1,6 @@
package commit
import (
- "context"
"testing"
"github.com/stretchr/testify/require"
@@ -25,7 +24,7 @@ func TestLanguages(t *testing.T) {
Revision: []byte("cb19058ecc02d01f8e4290b7e79cafd16a8839b6"),
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
resp, err := client.CommitLanguages(ctx, request)
@@ -66,7 +65,7 @@ func TestFileCountIsZeroWhenFeatureIsDisabled(t *testing.T) {
Revision: []byte("cb19058ecc02d01f8e4290b7e79cafd16a8839b6"),
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
resp, err := client.CommitLanguages(ctx, request)
@@ -101,7 +100,7 @@ func TestLanguagesEmptyRevision(t *testing.T) {
Repository: testRepo,
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
resp, err := client.CommitLanguages(ctx, request)
require.NoError(t, err)
diff --git a/internal/service/commit/last_commit_for_path_test.go b/internal/service/commit/last_commit_for_path_test.go
index 9e3741f30..859129e5b 100644
--- a/internal/service/commit/last_commit_for_path_test.go
+++ b/internal/service/commit/last_commit_for_path_test.go
@@ -1,7 +1,6 @@
package commit
import (
- "context"
"testing"
"github.com/golang/protobuf/ptypes/timestamp"
@@ -86,7 +85,7 @@ func TestSuccessfulLastCommitForPathRequest(t *testing.T) {
Path: testCase.path,
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
response, err := client.LastCommitForPath(ctx, request)
if err != nil {
@@ -141,7 +140,7 @@ func TestFailedLastCommitForPathRequest(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
_, err := client.LastCommitForPath(ctx, testCase.request)
testhelper.RequireGrpcError(t, err, testCase.code)
@@ -177,7 +176,7 @@ func TestSuccessfulLastCommitWithGlobCharacters(t *testing.T) {
LiteralPathspec: true,
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
response, err := client.LastCommitForPath(ctx, request)
require.NoError(t, err)
diff --git a/internal/service/commit/list_commits_by_oid_test.go b/internal/service/commit/list_commits_by_oid_test.go
index 7b3435350..3dd2cbb46 100644
--- a/internal/service/commit/list_commits_by_oid_test.go
+++ b/internal/service/commit/list_commits_by_oid_test.go
@@ -1,7 +1,6 @@
package commit
import (
- "context"
"io"
"testing"
@@ -95,7 +94,7 @@ func TestSuccessfulListCommitsByOidRequest(t *testing.T) {
request := testCase.request
request.Repository = testRepo
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.ListCommitsByOid(ctx, request)
if err != nil {
diff --git a/internal/service/commit/list_files_test.go b/internal/service/commit/list_files_test.go
index 1efcf4428..12cae000f 100644
--- a/internal/service/commit/list_files_test.go
+++ b/internal/service/commit/list_files_test.go
@@ -104,7 +104,7 @@ func TestListFilesSuccess(t *testing.T) {
Repository: testRepo, Revision: []byte(test.revision),
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.ListFiles(ctx, &rpcRequest)
if err != nil {
@@ -161,7 +161,7 @@ func TestListFilesFailure(t *testing.T) {
Repository: test.repo, Revision: []byte("master"),
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.ListFiles(ctx, &rpcRequest)
if err != nil {
diff --git a/internal/service/commit/list_last_commits_for_tree_test.go b/internal/service/commit/list_last_commits_for_tree_test.go
index 33d938cf6..86eba6cac 100644
--- a/internal/service/commit/list_last_commits_for_tree_test.go
+++ b/internal/service/commit/list_last_commits_for_tree_test.go
@@ -2,7 +2,6 @@ package commit
import (
"bytes"
- "context"
"io"
"os"
"path/filepath"
@@ -188,7 +187,7 @@ func TestSuccessfulListLastCommitsForTreeRequest(t *testing.T) {
Offset: testCase.offset,
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
stream, err := client.ListLastCommitsForTree(ctx, request)
@@ -404,7 +403,7 @@ func TestSuccessfulListLastCommitsForTreeRequestWithGlobCharacters(t *testing.T)
Offset: 0,
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
stream, err := client.ListLastCommitsForTree(ctx, request)
require.NoError(t, err)
diff --git a/internal/service/commit/raw_blame_test.go b/internal/service/commit/raw_blame_test.go
index 034b9f1ce..2c373cf5a 100644
--- a/internal/service/commit/raw_blame_test.go
+++ b/internal/service/commit/raw_blame_test.go
@@ -1,7 +1,6 @@
package commit
import (
- "context"
"fmt"
"io/ioutil"
"testing"
@@ -51,7 +50,7 @@ func TestSuccessfulRawBlameRequest(t *testing.T) {
Path: testCase.path,
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.RawBlame(ctx, request)
if err != nil {
@@ -129,7 +128,7 @@ func TestFailedRawBlameRequest(t *testing.T) {
Path: testCase.path,
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.RawBlame(ctx, &request)
if err != nil {
diff --git a/internal/service/commit/stats_test.go b/internal/service/commit/stats_test.go
index 2d9236754..b69046a12 100644
--- a/internal/service/commit/stats_test.go
+++ b/internal/service/commit/stats_test.go
@@ -1,7 +1,6 @@
package commit
import (
- "context"
"testing"
"github.com/stretchr/testify/assert"
@@ -18,7 +17,7 @@ func TestCommitStatsSuccess(t *testing.T) {
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
@@ -89,7 +88,7 @@ func TestCommitStatsFailure(t *testing.T) {
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
diff --git a/internal/service/commit/tree_entries_test.go b/internal/service/commit/tree_entries_test.go
index 6c7af65e7..57a03020f 100644
--- a/internal/service/commit/tree_entries_test.go
+++ b/internal/service/commit/tree_entries_test.go
@@ -1,7 +1,6 @@
package commit
import (
- "context"
"fmt"
"io"
"os"
@@ -69,7 +68,7 @@ func TestSuccessfulGetTreeEntriesWithCurlyBraces(t *testing.T) {
Recursive: testCase.recursive,
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.GetTreeEntries(ctx, request)
if err != nil {
@@ -381,7 +380,7 @@ func TestSuccessfulGetTreeEntries(t *testing.T) {
Recursive: testCase.recursive,
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.GetTreeEntries(ctx, request)
if err != nil {
@@ -440,7 +439,7 @@ func TestSuccessfulGetTreeEntries_FlatPathMaxDeep_SingleFoldersStructure(t *test
Recursive: false,
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
// request entries of the tree with single-folder structure on each level
@@ -485,7 +484,7 @@ func TestFailedGetTreeEntriesRequestDueToValidationError(t *testing.T) {
for _, rpcRequest := range rpcRequests {
t.Run(fmt.Sprintf("%v", rpcRequest), func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.GetTreeEntries(ctx, &rpcRequest)
if err != nil {
diff --git a/internal/service/commit/tree_entry_test.go b/internal/service/commit/tree_entry_test.go
index 32a68a970..8c0af7566 100644
--- a/internal/service/commit/tree_entry_test.go
+++ b/internal/service/commit/tree_entry_test.go
@@ -2,7 +2,6 @@ package commit
import (
"bytes"
- "context"
"fmt"
"io"
"testing"
@@ -147,7 +146,7 @@ func TestSuccessfulTreeEntry(t *testing.T) {
Limit: testCase.limit,
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.TreeEntry(ctx, request)
if err != nil {
@@ -182,7 +181,7 @@ func TestFailedTreeEntryRequestDueToValidationError(t *testing.T) {
for _, rpcRequest := range rpcRequests {
t.Run(fmt.Sprintf("%+v", rpcRequest), func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.TreeEntry(ctx, &rpcRequest)
if err != nil {
diff --git a/internal/service/diff/commit_test.go b/internal/service/diff/commit_test.go
index 9953d276a..a4e760faf 100644
--- a/internal/service/diff/commit_test.go
+++ b/internal/service/diff/commit_test.go
@@ -2,7 +2,6 @@ package diff
import (
"bytes"
- "context"
"fmt"
"io"
"testing"
@@ -179,7 +178,7 @@ func TestSuccessfulCommitDiffRequest(t *testing.T) {
testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "config", "diff.noprefix", testCase.noPrefixConfig)
rpcRequest := &gitalypb.CommitDiffRequest{Repository: testRepo, RightCommitId: rightCommit, LeftCommitId: leftCommit, IgnoreWhitespaceChange: false}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDiff(ctx, rpcRequest)
if err != nil {
@@ -216,7 +215,7 @@ func TestSuccessfulCommitDiffRequestWithPaths(t *testing.T) {
},
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDiff(ctx, rpcRequest)
if err != nil {
@@ -287,7 +286,7 @@ func TestSuccessfulCommitDiffRequestWithTypeChangeDiff(t *testing.T) {
LeftCommitId: leftCommit,
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDiff(ctx, rpcRequest)
if err != nil {
@@ -422,7 +421,7 @@ func TestSuccessfulCommitDiffRequestWithIgnoreWhitespaceChange(t *testing.T) {
Paths: entry.paths,
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDiff(ctx, rpcRequest)
if err != nil {
@@ -630,7 +629,7 @@ func TestSuccessfulCommitDiffRequestWithLimits(t *testing.T) {
request.LeftCommitId = leftCommit
request.RightCommitId = rightCommit
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDiff(ctx, &request)
if err != nil {
@@ -678,7 +677,7 @@ func TestFailedCommitDiffRequestDueToValidationError(t *testing.T) {
for _, rpcRequest := range rpcRequests {
t.Run(fmt.Sprintf("%v", rpcRequest), func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDiff(ctx, &rpcRequest)
if err != nil {
@@ -705,7 +704,7 @@ func TestFailedCommitDiffRequestWithNonExistentCommit(t *testing.T) {
leftCommit := nonExistentCommitID + "~" // Parent of rightCommit
rpcRequest := &gitalypb.CommitDiffRequest{Repository: testRepo, RightCommitId: nonExistentCommitID, LeftCommitId: leftCommit}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDiff(ctx, rpcRequest)
if err != nil {
@@ -730,7 +729,7 @@ func TestSuccessfulCommitDeltaRequest(t *testing.T) {
leftCommit := "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab"
rpcRequest := &gitalypb.CommitDeltaRequest{Repository: testRepo, RightCommitId: rightCommit, LeftCommitId: leftCommit}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDelta(ctx, rpcRequest)
if err != nil {
@@ -863,7 +862,7 @@ func TestSuccessfulCommitDeltaRequestWithPaths(t *testing.T) {
},
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDelta(ctx, rpcRequest)
if err != nil {
@@ -930,7 +929,7 @@ func TestFailedCommitDeltaRequestDueToValidationError(t *testing.T) {
for _, rpcRequest := range rpcRequests {
t.Run(fmt.Sprintf("%v", rpcRequest), func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDelta(ctx, &rpcRequest)
if err != nil {
@@ -957,7 +956,7 @@ func TestFailedCommitDeltaRequestWithNonExistentCommit(t *testing.T) {
leftCommit := nonExistentCommitID + "~" // Parent of rightCommit
rpcRequest := &gitalypb.CommitDeltaRequest{Repository: testRepo, RightCommitId: nonExistentCommitID, LeftCommitId: leftCommit}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.CommitDelta(ctx, rpcRequest)
if err != nil {
diff --git a/internal/service/diff/numstat_test.go b/internal/service/diff/numstat_test.go
index 073e1323c..160794c21 100644
--- a/internal/service/diff/numstat_test.go
+++ b/internal/service/diff/numstat_test.go
@@ -1,7 +1,6 @@
package diff
import (
- "context"
"io"
"testing"
@@ -134,7 +133,7 @@ func TestFailedDiffStatsRequest(t *testing.T) {
client, conn := newDiffClient(t, serverSocketPath)
defer conn.Close()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
diff --git a/internal/service/inspect/inspector_test.go b/internal/service/inspect/inspector_test.go
index 33f6385bc..4f119f0e6 100644
--- a/internal/service/inspect/inspector_test.go
+++ b/internal/service/inspect/inspector_test.go
@@ -2,7 +2,6 @@ package inspect
import (
"bytes"
- "context"
"errors"
"io"
"io/ioutil"
@@ -13,6 +12,7 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/testhelper"
)
func TestWrite(t *testing.T) {
@@ -102,7 +102,11 @@ func TestLogPackInfoStatistic(t *testing.T) {
Formatter: &logrus.JSONFormatter{},
Level: logrus.InfoLevel,
}
- ctx := ctxlogrus.ToContext(context.Background(), log.WithField("test", "logging"))
+
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
+ ctx = ctxlogrus.ToContext(ctx, log.WithField("test", "logging"))
logging := LogPackInfoStatistic(ctx)
logging(strings.NewReader("0038\x41ACK 1e292f8fedd741b75372e19097c76d327140c312 ready\n0035\x02Total 1044 (delta 519), reused 1035 (delta 512)\n0038\x41ACK 1e292f8fedd741b75372e19097c76d327140c312 ready\n0000\x01"))
diff --git a/internal/service/namespace/namespace_test.go b/internal/service/namespace/namespace_test.go
index 58d68f534..a59d17fa0 100644
--- a/internal/service/namespace/namespace_test.go
+++ b/internal/service/namespace/namespace_test.go
@@ -1,7 +1,6 @@
package namespace
import (
- "context"
"log"
"os"
"path/filepath"
@@ -49,7 +48,7 @@ func TestNamespaceExists(t *testing.T) {
defer conn.Close()
// Create one namespace for testing it exists
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
const (
@@ -175,7 +174,7 @@ func TestAddNamespace(t *testing.T) {
for _, tc := range queries {
t.Run(tc.desc, func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
_, err := client.AddNamespace(ctx, tc.request)
@@ -199,7 +198,7 @@ func TestRemoveNamespace(t *testing.T) {
client, conn := newNamespaceClient(t, serverSocketPath)
defer conn.Close()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
const (
@@ -262,7 +261,7 @@ func TestRenameNamespace(t *testing.T) {
client, conn := newNamespaceClient(t, serverSocketPath)
defer conn.Close()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
const (
@@ -344,7 +343,7 @@ func TestRenameNamespaceWithNonexistentParentDir(t *testing.T) {
client, conn := newNamespaceClient(t, serverSocketPath)
defer conn.Close()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
_, err := client.AddNamespace(ctx, &gitalypb.AddNamespaceRequest{
diff --git a/internal/service/operations/branches_test.go b/internal/service/operations/branches_test.go
index 8720693dd..78d475103 100644
--- a/internal/service/operations/branches_test.go
+++ b/internal/service/operations/branches_test.go
@@ -83,7 +83,7 @@ func TestSuccessfulGitHooksForUserCreateBranchRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- ctx = featureSet.WithParent(ctx)
+ ctx = featureSet.Disable(ctx)
testSuccessfulGitHooksForUserCreateBranchRequest(t, ctx)
}
@@ -149,7 +149,7 @@ func TestFailedUserCreateBranchDueToHooks(t *testing.T) {
require.NoError(t, err)
defer remove()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
response, err := client.UserCreateBranch(ctx, request)
@@ -215,7 +215,7 @@ func TestFailedUserCreateBranchRequest(t *testing.T) {
User: testCase.user,
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
_, err := client.UserCreateBranch(ctx, request)
@@ -229,11 +229,11 @@ func TestSuccessfulUserDeleteBranchRequest(t *testing.T) {
require.NoError(t, err)
for _, featureSet := range featureSets {
- t.Run(featureSet.String(), func(t *testing.T) {
+ t.Run("disabled "+featureSet.String(), func(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- ctx = featureSet.WithParent(ctx)
+ ctx = featureSet.Disable(ctx)
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
diff --git a/internal/service/operations/rebase_test.go b/internal/service/operations/rebase_test.go
index 2c6cecbdb..9967a5ae9 100644
--- a/internal/service/operations/rebase_test.go
+++ b/internal/service/operations/rebase_test.go
@@ -27,9 +27,6 @@ func TestSuccessfulUserRebaseConfirmableRequest(t *testing.T) {
featureSets, err := testhelper.NewFeatureSets(nil, featureflag.GoPostReceiveHook)
require.NoError(t, err)
- ctx, cancel := testhelper.Context()
- defer cancel()
-
var ruby rubyserver.Server
pushOptions := []string{"ci.skip", "test=value"}
@@ -44,7 +41,10 @@ func TestSuccessfulUserRebaseConfirmableRequest(t *testing.T) {
for _, featureSet := range featureSets {
t.Run(featureSet.String(), func(t *testing.T) {
- ctx := featureSet.WithParent(ctx)
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
+ ctx = featureSet.Disable(ctx)
testSuccessfulUserRebaseConfirmableRequest(t, ctx, serverSocketPath, pushOptions)
})
}
diff --git a/internal/service/operations/tags_test.go b/internal/service/operations/tags_test.go
index bc06a693c..549efdad3 100644
--- a/internal/service/operations/tags_test.go
+++ b/internal/service/operations/tags_test.go
@@ -22,11 +22,11 @@ func TestSuccessfulUserDeleteTagRequest(t *testing.T) {
require.NoError(t, err)
for _, featureSet := range featureSets {
- t.Run(featureSet.String(), func(t *testing.T) {
+ t.Run("disabled "+featureSet.String(), func(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- ctx = featureSet.WithParent(ctx)
+ ctx = featureSet.Disable(ctx)
serverSocketPath, stop := runOperationServiceServer(t)
defer stop()
@@ -59,15 +59,15 @@ func TestSuccessfulUserDeleteTagRequest(t *testing.T) {
}
func TestSuccessfulGitHooksForUserDeleteTagRequest(t *testing.T) {
- ctx, cancel := testhelper.Context()
- defer cancel()
-
featureSets, err := testhelper.NewFeatureSets(nil, featureflag.GoPostReceiveHook)
require.NoError(t, err)
for _, featureSet := range featureSets {
- t.Run(featureSet.String(), func(t *testing.T) {
- ctx := featureSet.WithParent(ctx)
+ t.Run("disabled "+featureSet.String(), func(t *testing.T) {
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
+ ctx = featureSet.Disable(ctx)
testSuccessfulGitHooksForUserDeleteTagRequest(t, ctx)
})
}
@@ -113,11 +113,11 @@ func TestSuccessfulUserCreateTagRequest(t *testing.T) {
require.NoError(t, err)
for _, featureSet := range featureSets {
- t.Run(featureSet.String(), func(t *testing.T) {
+ t.Run("disabled "+featureSet.String(), func(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- ctx = featureSet.WithParent(ctx)
+ ctx = featureSet.Disable(ctx)
serverSocketPath, stop := runOperationServiceServer(t)
defer stop()
@@ -191,9 +191,6 @@ func TestSuccessfulUserCreateTagRequest(t *testing.T) {
Message: []byte(testCase.message),
}
- ctx, cancel := testhelper.Context()
- defer cancel()
-
response, err := client.UserCreateTag(ctx, request)
require.NoError(t, err, "error from calling RPC")
require.Empty(t, response.PreReceiveError, "PreReceiveError must be empty, signalling the push was accepted")
diff --git a/internal/service/operations/update_branches_test.go b/internal/service/operations/update_branches_test.go
index 542d6cff2..cd00d5a4a 100644
--- a/internal/service/operations/update_branches_test.go
+++ b/internal/service/operations/update_branches_test.go
@@ -25,11 +25,11 @@ func TestSuccessfulUserUpdateBranchRequest(t *testing.T) {
require.NoError(t, err)
for _, featureSet := range featureSets {
- t.Run(featureSet.String(), func(t *testing.T) {
+ t.Run("disabled "+featureSet.String(), func(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- ctx = featureSet.WithParent(ctx)
+ ctx = featureSet.Disable(ctx)
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
@@ -104,12 +104,14 @@ func testSuccessfulGitHooksForUserUpdateBranchRequest(t *testing.T, ctx context.
func TestFailedUserUpdateBranchDueToHooks(t *testing.T) {
featureSet, err := testhelper.NewFeatureSets(nil, featureflag.GoUpdateHook)
require.NoError(t, err)
- ctx, cancel := testhelper.Context()
- defer cancel()
for _, features := range featureSet {
- t.Run(features.String(), func(t *testing.T) {
- ctx = features.WithParent(ctx)
+ t.Run("disabled "+features.String(), func(t *testing.T) {
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
+ ctx = features.Disable(ctx)
+
testFailedUserUpdateBranchDueToHooks(t, ctx)
})
}
@@ -236,7 +238,7 @@ func TestFailedUserUpdateBranchRequest(t *testing.T) {
User: testCase.user,
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
_, err := client.UserUpdateBranch(ctx, request)
diff --git a/internal/service/ref/branches_test.go b/internal/service/ref/branches_test.go
index 354cbdf14..0dbde77a8 100644
--- a/internal/service/ref/branches_test.go
+++ b/internal/service/ref/branches_test.go
@@ -1,7 +1,6 @@
package ref
import (
- "context"
"testing"
"github.com/stretchr/testify/require"
@@ -66,7 +65,7 @@ func TestSuccessfulFindBranchRequest(t *testing.T) {
Name: []byte(testCase.branchName),
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
response, err := client.FindBranch(ctx, request)
@@ -106,7 +105,7 @@ func TestFailedFindBranchRequest(t *testing.T) {
Name: []byte(testCase.branchName),
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
_, err := client.FindBranch(ctx, request)
diff --git a/internal/service/ref/refname_test.go b/internal/service/ref/refname_test.go
index 46699a56c..0b67a0b9b 100644
--- a/internal/service/ref/refname_test.go
+++ b/internal/service/ref/refname_test.go
@@ -1,7 +1,6 @@
package ref
import (
- "context"
"testing"
"github.com/stretchr/testify/require"
@@ -28,7 +27,7 @@ func TestFindRefNameSuccess(t *testing.T) {
Prefix: []byte(`refs/heads/`),
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.FindRefName(ctx, rpcRequest)
if err != nil {
@@ -58,7 +57,7 @@ func TestFindRefNameEmptyCommit(t *testing.T) {
Prefix: []byte(`refs/heads/`),
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.FindRefName(ctx, rpcRequest)
if err == nil {
@@ -87,7 +86,7 @@ func TestFindRefNameInvalidRepo(t *testing.T) {
Prefix: []byte(`refs/heads/`),
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.FindRefName(ctx, rpcRequest)
if err == nil {
@@ -119,7 +118,7 @@ func TestFindRefNameInvalidPrefix(t *testing.T) {
Prefix: []byte(`refs/nonexistant/`),
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.FindRefName(ctx, rpcRequest)
if err != nil {
@@ -145,7 +144,7 @@ func TestFindRefNameInvalidObject(t *testing.T) {
CommitId: "dead1234dead1234dead1234dead1234dead1234",
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.FindRefName(ctx, rpcRequest)
if err != nil {
diff --git a/internal/service/ref/refs_test.go b/internal/service/ref/refs_test.go
index c3dff3f37..cb98c6205 100644
--- a/internal/service/ref/refs_test.go
+++ b/internal/service/ref/refs_test.go
@@ -43,7 +43,7 @@ func TestSuccessfulFindAllBranchNames(t *testing.T) {
rpcRequest := &gitalypb.FindAllBranchNamesRequest{Repository: testRepo}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.FindAllBranchNames(ctx, rpcRequest)
require.NoError(t, err)
@@ -77,7 +77,7 @@ func TestFindAllBranchNamesVeryLargeResponse(t *testing.T) {
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
updater, err := updateref.New(ctx, testRepo)
@@ -131,7 +131,7 @@ func TestEmptyFindAllBranchNamesRequest(t *testing.T) {
defer conn.Close()
rpcRequest := &gitalypb.FindAllBranchNamesRequest{}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.FindAllBranchNames(ctx, rpcRequest)
if err != nil {
@@ -157,7 +157,7 @@ func TestInvalidRepoFindAllBranchNamesRequest(t *testing.T) {
repo := &gitalypb.Repository{StorageName: "default", RelativePath: "made/up/path"}
rpcRequest := &gitalypb.FindAllBranchNamesRequest{Repository: repo}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.FindAllBranchNames(ctx, rpcRequest)
if err != nil {
@@ -186,7 +186,7 @@ func TestSuccessfulFindAllTagNames(t *testing.T) {
rpcRequest := &gitalypb.FindAllTagNamesRequest{Repository: testRepo}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.FindAllTagNames(ctx, rpcRequest)
if err != nil {
@@ -220,7 +220,7 @@ func TestEmptyFindAllTagNamesRequest(t *testing.T) {
defer conn.Close()
rpcRequest := &gitalypb.FindAllTagNamesRequest{}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.FindAllTagNames(ctx, rpcRequest)
if err != nil {
@@ -246,7 +246,7 @@ func TestInvalidRepoFindAllTagNamesRequest(t *testing.T) {
repo := &gitalypb.Repository{StorageName: "default", RelativePath: "made/up/path"}
rpcRequest := &gitalypb.FindAllTagNamesRequest{Repository: repo}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.FindAllTagNames(ctx, rpcRequest)
if err != nil {
@@ -264,7 +264,7 @@ func TestInvalidRepoFindAllTagNamesRequest(t *testing.T) {
}
func TestHeadReference(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
@@ -290,7 +290,7 @@ func TestHeadReferenceWithNonExistingHead(t *testing.T) {
ioutil.WriteFile(testRepoPath+"/HEAD", []byte("ref: refs/heads/master"), 0644)
}()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
headRef, err := headReference(ctx, testRepo)
if err != nil {
@@ -321,7 +321,7 @@ func TestSetDefaultBranchRef(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
@@ -398,7 +398,7 @@ func TestDefaultBranchName(t *testing.T) {
FindBranchNames = testCase.findBranchNames
headReference = testCase.headReference
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
defaultBranch, err := DefaultBranchName(ctx, testRepo)
if err != nil {
@@ -422,7 +422,7 @@ func TestSuccessfulFindDefaultBranchName(t *testing.T) {
rpcRequest := &gitalypb.FindDefaultBranchNameRequest{Repository: testRepo}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
r, err := client.FindDefaultBranchName(ctx, rpcRequest)
if err != nil {
@@ -442,7 +442,7 @@ func TestEmptyFindDefaultBranchNameRequest(t *testing.T) {
defer conn.Close()
rpcRequest := &gitalypb.FindDefaultBranchNameRequest{}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
_, err := client.FindDefaultBranchName(ctx, rpcRequest)
@@ -460,7 +460,7 @@ func TestInvalidRepoFindDefaultBranchNameRequest(t *testing.T) {
repo := &gitalypb.Repository{StorageName: "default", RelativePath: "/made/up/path"}
rpcRequest := &gitalypb.FindDefaultBranchNameRequest{Repository: repo}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
_, err := client.FindDefaultBranchName(ctx, rpcRequest)
@@ -862,7 +862,7 @@ func TestInvalidFindAllTagsRequest(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.FindAllTags(ctx, tc.request)
if err != nil {
@@ -891,7 +891,7 @@ func TestSuccessfulFindLocalBranches(t *testing.T) {
rpcRequest := &gitalypb.FindLocalBranchesRequest{Repository: testRepo}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.FindLocalBranches(ctx, rpcRequest)
if err != nil {
@@ -1049,7 +1049,7 @@ func TestFindLocalBranchesSort(t *testing.T) {
t.Run(testCase.desc, func(t *testing.T) {
rpcRequest := &gitalypb.FindLocalBranchesRequest{Repository: testRepo, SortBy: testCase.sortBy}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.FindLocalBranches(ctx, rpcRequest)
if err != nil {
@@ -1085,7 +1085,7 @@ func TestEmptyFindLocalBranchesRequest(t *testing.T) {
defer conn.Close()
rpcRequest := &gitalypb.FindLocalBranchesRequest{}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.FindLocalBranches(ctx, rpcRequest)
if err != nil {
@@ -1139,7 +1139,7 @@ func TestSuccessfulFindAllBranchesRequest(t *testing.T) {
request := &gitalypb.FindAllBranchesRequest{Repository: testRepo}
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.FindAllBranches(ctx, request)
if err != nil {
@@ -1281,7 +1281,7 @@ func TestInvalidFindAllBranchesRequest(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.FindAllBranches(ctx, &tc.request)
if err != nil {
@@ -1451,7 +1451,7 @@ func TestListBranchNamesContainingCommit(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
request := &gitalypb.ListBranchNamesContainingCommitRequest{Repository: testRepo, CommitId: tc.commitID}
@@ -1836,7 +1836,7 @@ func TestInvalidFindTagRequest(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
_, err := client.FindTag(ctx, tc.request)
testhelper.RequireGrpcError(t, err, codes.InvalidArgument)
diff --git a/internal/service/ref/remote_branches_test.go b/internal/service/ref/remote_branches_test.go
index f62a5f5bb..a88ca9f61 100644
--- a/internal/service/ref/remote_branches_test.go
+++ b/internal/service/ref/remote_branches_test.go
@@ -1,7 +1,6 @@
package ref
import (
- "context"
"io"
"testing"
@@ -113,7 +112,7 @@ func TestInvalidFindAllRemoteBranchesRequest(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.FindAllRemoteBranches(ctx, &tc.request)
if err != nil {
diff --git a/internal/service/remote/fetch_internal_remote_test.go b/internal/service/remote/fetch_internal_remote_test.go
index 4d0b26790..7aa1dd587 100644
--- a/internal/service/remote/fetch_internal_remote_test.go
+++ b/internal/service/remote/fetch_internal_remote_test.go
@@ -1,7 +1,6 @@
package remote_test
import (
- "context"
"net"
"os"
"testing"
@@ -119,7 +118,7 @@ func TestFailedFetchInternalRemoteDueToValidations(t *testing.T) {
client, conn := remote.NewRemoteClient(t, serverSocketPath)
defer conn.Close()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
repo := &gitalypb.Repository{StorageName: "default", RelativePath: "repo.git"}
diff --git a/internal/service/remote/remotes_test.go b/internal/service/remote/remotes_test.go
index 4d13eec2e..350b890cb 100644
--- a/internal/service/remote/remotes_test.go
+++ b/internal/service/remote/remotes_test.go
@@ -2,7 +2,6 @@ package remote
import (
"bytes"
- "context"
"fmt"
"io"
"net/http"
@@ -25,7 +24,7 @@ func TestSuccessfulAddRemote(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
testCases := []struct {
@@ -109,7 +108,7 @@ func TestFailedAddRemoteDueToValidation(t *testing.T) {
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
testCases := []struct {
@@ -156,7 +155,7 @@ func TestSuccessfulRemoveRemote(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "remote", "add", "my-remote", "http://my-repo.git")
@@ -206,7 +205,7 @@ func TestFailedRemoveRemoteDueToValidation(t *testing.T) {
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
request := &gitalypb.RemoveRemoteRequest{Repository: testRepo} // Remote name empty
@@ -278,7 +277,7 @@ func TestListDifferentPushUrlRemote(t *testing.T) {
client, conn := NewRemoteClient(t, serverSocketPath)
defer conn.Close()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
@@ -325,7 +324,7 @@ func TestListRemotes(t *testing.T) {
client, conn := NewRemoteClient(t, serverSocketPath)
defer conn.Close()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
repoWithSingleRemote, _, cleanupFn := testhelper.NewTestRepo(t)
diff --git a/internal/service/remote/update_remote_mirror_test.go b/internal/service/remote/update_remote_mirror_test.go
index e4afec87f..80b0d443e 100644
--- a/internal/service/remote/update_remote_mirror_test.go
+++ b/internal/service/remote/update_remote_mirror_test.go
@@ -1,7 +1,6 @@
package remote
import (
- "context"
"strings"
"testing"
@@ -295,7 +294,7 @@ func TestFailedUpdateRemoteMirrorRequestDueToValidation(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
stream, err := client.UpdateRemoteMirror(ctx)
diff --git a/internal/service/repository/fetch_test.go b/internal/service/repository/fetch_test.go
index 0fc89f1a4..355517c97 100644
--- a/internal/service/repository/fetch_test.go
+++ b/internal/service/repository/fetch_test.go
@@ -17,7 +17,6 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
- "google.golang.org/grpc/metadata"
)
func TestFetchSourceBranchSourceRepositorySuccess(t *testing.T) {
@@ -28,24 +27,25 @@ func TestFetchSourceBranchSourceRepositorySuccess(t *testing.T) {
defer conn.Close()
for _, tc := range []struct {
- desc string
- FeatureFlags []featureflag.FeatureFlag
+ desc string
+ disabledFeatures []featureflag.FeatureFlag
}{
{
- desc: "ruby",
+ desc: "go",
},
{
- desc: "go",
- FeatureFlags: []featureflag.FeatureFlag{featureflag.GoFetchSourceBranch},
+ desc: "ruby",
+ disabledFeatures: []featureflag.FeatureFlag{featureflag.GoFetchSourceBranch},
},
} {
t.Run(tc.desc, func(t *testing.T) {
- ctxOuter, cancel := testhelper.Context()
+ ctx, cancel := testhelper.Context()
defer cancel()
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
- ctx := metadata.NewOutgoingContext(ctxOuter, md)
- for _, feature := range tc.FeatureFlags {
+ ctx = testhelper.MergeOutgoingMetadata(ctx, md)
+
+ for _, feature := range tc.disabledFeatures {
ctx = featureflag.OutgoingCtxWithFeatureFlagValue(ctx, feature, "true")
}
@@ -85,25 +85,26 @@ func TestFetchSourceBranchSameRepositorySuccess(t *testing.T) {
defer conn.Close()
for _, tc := range []struct {
- desc string
- FeatureFlags []featureflag.FeatureFlag
+ desc string
+ disabledFeatures []featureflag.FeatureFlag
}{
{
- desc: "ruby",
+ desc: "go",
},
{
- desc: "go",
- FeatureFlags: []featureflag.FeatureFlag{featureflag.GoFetchSourceBranch},
+ desc: "ruby",
+ disabledFeatures: []featureflag.FeatureFlag{featureflag.GoFetchSourceBranch},
},
} {
t.Run(tc.desc, func(t *testing.T) {
- ctxOuter, cancel := testhelper.Context()
+ ctx, cancel := testhelper.Context()
defer cancel()
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
- ctx := metadata.NewOutgoingContext(ctxOuter, md)
- for _, feature := range tc.FeatureFlags {
- ctx = featureflag.OutgoingCtxWithFeatureFlagValue(ctx, feature, "true")
+ ctx = testhelper.MergeOutgoingMetadata(ctx, md)
+
+ for _, feature := range tc.disabledFeatures {
+ ctx = featureflag.OutgoingCtxWithFeatureFlagValue(ctx, feature, "false")
}
repo, repoPath, cleanup := newTestRepo(t, "fetch-source-source.git")
@@ -139,25 +140,26 @@ func TestFetchSourceBranchBranchNotFound(t *testing.T) {
defer conn.Close()
for _, tc := range []struct {
- desc string
- FeatureFlags []featureflag.FeatureFlag
+ desc string
+ disabledFeatures []featureflag.FeatureFlag
}{
{
- desc: "ruby",
+ desc: "go",
},
{
- desc: "go",
- FeatureFlags: []featureflag.FeatureFlag{featureflag.GoFetchSourceBranch},
+ desc: "ruby",
+ disabledFeatures: []featureflag.FeatureFlag{featureflag.GoFetchSourceBranch},
},
} {
t.Run(tc.desc, func(t *testing.T) {
- ctxOuter, cancel := testhelper.Context()
+ ctx, cancel := testhelper.Context()
defer cancel()
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
- ctx := metadata.NewOutgoingContext(ctxOuter, md)
- for _, feature := range tc.FeatureFlags {
- ctx = featureflag.OutgoingCtxWithFeatureFlagValue(ctx, feature, "true")
+ ctx = testhelper.MergeOutgoingMetadata(ctx, md)
+
+ for _, feature := range tc.disabledFeatures {
+ ctx = featureflag.OutgoingCtxWithFeatureFlagValue(ctx, feature, "false")
}
targetRepo, _, cleanup := newTestRepo(t, "fetch-source-target.git")
@@ -211,12 +213,11 @@ func TestFetchSourceBranchWrongRef(t *testing.T) {
client, conn := repository.NewRepositoryClient(t, serverSocketPath)
defer conn.Close()
- ctxOuter, cancel := testhelper.Context()
+ ctx, cancel := testhelper.Context()
defer cancel()
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
- ctx := metadata.NewOutgoingContext(ctxOuter, md)
- ctx = featureflag.OutgoingCtxWithFeatureFlagValue(ctx, featureflag.GoFetchSourceBranch, "true")
+ ctx = testhelper.MergeOutgoingMetadata(ctx, md)
targetRepo, _, cleanup := newTestRepo(t, "fetch-source-target.git")
defer cleanup()
diff --git a/internal/service/repository/gc_test.go b/internal/service/repository/gc_test.go
index 256a517fd..a0ba9c251 100644
--- a/internal/service/repository/gc_test.go
+++ b/internal/service/repository/gc_test.go
@@ -2,7 +2,6 @@ package repository
import (
"bytes"
- "context"
"fmt"
"io/ioutil"
"os"
@@ -97,7 +96,7 @@ func TestGarbageCollectSuccess(t *testing.T) {
// precision on `mtime`.
// Stamp taken from https://golang.org/pkg/time/#pkg-constants
testhelper.MustRunCommand(t, nil, "touch", "-t", testTimeString, packPath)
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.GarbageCollect(ctx, test.req)
assert.NoError(t, err)
@@ -222,7 +221,7 @@ func TestGarbageCollectFailure(t *testing.T) {
for _, test := range tests {
t.Run(fmt.Sprintf("%v", test.repo), func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
_, err := client.GarbageCollect(ctx, &gitalypb.GarbageCollectRequest{Repository: test.repo})
testhelper.RequireGrpcError(t, err, test.code)
@@ -338,7 +337,7 @@ func TestGarbageCollectDeltaIslands(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
gittest.TestDeltaIslands(t, testRepoPath, func() error {
diff --git a/internal/service/repository/repack_test.go b/internal/service/repository/repack_test.go
index b3b0d584d..bd2ec0635 100644
--- a/internal/service/repository/repack_test.go
+++ b/internal/service/repository/repack_test.go
@@ -2,7 +2,6 @@ package repository
import (
"bytes"
- "context"
"encoding/json"
"os/exec"
"path"
@@ -39,7 +38,7 @@ func TestRepackIncrementalSuccess(t *testing.T) {
// Stamp taken from https://golang.org/pkg/time/#pkg-constants
testhelper.MustRunCommand(t, nil, "touch", "-t", testTimeString, path.Join(packPath, "*"))
testTime := time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC)
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.RepackIncremental(ctx, &gitalypb.RepackIncrementalRequest{Repository: testRepo})
assert.NoError(t, err)
@@ -137,7 +136,7 @@ func TestRepackIncrementalFailure(t *testing.T) {
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
_, err := client.RepackIncremental(ctx, &gitalypb.RepackIncrementalRequest{Repository: test.repo})
testhelper.RequireGrpcError(t, err, test.code)
@@ -171,7 +170,7 @@ func TestRepackFullSuccess(t *testing.T) {
// precision on `mtime`.
testhelper.MustRunCommand(t, nil, "touch", "-t", testTimeString, packPath)
testTime := time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC)
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.RepackFull(ctx, test.req)
assert.NoError(t, err)
@@ -273,7 +272,7 @@ func TestRepackFullFailure(t *testing.T) {
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
_, err := client.RepackFull(ctx, &gitalypb.RepackFullRequest{Repository: test.repo})
testhelper.RequireGrpcError(t, err, test.code)
@@ -291,7 +290,7 @@ func TestRepackFullDeltaIslands(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
gittest.TestDeltaIslands(t, testRepoPath, func() error {
diff --git a/internal/service/repository/repository_test.go b/internal/service/repository/repository_test.go
index afc2e2ff4..3d3a34176 100644
--- a/internal/service/repository/repository_test.go
+++ b/internal/service/repository/repository_test.go
@@ -1,7 +1,6 @@
package repository
import (
- "context"
"io/ioutil"
"os"
"path"
@@ -105,7 +104,7 @@ func TestRepositoryExists(t *testing.T) {
for _, tc := range queries {
t.Run(tc.desc, func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
response, err := client.RepositoryExists(ctx, tc.request)
@@ -161,7 +160,7 @@ func TestSuccessfulHasLocalBranches(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
response, err := client.HasLocalBranches(ctx, tc.request)
@@ -202,7 +201,7 @@ func TestFailedHasLocalBranches(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
request := &gitalypb.HasLocalBranchesRequest{Repository: tc.repository}
diff --git a/internal/service/repository/size_test.go b/internal/service/repository/size_test.go
index c227f82c7..ff28183ff 100644
--- a/internal/service/repository/size_test.go
+++ b/internal/service/repository/size_test.go
@@ -1,7 +1,6 @@
package repository
import (
- "context"
"testing"
"github.com/stretchr/testify/require"
@@ -25,7 +24,7 @@ func TestSuccessfulRepositorySizeRequest(t *testing.T) {
request := &gitalypb.RepositorySizeRequest{Repository: repo}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
response, err := client.RepositorySize(ctx, request)
require.NoError(t, err)
@@ -58,7 +57,7 @@ func TestFailedRepositorySizeRequest(t *testing.T) {
Repository: testCase.repo,
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
_, err := client.RepositorySize(ctx, request)
testhelper.RequireGrpcError(t, err, codes.InvalidArgument)
@@ -80,7 +79,7 @@ func TestSuccessfulGetObjectDirectorySizeRequest(t *testing.T) {
Repository: testRepo,
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
response, err := client.GetObjectDirectorySize(ctx, request)
diff --git a/internal/service/smarthttp/inforefs_test.go b/internal/service/smarthttp/inforefs_test.go
index c13e6fb02..e87b007e6 100644
--- a/internal/service/smarthttp/inforefs_test.go
+++ b/internal/service/smarthttp/inforefs_test.go
@@ -34,7 +34,10 @@ func TestSuccessfulInfoRefsUploadPack(t *testing.T) {
rpcRequest := &gitalypb.InfoRefsRequest{Repository: testRepo}
- response, err := makeInfoRefsUploadPackRequest(context.Background(), t, serverSocketPath, rpcRequest)
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
+ response, err := makeInfoRefsUploadPackRequest(ctx, t, serverSocketPath, rpcRequest)
require.NoError(t, err)
assertGitRefAdvertisement(t, "InfoRefsUploadPack", string(response), "001e# service=git-upload-pack", "0000", []string{
"003ef4e6814c3e4e7a0de82a9e7cd20c626cc963a2f8 refs/tags/v1.0.0",
@@ -80,7 +83,10 @@ func TestSuccessfulInfoRefsUploadPackWithGitConfigOptions(t *testing.T) {
GitConfigOptions: []string{"transfer.hideRefs=refs"},
}
- response, err := makeInfoRefsUploadPackRequest(context.Background(), t, serverSocketPath, rpcRequest)
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
+ response, err := makeInfoRefsUploadPackRequest(ctx, t, serverSocketPath, rpcRequest)
require.NoError(t, err)
assertGitRefAdvertisement(t, "InfoRefsUploadPack", string(response), "001e# service=git-upload-pack", "0000", []string{})
}
@@ -101,7 +107,7 @@ func TestSuccessfulInfoRefsUploadPackWithGitProtocol(t *testing.T) {
}
client, _ := newSmartHTTPClient(t, serverSocketPath)
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.InfoRefsUploadPack(ctx, rpcRequest)
@@ -151,7 +157,7 @@ func TestSuccessfulInfoRefsReceivePack(t *testing.T) {
rpcRequest := &gitalypb.InfoRefsRequest{Repository: testRepo}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.InfoRefsReceivePack(ctx, rpcRequest)
if err != nil {
@@ -218,7 +224,7 @@ func TestFailureRepoNotFoundInfoRefsReceivePack(t *testing.T) {
repo := &gitalypb.Repository{StorageName: "default", RelativePath: "testdata/scratch/another_repo"}
rpcRequest := &gitalypb.InfoRefsRequest{Repository: repo}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.InfoRefsReceivePack(ctx, rpcRequest)
if err != nil {
@@ -239,7 +245,7 @@ func TestFailureRepoNotSetInfoRefsReceivePack(t *testing.T) {
defer conn.Close()
rpcRequest := &gitalypb.InfoRefsRequest{}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
c, err := client.InfoRefsReceivePack(ctx, rpcRequest)
if err != nil {
@@ -282,7 +288,8 @@ func TestCacheInfoRefsUploadPack(t *testing.T) {
rpcRequest := &gitalypb.InfoRefsRequest{Repository: testRepo}
- ctx := context.Background()
+ ctx, cancel := testhelper.Context()
+ defer cancel()
assertNormalResponse := func() {
response, err := makeInfoRefsUploadPackRequest(ctx, t, serverSocketPath, rpcRequest)
@@ -318,7 +325,7 @@ func TestCacheInfoRefsUploadPack(t *testing.T) {
// invalidate cache for repository
ender, err := cache.LeaseKeyer{}.StartLease(rpcRequest.Repository)
require.NoError(t, err)
- require.NoError(t, ender.EndLease(setInfoRefsUploadPackMethod(context.Background())))
+ require.NoError(t, ender.EndLease(setInfoRefsUploadPackMethod(ctx)))
// replaced cache response is no longer valid
assertNormalResponse()
diff --git a/internal/service/smarthttp/receive_pack_test.go b/internal/service/smarthttp/receive_pack_test.go
index 4e8b3de7d..b6a306957 100644
--- a/internal/service/smarthttp/receive_pack_test.go
+++ b/internal/service/smarthttp/receive_pack_test.go
@@ -124,7 +124,7 @@ func TestFailedReceivePackRequestWithGitOpts(t *testing.T) {
client, conn := newSmartHTTPClient(t, serverSocketPath)
defer conn.Close()
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
stream, err := client.PostReceivePack(ctx)
@@ -274,7 +274,7 @@ func TestFailedReceivePackRequestDueToValidationError(t *testing.T) {
for _, rpcRequest := range rpcRequests {
t.Run(fmt.Sprintf("%v", rpcRequest), func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
stream, err := client.PostReceivePack(ctx)
require.NoError(t, err)
@@ -358,12 +358,14 @@ func TestPostReceivePackToHooks(t *testing.T) {
features, err := testhelper.NewFeatureSets([]featureflag.FeatureFlag{featureflag.GoPostReceiveHook})
require.NoError(t, err)
- ctx, cancel := testhelper.Context()
- defer cancel()
-
for _, feature := range features {
- t.Run(feature.String(), func(t *testing.T) {
- testPostReceivePackToHooks(t, feature.WithParent(ctx))
+ t.Run("disabled "+feature.String(), func(t *testing.T) {
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
+ ctx = feature.Disable(ctx)
+
+ testPostReceivePackToHooks(t, ctx)
})
}
}
@@ -483,7 +485,7 @@ func TestPostReceiveWithTransactionsViaPraefect(t *testing.T) {
require.NoError(t, err)
for _, features := range featureSets {
- t.Run(fmt.Sprintf("features:%s", features), func(t *testing.T) {
+ t.Run("disabled "+features.String(), func(t *testing.T) {
repo, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
@@ -539,7 +541,7 @@ func TestPostReceiveWithTransactionsViaPraefect(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- ctx = features.WithParent(ctx)
+ ctx = features.Disable(ctx)
stream, err := client.PostReceivePack(ctx)
require.NoError(t, err)
@@ -605,7 +607,7 @@ func TestPostReceiveWithReferenceTransactionHook(t *testing.T) {
require.NoError(t, err)
for _, features := range featureSets {
- t.Run(fmt.Sprintf("features:%s", features), func(t *testing.T) {
+ t.Run("disabled "+features.String(), func(t *testing.T) {
refTransactionServer.called = 0
client, conn := newSmartHTTPClient(t, "unix://"+gitalySocketPath)
@@ -627,7 +629,7 @@ func TestPostReceiveWithReferenceTransactionHook(t *testing.T) {
require.NoError(t, err)
ctx = helper.IncomingToOutgoing(ctx)
- ctx = features.WithParent(ctx)
+ ctx = features.Disable(ctx)
stream, err := client.PostReceivePack(ctx)
require.NoError(t, err)
@@ -648,7 +650,7 @@ func TestPostReceiveWithReferenceTransactionHook(t *testing.T) {
// If the reference-transaction hook is not supported or the feature flag is
// not enabled, voting only happens via the pre-receive hook.
- if !features.IsEnabled(featureflag.ReferenceTransactionHook) || !supported {
+ if features.IsDisabled(featureflag.ReferenceTransactionHook) || !supported {
require.Equal(t, 1, refTransactionServer.called)
} else {
require.Equal(t, 3, refTransactionServer.called)
diff --git a/internal/service/ssh/receive_pack_test.go b/internal/service/ssh/receive_pack_test.go
index d83d15571..059ed950b 100644
--- a/internal/service/ssh/receive_pack_test.go
+++ b/internal/service/ssh/receive_pack_test.go
@@ -2,7 +2,6 @@ package ssh
import (
"bytes"
- "context"
"fmt"
"io"
"io/ioutil"
@@ -62,7 +61,7 @@ func TestFailedReceivePackRequestDueToValidationError(t *testing.T) {
for _, test := range tests {
t.Run(test.Desc, func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
stream, err := client.SSHReceivePack(ctx)
diff --git a/internal/service/ssh/upload_archive_test.go b/internal/service/ssh/upload_archive_test.go
index 160e6ee87..334e11864 100644
--- a/internal/service/ssh/upload_archive_test.go
+++ b/internal/service/ssh/upload_archive_test.go
@@ -1,7 +1,6 @@
package ssh
import (
- "context"
"fmt"
"os"
"os/exec"
@@ -80,7 +79,7 @@ func TestFailedUploadArchiveRequestDueToValidationError(t *testing.T) {
for _, test := range tests {
t.Run(test.Desc, func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
stream, err := client.SSHUploadArchive(ctx)
if err != nil {
diff --git a/internal/service/ssh/upload_pack_test.go b/internal/service/ssh/upload_pack_test.go
index 40d6cc579..351364418 100644
--- a/internal/service/ssh/upload_pack_test.go
+++ b/internal/service/ssh/upload_pack_test.go
@@ -1,7 +1,6 @@
package ssh
import (
- "context"
"fmt"
"io"
"os"
@@ -172,7 +171,7 @@ func TestFailedUploadPackRequestDueToValidationError(t *testing.T) {
for _, test := range tests {
t.Run(test.Desc, func(t *testing.T) {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := testhelper.Context()
defer cancel()
stream, err := client.SSHUploadPack(ctx)
if err != nil {
diff --git a/internal/supervisor/supervisor_test.go b/internal/supervisor/supervisor_test.go
index eb59a4c72..40ebaf27e 100644
--- a/internal/supervisor/supervisor_test.go
+++ b/internal/supervisor/supervisor_test.go
@@ -125,7 +125,7 @@ func TestSpawnFailure(t *testing.T) {
}
func tryConnect(socketPath string, attempts int, timeout time.Duration) (pids []int, err error) {
- ctx, cancel := context.WithTimeout(context.Background(), timeout)
+ ctx, cancel := testhelper.Context(testhelper.ContextWithTimeout(timeout))
defer cancel()
for j := 0; j < attempts; j++ {
diff --git a/internal/testhelper/grpc_test.go b/internal/testhelper/grpc_test.go
index 792d7d11a..6b1272c3f 100644
--- a/internal/testhelper/grpc_test.go
+++ b/internal/testhelper/grpc_test.go
@@ -1,7 +1,6 @@
package testhelper_test
import (
- "context"
"testing"
"github.com/stretchr/testify/require"
@@ -11,7 +10,11 @@ import (
func TestSetCtxGrpcMethod(t *testing.T) {
expectFullMethodName := "/pinkypb/TakeOverTheWorld.SNARF"
- ctx := testhelper.SetCtxGrpcMethod(context.Background(), expectFullMethodName)
+
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
+ ctx = testhelper.SetCtxGrpcMethod(ctx, expectFullMethodName)
actualFullMethodName, ok := grpc.Method(ctx)
require.True(t, ok, "expected context to contain server transport stream")
diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go
index 72d803176..ee1562b01 100644
--- a/internal/testhelper/testhelper.go
+++ b/internal/testhelper/testhelper.go
@@ -21,6 +21,7 @@ import (
"path"
"path/filepath"
"runtime"
+ "sort"
"strconv"
"strings"
"sync"
@@ -146,6 +147,26 @@ func GitalyServersMetadata(t testing.TB, serverSocketPath string) metadata.MD {
return metadata.Pairs("gitaly-servers", base64.StdEncoding.EncodeToString(gitalyServersJSON))
}
+// MergeOutgoingMetadata merges provided metadata-s and returns context with resulting value.
+func MergeOutgoingMetadata(ctx context.Context, md ...metadata.MD) context.Context {
+ ctxmd, ok := metadata.FromOutgoingContext(ctx)
+ if !ok {
+ return metadata.NewOutgoingContext(ctx, metadata.Join(md...))
+ }
+
+ return metadata.NewOutgoingContext(ctx, metadata.Join(append(md, ctxmd)...))
+}
+
+// MergeIncomingMetadata merges provided metadata-s and returns context with resulting value.
+func MergeIncomingMetadata(ctx context.Context, md ...metadata.MD) context.Context {
+ ctxmd, ok := metadata.FromIncomingContext(ctx)
+ if !ok {
+ return metadata.NewIncomingContext(ctx, metadata.Join(md...))
+ }
+
+ return metadata.NewIncomingContext(ctx, metadata.Join(append(md, ctxmd)...))
+}
+
// isValidRepoPath checks whether a valid git repository exists at the given path.
func isValidRepoPath(absolutePath string) bool {
if _, err := os.Stat(filepath.Join(absolutePath, "objects")); err != nil {
@@ -438,9 +459,36 @@ func mustFindNoRunningChildProcess() {
panic(fmt.Errorf("%s: %v", desc, err))
}
+// ContextOpt returns a new context instance with the new additions to it.
+type ContextOpt func(context.Context) (context.Context, func())
+
+// ContextWithTimeout allows to set provided timeout to the context.
+func ContextWithTimeout(duration time.Duration) ContextOpt {
+ return func(ctx context.Context) (context.Context, func()) {
+ return context.WithTimeout(ctx, duration)
+ }
+}
+
// Context returns a cancellable context.
-func Context() (context.Context, func()) {
- return context.WithCancel(context.Background())
+func Context(opts ...ContextOpt) (context.Context, func()) {
+ ctx, cancel := context.WithCancel(context.Background())
+ for _, ff := range featureflag.All {
+ ctx = featureflag.IncomingCtxWithFeatureFlag(ctx, ff)
+ ctx = featureflag.OutgoingCtxWithFeatureFlags(ctx, ff)
+ }
+
+ cancels := make([]func(), len(opts)+1)
+ cancels[0] = cancel
+ for i, opt := range opts {
+ ctx, cancel = opt(ctx)
+ cancels[i+1] = cancel
+ }
+
+ return ctx, func() {
+ for i := len(cancels) - 1; i >= 0; i-- {
+ cancels[i]()
+ }
+ }
}
// CreateRepo creates a temporary directory for a repo, without initializing it
@@ -733,48 +781,41 @@ func WriteBlobs(t testing.TB, testRepoPath string, n int) []string {
return blobIDs
}
-// FeatureSet is a representation of a set of features that are enabled
-// This is useful in situations where a test needs to test any combination of features toggled on and off
+// FeatureSet is a representation of a set of features that should be disabled.
+// This is useful in situations where a test needs to test any combination of features toggled on and off.
+// It is designed to disable features as all features are enabled by default, please see: testhelper.Context()
type FeatureSet struct {
- features map[featureflag.FeatureFlag]bool
- rubyFeatures map[featureflag.FeatureFlag]bool
+ features map[featureflag.FeatureFlag]struct{}
+ rubyFeatures map[featureflag.FeatureFlag]struct{}
}
-func (f FeatureSet) IsEnabled(flag featureflag.FeatureFlag) bool {
- on, ok := f.features[flag]
- if !ok {
- return flag.OnByDefault
- }
-
- return on
+func (f FeatureSet) IsDisabled(flag featureflag.FeatureFlag) bool {
+ _, ok := f.features[flag]
+ return ok
}
func (f FeatureSet) String() string {
- features := make([]string, 0, len(f.enabledFeatures()))
- for _, feature := range f.enabledFeatures() {
+ features := make([]string, 0, len(f.features))
+ for feature := range f.features {
features = append(features, feature.Name)
}
- return strings.Join(features, ",")
-}
-
-func (f FeatureSet) enabledFeatures() []featureflag.FeatureFlag {
- var enabled []featureflag.FeatureFlag
-
- for feature := range f.features {
- enabled = append(enabled, feature)
+ if len(features) == 0 {
+ return "none"
}
- return enabled
+ sort.Strings(features)
+
+ return strings.Join(features, ",")
}
-func (f FeatureSet) WithParent(ctx context.Context) context.Context {
- for _, enabledFeature := range f.enabledFeatures() {
- if _, ok := f.rubyFeatures[enabledFeature]; ok {
- ctx = featureflag.OutgoingCtxWithRubyFeatureFlags(ctx, enabledFeature)
+func (f FeatureSet) Disable(ctx context.Context) context.Context {
+ for feature := range f.features {
+ if _, ok := f.rubyFeatures[feature]; ok {
+ ctx = featureflag.OutgoingCtxWithRubyFeatureFlagValue(ctx, feature, "false")
continue
}
- ctx = featureflag.OutgoingCtxWithFeatureFlags(ctx, enabledFeature)
+ ctx = featureflag.OutgoingCtxWithFeatureFlagValue(ctx, feature, "false")
}
return ctx
@@ -786,20 +827,20 @@ type FeatureSets []FeatureSet
// NewFeatureSets takes a slice of go feature flags, and an optional variadic set of ruby feature flags
// and returns a FeatureSets slice
func NewFeatureSets(goFeatures []featureflag.FeatureFlag, rubyFeatures ...featureflag.FeatureFlag) (FeatureSets, error) {
- rubyFeatureMap := make(map[featureflag.FeatureFlag]bool)
+ rubyFeatureMap := make(map[featureflag.FeatureFlag]struct{})
for _, rubyFeature := range rubyFeatures {
- rubyFeatureMap[rubyFeature] = true
+ rubyFeatureMap[rubyFeature] = struct{}{}
}
// start with an empty feature set
- f := []FeatureSet{{features: make(map[featureflag.FeatureFlag]bool), rubyFeatures: rubyFeatureMap}}
+ f := []FeatureSet{{features: make(map[featureflag.FeatureFlag]struct{}), rubyFeatures: rubyFeatureMap}}
allFeatures := append(goFeatures, rubyFeatures...)
for i := range allFeatures {
- featureMap := make(map[featureflag.FeatureFlag]bool)
+ featureMap := make(map[featureflag.FeatureFlag]struct{})
for j := 0; j <= i; j++ {
- featureMap[allFeatures[j]] = true
+ featureMap[allFeatures[j]] = struct{}{}
}
f = append(f, FeatureSet{features: featureMap, rubyFeatures: rubyFeatureMap})
diff --git a/internal/testhelper/testserver.go b/internal/testhelper/testserver.go
index b2218c492..2a14a8ee1 100644
--- a/internal/testhelper/testserver.go
+++ b/internal/testhelper/testserver.go
@@ -41,12 +41,6 @@ import (
"gopkg.in/yaml.v2"
)
-// PraefectEnabled returns whether or not tests should use a praefect proxy
-func PraefectEnabled() bool {
- _, ok := os.LookupEnv("GITALY_TEST_PRAEFECT_BIN")
- return ok
-}
-
// TestServerOpt is an option for TestServer
type TestServerOpt func(t *TestServer)
@@ -75,15 +69,19 @@ func NewTestServer(srv *grpc.Server, opts ...TestServerOpt) *TestServer {
opt(ts)
}
+ // the health service needs to be registered in order to support health checks on all
+ // gitaly services that are under test.
+ // The health check is executed by the praefect in case 'test-with-praefect' verification
+ // job is running.
+ healthpb.RegisterHealthServer(srv, health.NewServer())
+
return ts
}
// NewServerWithAuth creates a new test server with authentication
func NewServerWithAuth(tb testing.TB, streamInterceptors []grpc.StreamServerInterceptor, unaryInterceptors []grpc.UnaryServerInterceptor, token string, opts ...TestServerOpt) *TestServer {
if token != "" {
- if PraefectEnabled() {
- opts = append(opts, WithToken(token))
- }
+ opts = append(opts, WithToken(token))
streamInterceptors = append(streamInterceptors, serverauth.StreamServerInterceptor(auth.Config{Token: token}))
unaryInterceptors = append(unaryInterceptors, serverauth.UnaryServerInterceptor(auth.Config{Token: token}))
}
@@ -160,6 +158,11 @@ func (p *TestServer) Start() error {
Token: p.token,
},
MemoryQueueEnabled: true,
+ Failover: praefectconfig.Failover{
+ Enabled: true,
+ BootstrapInterval: config.Duration(time.Microsecond),
+ MonitorInterval: config.Duration(time.Second),
+ },
}
for _, storage := range p.storages {
@@ -212,11 +215,11 @@ func (p *TestServer) Start() error {
conn, err := grpc.Dial("unix://"+praefectServerSocketPath, opts...)
if err != nil {
- return fmt.Errorf("dial: %v", err)
+ return fmt.Errorf("dial to praefect: %v", err)
}
defer conn.Close()
- if err = waitForPraefectStartup(conn); err != nil {
+ if err = WaitHealthy(conn, 3, time.Second); err != nil {
return err
}
@@ -234,25 +237,58 @@ func (p *TestServer) listen() (string, error) {
}
go p.grpcServer.Serve(listener)
+
+ opts := []grpc.DialOption{grpc.WithInsecure()}
+ if p.token != "" {
+ opts = append(opts, grpc.WithPerRPCCredentials(gitalyauth.RPCCredentialsV2(p.token)))
+ }
+
+ conn, err := grpc.Dial("unix://"+gitalyServerSocketPath, opts...)
+
+ if err != nil {
+ return "", err
+ }
+ defer conn.Close()
+
+ if err := WaitHealthy(conn, 3, time.Second); err != nil {
+ return "", err
+ }
+
return gitalyServerSocketPath, nil
}
-func waitForPraefectStartup(conn *grpc.ClientConn) error {
- client := healthpb.NewHealthClient(conn)
+// WaitHealthy executes health check request `retries` times and awaits each `timeout` period to respond.
+// After `retries` unsuccessful attempts it returns an error.
+// Returns immediately without an error once get a successful health check response.
+func WaitHealthy(conn *grpc.ClientConn, retries int, timeout time.Duration) error {
+ for i := 0; i < retries; i++ {
+ if IsHealthy(conn, timeout) {
+ return nil
+ }
+ }
+
+ return errors.New("server not yet ready to serve")
+}
- ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
+// IsHealthy creates a health client to passed in connection and send `Check` request.
+// It waits for `timeout` duration to get response back.
+// It returns `true` only if remote responds with `SERVING` status.
+func IsHealthy(conn *grpc.ClientConn, timeout time.Duration) bool {
+ healthClient := healthpb.NewHealthClient(conn)
+
+ ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
- resp, err := client.Check(ctx, &healthpb.HealthCheckRequest{}, grpc.WaitForReady(true))
+ resp, err := healthClient.Check(ctx, &healthpb.HealthCheckRequest{}, grpc.WaitForReady(true))
if err != nil {
- return err
+ return false
}
if resp.Status != healthpb.HealthCheckResponse_SERVING {
- return errors.New("server not yet ready to serve")
+ return false
}
- return nil
+ return true
}
// NewServer creates a Server for testing purposes