From ae1d4797f13c31a7b71601def595c22b7df5f8fe Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Mon, 6 May 2019 18:02:32 +0200 Subject: [PATCH 1/4] Use cat-file caching in tests by default --- internal/testhelper/testhelper.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go index 5b139227f4c..ba91df83338 100644 --- a/internal/testhelper/testhelper.go +++ b/internal/testhelper/testhelper.go @@ -28,9 +28,11 @@ import ( "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/config" + "gitlab.com/gitlab-org/gitaly/internal/git/catfile" "gitlab.com/gitlab-org/gitaly/internal/helper/fieldextractors" "gitlab.com/gitlab-org/gitaly/internal/helper/text" gitalylog "gitlab.com/gitlab-org/gitaly/internal/log" + "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/internal/storage" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -302,6 +304,7 @@ func NewTestGrpcServer(tb testing.TB, streamInterceptors []grpc.StreamServerInte func MustHaveNoChildProcess() { waitDone := make(chan struct{}) go func() { + catfile.ExpireAll() command.WaitAllDone() close(waitDone) }() @@ -348,7 +351,15 @@ func mustFindNoRunningChildProcess() { // Context returns a cancellable context. func Context() (context.Context, func()) { - return context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(context.Background()) + + md := metadata.New(map[string]string{ + featureflag.HeaderKey(catfile.CacheFeatureFlagKey): "true", + "gitaly-session-id": "gitaly-test", + }) + ctx = metadata.NewOutgoingContext(ctx, md) + + return ctx, cancel } // CreateRepo creates an temporary directory for a repo, without initializing it -- GitLab From bce215f0b3c006dd4e717ba66fca872d7635a7c8 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Mon, 6 May 2019 18:34:47 +0200 Subject: [PATCH 2/4] Fix import cycle --- internal/command/command.go | 12 +++- internal/command/commandtest/check.go | 63 +++++++++++++++++++ internal/git/catfile/batch_cache.go | 18 +++--- internal/git/catfile/catfile.go | 8 +-- internal/git/catfile/testhelper_test.go | 4 +- internal/metadata/featureflag/flags.go | 7 +++ internal/rubyserver/testhelper_test.go | 3 +- internal/service/blob/testhelper_test.go | 3 +- internal/service/commit/find_commit_test.go | 4 +- internal/service/commit/testhelper_test.go | 3 +- internal/service/conflicts/testhelper_test.go | 3 +- internal/service/diff/testhelper_test.go | 3 +- .../service/objectpool/testhelper_test.go | 3 +- .../service/operations/testhelper_test.go | 3 +- internal/service/ref/testhelper_test.go | 3 +- internal/service/remote/testhelper_test.go | 3 +- .../service/repository/testhelper_test.go | 3 +- internal/service/ssh/testhelper_test.go | 3 +- internal/service/wiki/testhelper_test.go | 3 +- internal/supervisor/supervisor_test.go | 4 +- internal/tempdir/testhelper_test.go | 4 +- internal/testhelper/testhelper.go | 57 +---------------- 22 files changed, 126 insertions(+), 91 deletions(-) create mode 100644 internal/command/commandtest/check.go create mode 100644 internal/metadata/featureflag/flags.go diff --git a/internal/command/command.go b/internal/command/command.go index 5f72fec602a..4e837132291 100644 --- a/internal/command/command.go +++ b/internal/command/command.go @@ -134,12 +134,22 @@ func GitPath() string { return config.Config.Git.BinPath } -var wg = &sync.WaitGroup{} +var ( + wg = &sync.WaitGroup{} + cleanupFunctions []func() +) + +// RegisterCleanup registers callbacks that will be run during WaitAllDone. +func RegisterCleanup(fn func()) { cleanupFunctions = append(cleanupFunctions, fn) } // WaitAllDone waits for all commands started by the command package to // finish. This can only be called once in the lifecycle of the current // Go process. func WaitAllDone() { + for _, fn := range cleanupFunctions { + fn() + } + wg.Wait() } diff --git a/internal/command/commandtest/check.go b/internal/command/commandtest/check.go new file mode 100644 index 00000000000..54f683e405b --- /dev/null +++ b/internal/command/commandtest/check.go @@ -0,0 +1,63 @@ +package commandtest + +import ( + "fmt" + "os" + "os/exec" + "strings" + "syscall" + "time" + + "gitlab.com/gitlab-org/gitaly/internal/command" + "gitlab.com/gitlab-org/gitaly/internal/helper/text" +) + +// MustHaveNoChildProcess panics if it finds a running or finished child +// process. It waits for 2 seconds for processes to be cleaned up by other +// goroutines. +func MustHaveNoChildProcess() { + waitDone := make(chan struct{}) + go func() { + command.WaitAllDone() + close(waitDone) + }() + + select { + case <-waitDone: + case <-time.After(2 * time.Second): + } + + mustFindNoFinishedChildProcess() + mustFindNoRunningChildProcess() +} + +func mustFindNoFinishedChildProcess() { + // Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error) + // + // We use pid -1 to wait for any child. We don't care about wstatus or + // rusage. Use WNOHANG to return immediately if there is no child waiting + // to be reaped. + wpid, err := syscall.Wait4(-1, nil, syscall.WNOHANG, nil) + if err == nil && wpid > 0 { + panic(fmt.Errorf("wait4 found child process %d", wpid)) + } +} + +func mustFindNoRunningChildProcess() { + pgrep := exec.Command("pgrep", "-P", fmt.Sprintf("%d", os.Getpid())) + desc := fmt.Sprintf("%q", strings.Join(pgrep.Args, " ")) + + out, err := pgrep.Output() + if err == nil { + pidsComma := strings.Replace(text.ChompBytes(out), "\n", ",", -1) + psOut, _ := exec.Command("ps", "-o", "pid,args", "-p", pidsComma).Output() + panic(fmt.Errorf("found running child processes %s:\n%s", pidsComma, psOut)) + } + + if status, ok := command.ExitStatus(err); ok && status == 1 { + // Exit status 1 means no processes were found + return + } + + panic(fmt.Errorf("%s: %v", desc, err)) +} diff --git a/internal/git/catfile/batch_cache.go b/internal/git/catfile/batch_cache.go index 10ea489a1d9..1ae63435557 100644 --- a/internal/git/catfile/batch_cache.go +++ b/internal/git/catfile/batch_cache.go @@ -6,6 +6,7 @@ import ( "time" "github.com/prometheus/client_golang/prometheus" + "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/git/repository" ) @@ -19,18 +20,21 @@ const ( defaultEvictionInterval = 1 * time.Second ) -var catfileCacheMembers = prometheus.NewGauge( - prometheus.GaugeOpts{ - Name: "gitaly_catfile_cache_members", - Help: "Gauge of catfile cache members", - }, -) +var ( + catfileCacheMembers = prometheus.NewGauge( + prometheus.GaugeOpts{ + Name: "gitaly_catfile_cache_members", + Help: "Gauge of catfile cache members", + }, + ) -var cache *batchCache + cache *batchCache +) func init() { prometheus.MustRegister(catfileCacheMembers) cache = newCache(DefaultBatchfileTTL, CacheMaxItems) + command.RegisterCleanup(cache.EvictAll) } func newCacheKey(sessionID string, repo repository.GitRepo) key { diff --git a/internal/git/catfile/catfile.go b/internal/git/catfile/catfile.go index 288470170e3..e64d6423077 100644 --- a/internal/git/catfile/catfile.go +++ b/internal/git/catfile/catfile.go @@ -34,12 +34,6 @@ var totalCatfileProcesses = prometheus.NewCounter( }, ) -const ( - // CacheFeatureFlagKey is the feature flag key for catfile batch caching. This should match - // what is in gitlab-ce - CacheFeatureFlagKey = "catfile-cache" -) - func init() { prometheus.MustRegister(catfileCacheCounter) prometheus.MustRegister(currentCatfileProcesses) @@ -135,7 +129,7 @@ func New(ctx context.Context, repo *gitalypb.Repository) (*Batch, error) { sessionID := metadata.GetValue(ctx, "gitaly-session-id") - if featureflag.IsDisabled(ctx, CacheFeatureFlagKey) || sessionID == "" { + if featureflag.IsDisabled(ctx, featureflag.CatfileCacheKey) || sessionID == "" { return newBatch(ctx, repoPath, env) } diff --git a/internal/git/catfile/testhelper_test.go b/internal/git/catfile/testhelper_test.go index 715d770f784..30c16993799 100644 --- a/internal/git/catfile/testhelper_test.go +++ b/internal/git/catfile/testhelper_test.go @@ -4,7 +4,7 @@ import ( "os" "testing" - "gitlab.com/gitlab-org/gitaly/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" ) func TestMain(m *testing.M) { @@ -12,7 +12,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - defer testhelper.MustHaveNoChildProcess() + defer commandtest.MustHaveNoChildProcess() return m.Run() } diff --git a/internal/metadata/featureflag/flags.go b/internal/metadata/featureflag/flags.go new file mode 100644 index 00000000000..3611acff261 --- /dev/null +++ b/internal/metadata/featureflag/flags.go @@ -0,0 +1,7 @@ +package featureflag + +const ( + // CatfileCacheKey is the feature flag key for catfile batch caching. This should match + // what is in gitlab-ce + CatfileCacheKey = "catfile-cache" +) diff --git a/internal/rubyserver/testhelper_test.go b/internal/rubyserver/testhelper_test.go index cc83a7923ca..f4dda89ac51 100644 --- a/internal/rubyserver/testhelper_test.go +++ b/internal/rubyserver/testhelper_test.go @@ -4,6 +4,7 @@ import ( "os" "testing" + "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/testhelper" ) @@ -16,7 +17,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - defer testhelper.MustHaveNoChildProcess() + defer commandtest.MustHaveNoChildProcess() return m.Run() } diff --git a/internal/service/blob/testhelper_test.go b/internal/service/blob/testhelper_test.go index 95cc08caf54..8478b41561b 100644 --- a/internal/service/blob/testhelper_test.go +++ b/internal/service/blob/testhelper_test.go @@ -7,6 +7,7 @@ import ( "testing" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" + "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "google.golang.org/grpc" @@ -20,7 +21,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - defer testhelper.MustHaveNoChildProcess() + defer commandtest.MustHaveNoChildProcess() var err error testhelper.ConfigureRuby() diff --git a/internal/service/commit/find_commit_test.go b/internal/service/commit/find_commit_test.go index ab64427c70f..c7a6837d430 100644 --- a/internal/service/commit/find_commit_test.go +++ b/internal/service/commit/find_commit_test.go @@ -332,7 +332,7 @@ func benchmarkFindCommit(withCache bool, b *testing.B) { revision := revisions[b.N%len(revisions)] if withCache { md := metadata.New(map[string]string{ - featureflag.HeaderKey(catfile.CacheFeatureFlagKey): "true", + featureflag.HeaderKey(featureflag.CatfileCacheKey): "true", "gitaly-session-id": "abc123", }) @@ -378,7 +378,7 @@ func TestFindCommitWithCache(t *testing.T) { for i := 0; i < 10; i++ { revision := revisions[i%len(revisions)] md := metadata.New(map[string]string{ - featureflag.HeaderKey(catfile.CacheFeatureFlagKey): "true", + featureflag.HeaderKey(featureflag.CatfileCacheKey): "true", "gitaly-session-id": "abc123", }) diff --git a/internal/service/commit/testhelper_test.go b/internal/service/commit/testhelper_test.go index 861b2e89ced..8153bdc883b 100644 --- a/internal/service/commit/testhelper_test.go +++ b/internal/service/commit/testhelper_test.go @@ -8,6 +8,7 @@ import ( "github.com/golang/protobuf/ptypes/timestamp" log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" + "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/linguist" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/testhelper" @@ -24,7 +25,7 @@ func TestMain(m *testing.M) { var rubyServer *rubyserver.Server func testMain(m *testing.M) int { - defer testhelper.MustHaveNoChildProcess() + defer commandtest.MustHaveNoChildProcess() testhelper.ConfigureRuby() if err := linguist.LoadColors(); err != nil { diff --git a/internal/service/conflicts/testhelper_test.go b/internal/service/conflicts/testhelper_test.go index 482fc0631e3..94935001314 100644 --- a/internal/service/conflicts/testhelper_test.go +++ b/internal/service/conflicts/testhelper_test.go @@ -7,6 +7,7 @@ import ( log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" + "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/git/hooks" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/testhelper" @@ -21,7 +22,7 @@ func TestMain(m *testing.M) { var RubyServer *rubyserver.Server func testMain(m *testing.M) int { - defer testhelper.MustHaveNoChildProcess() + defer commandtest.MustHaveNoChildProcess() var err error diff --git a/internal/service/diff/testhelper_test.go b/internal/service/diff/testhelper_test.go index bd5d792642e..e98b5ce7b12 100644 --- a/internal/service/diff/testhelper_test.go +++ b/internal/service/diff/testhelper_test.go @@ -7,6 +7,7 @@ import ( log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" + "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "google.golang.org/grpc" @@ -20,7 +21,7 @@ func TestMain(m *testing.M) { var rubyServer *rubyserver.Server func testMain(m *testing.M) int { - defer testhelper.MustHaveNoChildProcess() + defer commandtest.MustHaveNoChildProcess() var err error diff --git a/internal/service/objectpool/testhelper_test.go b/internal/service/objectpool/testhelper_test.go index 943fd1942ac..b2bcfbcc0aa 100644 --- a/internal/service/objectpool/testhelper_test.go +++ b/internal/service/objectpool/testhelper_test.go @@ -7,6 +7,7 @@ import ( "time" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" + "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "google.golang.org/grpc" "google.golang.org/grpc/reflection" @@ -17,7 +18,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - defer testhelper.MustHaveNoChildProcess() + defer commandtest.MustHaveNoChildProcess() return m.Run() } diff --git a/internal/service/operations/testhelper_test.go b/internal/service/operations/testhelper_test.go index 5649ed514d5..cd08dfdecb0 100644 --- a/internal/service/operations/testhelper_test.go +++ b/internal/service/operations/testhelper_test.go @@ -11,6 +11,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" + "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/git/hooks" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/testhelper" @@ -42,7 +43,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - defer testhelper.MustHaveNoChildProcess() + defer commandtest.MustHaveNoChildProcess() hookDir, err := ioutil.TempDir("", "gitaly-tmp-hooks") if err != nil { diff --git a/internal/service/ref/testhelper_test.go b/internal/service/ref/testhelper_test.go index 3d7da42bbcb..c6abfa93ad2 100644 --- a/internal/service/ref/testhelper_test.go +++ b/internal/service/ref/testhelper_test.go @@ -10,6 +10,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" + "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/helper/lines" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/testhelper" @@ -80,7 +81,7 @@ func TestMain(m *testing.M) { var rubyServer *rubyserver.Server func testMain(m *testing.M) int { - defer testhelper.MustHaveNoChildProcess() + defer commandtest.MustHaveNoChildProcess() var err error diff --git a/internal/service/remote/testhelper_test.go b/internal/service/remote/testhelper_test.go index 3f37b1c602a..6e30336ab8c 100644 --- a/internal/service/remote/testhelper_test.go +++ b/internal/service/remote/testhelper_test.go @@ -7,6 +7,7 @@ import ( "testing" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" + "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "google.golang.org/grpc" @@ -20,7 +21,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - defer testhelper.MustHaveNoChildProcess() + defer commandtest.MustHaveNoChildProcess() var err error diff --git a/internal/service/repository/testhelper_test.go b/internal/service/repository/testhelper_test.go index e2a8c1f95ac..304d2a8eaec 100644 --- a/internal/service/repository/testhelper_test.go +++ b/internal/service/repository/testhelper_test.go @@ -11,6 +11,7 @@ import ( "github.com/stretchr/testify/assert" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" gitalyauth "gitlab.com/gitlab-org/gitaly/auth" + "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/server/auth" @@ -82,7 +83,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - defer testhelper.MustHaveNoChildProcess() + defer commandtest.MustHaveNoChildProcess() testhelper.ConfigureRuby() config.Config.Auth = config.Auth{Token: testhelper.RepositoryAuthToken} diff --git a/internal/service/ssh/testhelper_test.go b/internal/service/ssh/testhelper_test.go index 1945bf42837..40c8b47bb4d 100644 --- a/internal/service/ssh/testhelper_test.go +++ b/internal/service/ssh/testhelper_test.go @@ -8,6 +8,7 @@ import ( log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" + "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "google.golang.org/grpc" "google.golang.org/grpc/reflection" @@ -29,7 +30,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - defer testhelper.MustHaveNoChildProcess() + defer commandtest.MustHaveNoChildProcess() cwd = mustGetCwd() diff --git a/internal/service/wiki/testhelper_test.go b/internal/service/wiki/testhelper_test.go index e909db22400..2400cb4b993 100644 --- a/internal/service/wiki/testhelper_test.go +++ b/internal/service/wiki/testhelper_test.go @@ -11,6 +11,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" + "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/git/hooks" gitlog "gitlab.com/gitlab-org/gitaly/internal/git/log" "gitlab.com/gitlab-org/gitaly/internal/helper" @@ -38,7 +39,7 @@ func TestMain(m *testing.M) { var rubyServer *rubyserver.Server func testMain(m *testing.M) int { - defer testhelper.MustHaveNoChildProcess() + defer commandtest.MustHaveNoChildProcess() hooks.Override = "/does/not/exist" diff --git a/internal/supervisor/supervisor_test.go b/internal/supervisor/supervisor_test.go index c56e5fb3ebe..a124310de23 100644 --- a/internal/supervisor/supervisor_test.go +++ b/internal/supervisor/supervisor_test.go @@ -15,7 +15,7 @@ import ( "time" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" ) var ( @@ -29,7 +29,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - defer testhelper.MustHaveNoChildProcess() + defer commandtest.MustHaveNoChildProcess() var err error testDir, err = ioutil.TempDir("", "gitaly-supervisor-test") diff --git a/internal/tempdir/testhelper_test.go b/internal/tempdir/testhelper_test.go index 74656848a79..7870b90a510 100644 --- a/internal/tempdir/testhelper_test.go +++ b/internal/tempdir/testhelper_test.go @@ -4,7 +4,7 @@ import ( "os" "testing" - "gitlab.com/gitlab-org/gitaly/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" ) func TestMain(m *testing.M) { @@ -12,7 +12,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - defer testhelper.MustHaveNoChildProcess() + defer commandtest.MustHaveNoChildProcess() return m.Run() } diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go index ba91df83338..2ae204d0c48 100644 --- a/internal/testhelper/testhelper.go +++ b/internal/testhelper/testhelper.go @@ -15,9 +15,7 @@ import ( "path/filepath" "runtime" "strings" - "syscall" "testing" - "time" grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" @@ -28,9 +26,7 @@ import ( "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/config" - "gitlab.com/gitlab-org/gitaly/internal/git/catfile" "gitlab.com/gitlab-org/gitaly/internal/helper/fieldextractors" - "gitlab.com/gitlab-org/gitaly/internal/helper/text" gitalylog "gitlab.com/gitlab-org/gitaly/internal/log" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/internal/storage" @@ -298,63 +294,12 @@ func NewTestGrpcServer(tb testing.TB, streamInterceptors []grpc.StreamServerInte ) } -// MustHaveNoChildProcess panics if it finds a running or finished child -// process. It waits for 2 seconds for processes to be cleaned up by other -// goroutines. -func MustHaveNoChildProcess() { - waitDone := make(chan struct{}) - go func() { - catfile.ExpireAll() - command.WaitAllDone() - close(waitDone) - }() - - select { - case <-waitDone: - case <-time.After(2 * time.Second): - } - - mustFindNoFinishedChildProcess() - mustFindNoRunningChildProcess() -} - -func mustFindNoFinishedChildProcess() { - // Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error) - // - // We use pid -1 to wait for any child. We don't care about wstatus or - // rusage. Use WNOHANG to return immediately if there is no child waiting - // to be reaped. - wpid, err := syscall.Wait4(-1, nil, syscall.WNOHANG, nil) - if err == nil && wpid > 0 { - panic(fmt.Errorf("wait4 found child process %d", wpid)) - } -} - -func mustFindNoRunningChildProcess() { - pgrep := exec.Command("pgrep", "-P", fmt.Sprintf("%d", os.Getpid())) - desc := fmt.Sprintf("%q", strings.Join(pgrep.Args, " ")) - - out, err := pgrep.Output() - if err == nil { - pidsComma := strings.Replace(text.ChompBytes(out), "\n", ",", -1) - psOut, _ := exec.Command("ps", "-o", "pid,args", "-p", pidsComma).Output() - panic(fmt.Errorf("found running child processes %s:\n%s", pidsComma, psOut)) - } - - if status, ok := command.ExitStatus(err); ok && status == 1 { - // Exit status 1 means no processes were found - return - } - - panic(fmt.Errorf("%s: %v", desc, err)) -} - // Context returns a cancellable context. func Context() (context.Context, func()) { ctx, cancel := context.WithCancel(context.Background()) md := metadata.New(map[string]string{ - featureflag.HeaderKey(catfile.CacheFeatureFlagKey): "true", + featureflag.HeaderKey(featureflag.CatfileCacheKey): "true", "gitaly-session-id": "gitaly-test", }) ctx = metadata.NewOutgoingContext(ctx, md) -- GitLab From 364f6c55bd1fb5b5f5890bc749cb324fe6da660d Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Mon, 6 May 2019 18:45:36 +0200 Subject: [PATCH 3/4] Make diff smaller --- internal/command/commandtest/check.go | 63 ------------------- internal/git/catfile/testhelper_test.go | 4 +- internal/metadata/featureflag/flags.go | 3 + internal/rubyserver/testhelper_test.go | 3 +- internal/service/blob/testhelper_test.go | 3 +- internal/service/commit/testhelper_test.go | 3 +- internal/service/conflicts/testhelper_test.go | 3 +- internal/service/diff/testhelper_test.go | 3 +- .../service/objectpool/testhelper_test.go | 3 +- .../service/operations/testhelper_test.go | 3 +- internal/service/ref/testhelper_test.go | 3 +- internal/service/remote/testhelper_test.go | 3 +- internal/service/repository/gc_test.go | 2 +- internal/service/repository/repack.go | 4 +- internal/service/repository/repack_test.go | 2 +- .../service/repository/testhelper_test.go | 3 +- internal/service/ssh/testhelper_test.go | 3 +- internal/service/wiki/testhelper_test.go | 3 +- internal/supervisor/supervisor_test.go | 4 +- internal/tempdir/testhelper_test.go | 4 +- internal/testhelper/testhelper.go | 53 ++++++++++++++++ 21 files changed, 77 insertions(+), 98 deletions(-) delete mode 100644 internal/command/commandtest/check.go diff --git a/internal/command/commandtest/check.go b/internal/command/commandtest/check.go deleted file mode 100644 index 54f683e405b..00000000000 --- a/internal/command/commandtest/check.go +++ /dev/null @@ -1,63 +0,0 @@ -package commandtest - -import ( - "fmt" - "os" - "os/exec" - "strings" - "syscall" - "time" - - "gitlab.com/gitlab-org/gitaly/internal/command" - "gitlab.com/gitlab-org/gitaly/internal/helper/text" -) - -// MustHaveNoChildProcess panics if it finds a running or finished child -// process. It waits for 2 seconds for processes to be cleaned up by other -// goroutines. -func MustHaveNoChildProcess() { - waitDone := make(chan struct{}) - go func() { - command.WaitAllDone() - close(waitDone) - }() - - select { - case <-waitDone: - case <-time.After(2 * time.Second): - } - - mustFindNoFinishedChildProcess() - mustFindNoRunningChildProcess() -} - -func mustFindNoFinishedChildProcess() { - // Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error) - // - // We use pid -1 to wait for any child. We don't care about wstatus or - // rusage. Use WNOHANG to return immediately if there is no child waiting - // to be reaped. - wpid, err := syscall.Wait4(-1, nil, syscall.WNOHANG, nil) - if err == nil && wpid > 0 { - panic(fmt.Errorf("wait4 found child process %d", wpid)) - } -} - -func mustFindNoRunningChildProcess() { - pgrep := exec.Command("pgrep", "-P", fmt.Sprintf("%d", os.Getpid())) - desc := fmt.Sprintf("%q", strings.Join(pgrep.Args, " ")) - - out, err := pgrep.Output() - if err == nil { - pidsComma := strings.Replace(text.ChompBytes(out), "\n", ",", -1) - psOut, _ := exec.Command("ps", "-o", "pid,args", "-p", pidsComma).Output() - panic(fmt.Errorf("found running child processes %s:\n%s", pidsComma, psOut)) - } - - if status, ok := command.ExitStatus(err); ok && status == 1 { - // Exit status 1 means no processes were found - return - } - - panic(fmt.Errorf("%s: %v", desc, err)) -} diff --git a/internal/git/catfile/testhelper_test.go b/internal/git/catfile/testhelper_test.go index 30c16993799..715d770f784 100644 --- a/internal/git/catfile/testhelper_test.go +++ b/internal/git/catfile/testhelper_test.go @@ -4,7 +4,7 @@ import ( "os" "testing" - "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" + "gitlab.com/gitlab-org/gitaly/internal/testhelper" ) func TestMain(m *testing.M) { @@ -12,7 +12,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - defer commandtest.MustHaveNoChildProcess() + defer testhelper.MustHaveNoChildProcess() return m.Run() } diff --git a/internal/metadata/featureflag/flags.go b/internal/metadata/featureflag/flags.go index 3611acff261..9ca6f7520e8 100644 --- a/internal/metadata/featureflag/flags.go +++ b/internal/metadata/featureflag/flags.go @@ -4,4 +4,7 @@ const ( // CatfileCacheKey is the feature flag key for catfile batch caching. This should match // what is in gitlab-ce CatfileCacheKey = "catfile-cache" + + // DeltaIslandsKey controls whether we use Git delta islands during a repack. + DeltaIslandsKey = "delta-islands" ) diff --git a/internal/rubyserver/testhelper_test.go b/internal/rubyserver/testhelper_test.go index f4dda89ac51..cc83a7923ca 100644 --- a/internal/rubyserver/testhelper_test.go +++ b/internal/rubyserver/testhelper_test.go @@ -4,7 +4,6 @@ import ( "os" "testing" - "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/testhelper" ) @@ -17,7 +16,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - defer commandtest.MustHaveNoChildProcess() + defer testhelper.MustHaveNoChildProcess() return m.Run() } diff --git a/internal/service/blob/testhelper_test.go b/internal/service/blob/testhelper_test.go index 8478b41561b..95cc08caf54 100644 --- a/internal/service/blob/testhelper_test.go +++ b/internal/service/blob/testhelper_test.go @@ -7,7 +7,6 @@ import ( "testing" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" - "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "google.golang.org/grpc" @@ -21,7 +20,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - defer commandtest.MustHaveNoChildProcess() + defer testhelper.MustHaveNoChildProcess() var err error testhelper.ConfigureRuby() diff --git a/internal/service/commit/testhelper_test.go b/internal/service/commit/testhelper_test.go index 8153bdc883b..861b2e89ced 100644 --- a/internal/service/commit/testhelper_test.go +++ b/internal/service/commit/testhelper_test.go @@ -8,7 +8,6 @@ import ( "github.com/golang/protobuf/ptypes/timestamp" log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" - "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/linguist" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/testhelper" @@ -25,7 +24,7 @@ func TestMain(m *testing.M) { var rubyServer *rubyserver.Server func testMain(m *testing.M) int { - defer commandtest.MustHaveNoChildProcess() + defer testhelper.MustHaveNoChildProcess() testhelper.ConfigureRuby() if err := linguist.LoadColors(); err != nil { diff --git a/internal/service/conflicts/testhelper_test.go b/internal/service/conflicts/testhelper_test.go index 94935001314..482fc0631e3 100644 --- a/internal/service/conflicts/testhelper_test.go +++ b/internal/service/conflicts/testhelper_test.go @@ -7,7 +7,6 @@ import ( log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" - "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/git/hooks" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/testhelper" @@ -22,7 +21,7 @@ func TestMain(m *testing.M) { var RubyServer *rubyserver.Server func testMain(m *testing.M) int { - defer commandtest.MustHaveNoChildProcess() + defer testhelper.MustHaveNoChildProcess() var err error diff --git a/internal/service/diff/testhelper_test.go b/internal/service/diff/testhelper_test.go index e98b5ce7b12..bd5d792642e 100644 --- a/internal/service/diff/testhelper_test.go +++ b/internal/service/diff/testhelper_test.go @@ -7,7 +7,6 @@ import ( log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" - "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "google.golang.org/grpc" @@ -21,7 +20,7 @@ func TestMain(m *testing.M) { var rubyServer *rubyserver.Server func testMain(m *testing.M) int { - defer commandtest.MustHaveNoChildProcess() + defer testhelper.MustHaveNoChildProcess() var err error diff --git a/internal/service/objectpool/testhelper_test.go b/internal/service/objectpool/testhelper_test.go index b2bcfbcc0aa..943fd1942ac 100644 --- a/internal/service/objectpool/testhelper_test.go +++ b/internal/service/objectpool/testhelper_test.go @@ -7,7 +7,6 @@ import ( "time" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" - "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "google.golang.org/grpc" "google.golang.org/grpc/reflection" @@ -18,7 +17,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - defer commandtest.MustHaveNoChildProcess() + defer testhelper.MustHaveNoChildProcess() return m.Run() } diff --git a/internal/service/operations/testhelper_test.go b/internal/service/operations/testhelper_test.go index cd08dfdecb0..5649ed514d5 100644 --- a/internal/service/operations/testhelper_test.go +++ b/internal/service/operations/testhelper_test.go @@ -11,7 +11,6 @@ import ( log "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" - "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/git/hooks" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/testhelper" @@ -43,7 +42,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - defer commandtest.MustHaveNoChildProcess() + defer testhelper.MustHaveNoChildProcess() hookDir, err := ioutil.TempDir("", "gitaly-tmp-hooks") if err != nil { diff --git a/internal/service/ref/testhelper_test.go b/internal/service/ref/testhelper_test.go index c6abfa93ad2..3d7da42bbcb 100644 --- a/internal/service/ref/testhelper_test.go +++ b/internal/service/ref/testhelper_test.go @@ -10,7 +10,6 @@ import ( log "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" - "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/helper/lines" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/testhelper" @@ -81,7 +80,7 @@ func TestMain(m *testing.M) { var rubyServer *rubyserver.Server func testMain(m *testing.M) int { - defer commandtest.MustHaveNoChildProcess() + defer testhelper.MustHaveNoChildProcess() var err error diff --git a/internal/service/remote/testhelper_test.go b/internal/service/remote/testhelper_test.go index 6e30336ab8c..3f37b1c602a 100644 --- a/internal/service/remote/testhelper_test.go +++ b/internal/service/remote/testhelper_test.go @@ -7,7 +7,6 @@ import ( "testing" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" - "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "google.golang.org/grpc" @@ -21,7 +20,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - defer commandtest.MustHaveNoChildProcess() + defer testhelper.MustHaveNoChildProcess() var err error diff --git a/internal/service/repository/gc_test.go b/internal/service/repository/gc_test.go index 7bd0969af31..1ecd8689c40 100644 --- a/internal/service/repository/gc_test.go +++ b/internal/service/repository/gc_test.go @@ -309,7 +309,7 @@ func TestGarbageCollectDeltaIslands(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - md := metadata.New(map[string]string{featureflag.HeaderKey(deltaIslandsFeatureFlag): "true"}) + md := metadata.New(map[string]string{featureflag.HeaderKey(featureflag.DeltaIslandsKey): "true"}) ctxWithFeatureFlag := metadata.NewOutgoingContext(ctx, md) testCases := []struct { diff --git a/internal/service/repository/repack.go b/internal/service/repository/repack.go index aeaf5fe4f10..8af27f39579 100644 --- a/internal/service/repository/repack.go +++ b/internal/service/repository/repack.go @@ -13,8 +13,6 @@ import ( "google.golang.org/grpc/status" ) -const deltaIslandsFeatureFlag = "delta-islands" - var ( repackCounter = prometheus.NewCounterVec( prometheus.CounterOpts{ @@ -73,7 +71,7 @@ func repackConfig(ctx context.Context, bitmap bool) []string { args = append(args, "-c", "repack.writeBitmaps=false") } - deltaIslands := featureflag.IsEnabled(ctx, deltaIslandsFeatureFlag) + deltaIslands := featureflag.IsEnabled(ctx, featureflag.DeltaIslandsKey) if deltaIslands { args = append(args, "-c", "pack.island=refs/heads", diff --git a/internal/service/repository/repack_test.go b/internal/service/repository/repack_test.go index 082d41243d5..237f4bfa0ff 100644 --- a/internal/service/repository/repack_test.go +++ b/internal/service/repository/repack_test.go @@ -204,7 +204,7 @@ func TestRepackFullDeltaIslands(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - md := metadata.New(map[string]string{featureflag.HeaderKey(deltaIslandsFeatureFlag): "true"}) + md := metadata.New(map[string]string{featureflag.HeaderKey(featureflag.DeltaIslandsKey): "true"}) ctxWithFeatureFlag := metadata.NewOutgoingContext(ctx, md) testCases := []struct { diff --git a/internal/service/repository/testhelper_test.go b/internal/service/repository/testhelper_test.go index 304d2a8eaec..e2a8c1f95ac 100644 --- a/internal/service/repository/testhelper_test.go +++ b/internal/service/repository/testhelper_test.go @@ -11,7 +11,6 @@ import ( "github.com/stretchr/testify/assert" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" gitalyauth "gitlab.com/gitlab-org/gitaly/auth" - "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/server/auth" @@ -83,7 +82,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - defer commandtest.MustHaveNoChildProcess() + defer testhelper.MustHaveNoChildProcess() testhelper.ConfigureRuby() config.Config.Auth = config.Auth{Token: testhelper.RepositoryAuthToken} diff --git a/internal/service/ssh/testhelper_test.go b/internal/service/ssh/testhelper_test.go index 40c8b47bb4d..1945bf42837 100644 --- a/internal/service/ssh/testhelper_test.go +++ b/internal/service/ssh/testhelper_test.go @@ -8,7 +8,6 @@ import ( log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" - "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "google.golang.org/grpc" "google.golang.org/grpc/reflection" @@ -30,7 +29,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - defer commandtest.MustHaveNoChildProcess() + defer testhelper.MustHaveNoChildProcess() cwd = mustGetCwd() diff --git a/internal/service/wiki/testhelper_test.go b/internal/service/wiki/testhelper_test.go index 2400cb4b993..e909db22400 100644 --- a/internal/service/wiki/testhelper_test.go +++ b/internal/service/wiki/testhelper_test.go @@ -11,7 +11,6 @@ import ( log "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" - "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" "gitlab.com/gitlab-org/gitaly/internal/git/hooks" gitlog "gitlab.com/gitlab-org/gitaly/internal/git/log" "gitlab.com/gitlab-org/gitaly/internal/helper" @@ -39,7 +38,7 @@ func TestMain(m *testing.M) { var rubyServer *rubyserver.Server func testMain(m *testing.M) int { - defer commandtest.MustHaveNoChildProcess() + defer testhelper.MustHaveNoChildProcess() hooks.Override = "/does/not/exist" diff --git a/internal/supervisor/supervisor_test.go b/internal/supervisor/supervisor_test.go index a124310de23..c56e5fb3ebe 100644 --- a/internal/supervisor/supervisor_test.go +++ b/internal/supervisor/supervisor_test.go @@ -15,7 +15,7 @@ import ( "time" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" + "gitlab.com/gitlab-org/gitaly/internal/testhelper" ) var ( @@ -29,7 +29,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - defer commandtest.MustHaveNoChildProcess() + defer testhelper.MustHaveNoChildProcess() var err error testDir, err = ioutil.TempDir("", "gitaly-supervisor-test") diff --git a/internal/tempdir/testhelper_test.go b/internal/tempdir/testhelper_test.go index 7870b90a510..74656848a79 100644 --- a/internal/tempdir/testhelper_test.go +++ b/internal/tempdir/testhelper_test.go @@ -4,7 +4,7 @@ import ( "os" "testing" - "gitlab.com/gitlab-org/gitaly/internal/command/commandtest" + "gitlab.com/gitlab-org/gitaly/internal/testhelper" ) func TestMain(m *testing.M) { @@ -12,7 +12,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - defer commandtest.MustHaveNoChildProcess() + defer testhelper.MustHaveNoChildProcess() return m.Run() } diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go index 2ae204d0c48..c3d273503dd 100644 --- a/internal/testhelper/testhelper.go +++ b/internal/testhelper/testhelper.go @@ -15,7 +15,9 @@ import ( "path/filepath" "runtime" "strings" + "syscall" "testing" + "time" grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" @@ -27,6 +29,7 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/helper/fieldextractors" + "gitlab.com/gitlab-org/gitaly/internal/helper/text" gitalylog "gitlab.com/gitlab-org/gitaly/internal/log" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/internal/storage" @@ -294,6 +297,56 @@ func NewTestGrpcServer(tb testing.TB, streamInterceptors []grpc.StreamServerInte ) } +// MustHaveNoChildProcess panics if it finds a running or finished child +// process. It waits for 2 seconds for processes to be cleaned up by other +// goroutines. +func MustHaveNoChildProcess() { + waitDone := make(chan struct{}) + go func() { + command.WaitAllDone() + close(waitDone) + }() + + select { + case <-waitDone: + case <-time.After(2 * time.Second): + } + + mustFindNoFinishedChildProcess() + mustFindNoRunningChildProcess() +} + +func mustFindNoFinishedChildProcess() { + // Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error) + // + // We use pid -1 to wait for any child. We don't care about wstatus or + // rusage. Use WNOHANG to return immediately if there is no child waiting + // to be reaped. + wpid, err := syscall.Wait4(-1, nil, syscall.WNOHANG, nil) + if err == nil && wpid > 0 { + panic(fmt.Errorf("wait4 found child process %d", wpid)) + } +} + +func mustFindNoRunningChildProcess() { + pgrep := exec.Command("pgrep", "-P", fmt.Sprintf("%d", os.Getpid())) + desc := fmt.Sprintf("%q", strings.Join(pgrep.Args, " ")) + + out, err := pgrep.Output() + if err == nil { + pidsComma := strings.Replace(text.ChompBytes(out), "\n", ",", -1) + psOut, _ := exec.Command("ps", "-o", "pid,args", "-p", pidsComma).Output() + panic(fmt.Errorf("found running child processes %s:\n%s", pidsComma, psOut)) + } + + if status, ok := command.ExitStatus(err); ok && status == 1 { + // Exit status 1 means no processes were found + return + } + + panic(fmt.Errorf("%s: %v", desc, err)) +} + // Context returns a cancellable context. func Context() (context.Context, func()) { ctx, cancel := context.WithCancel(context.Background()) -- GitLab From 9c90196ae06e3a8c0687d9227a29aa2d85975c86 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Mon, 6 May 2019 18:47:59 +0200 Subject: [PATCH 4/4] changelog --- changelogs/unreleased/enable-catfile-cache-in-test.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelogs/unreleased/enable-catfile-cache-in-test.yml diff --git a/changelogs/unreleased/enable-catfile-cache-in-test.yml b/changelogs/unreleased/enable-catfile-cache-in-test.yml new file mode 100644 index 00000000000..3195ac22417 --- /dev/null +++ b/changelogs/unreleased/enable-catfile-cache-in-test.yml @@ -0,0 +1,5 @@ +--- +title: Use cat-file caching in tests by default +merge_request: 1239 +author: +type: other -- GitLab