diff options
author | Will Chandler <wchandler@gitlab.com> | 2023-10-27 00:09:41 +0300 |
---|---|---|
committer | Will Chandler <wchandler@gitlab.com> | 2023-10-27 16:45:45 +0300 |
commit | 4b81249cafade1e13efb6d0a55b4536cfe0feb5f (patch) | |
tree | f8fe3773dce7a2732b08ce9c98aa7c62750b9e37 | |
parent | 9e8ba7b13c0226c52c20482d243d5b2cb4f1e2b1 (diff) |
cgroups: Move repeated command to package variable
We reuse the same command many times in the cgroup tests.
Move the command arguments to a variable to make it clear we're running
the same thing every time.
-rw-r--r-- | internal/cgroups/testhelper_test.go | 3 | ||||
-rw-r--r-- | internal/cgroups/v1_linux_test.go | 8 | ||||
-rw-r--r-- | internal/cgroups/v2_linux_test.go | 8 |
3 files changed, 11 insertions, 8 deletions
diff --git a/internal/cgroups/testhelper_test.go b/internal/cgroups/testhelper_test.go index 55d0ae338..25b7e008e 100644 --- a/internal/cgroups/testhelper_test.go +++ b/internal/cgroups/testhelper_test.go @@ -10,6 +10,9 @@ import ( "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" ) +// cmdArgs are Command arguments used processes to be added to a cgroup. +var cmdArgs = []string{"ls", "-hal", "."} + func TestMain(m *testing.M) { testhelper.Run(m) } diff --git a/internal/cgroups/v1_linux_test.go b/internal/cgroups/v1_linux_test.go index e28df87df..cb28d40c0 100644 --- a/internal/cgroups/v1_linux_test.go +++ b/internal/cgroups/v1_linux_test.go @@ -228,7 +228,7 @@ func TestAddCommand(t *testing.T) { require.NoError(t, v1Manager1.Setup()) ctx := testhelper.Context(t) - cmd2 := exec.CommandContext(ctx, "ls", "-hal", ".") + cmd2 := exec.CommandContext(ctx, cmdArgs[0], cmdArgs[1:]...) require.NoError(t, cmd2.Run()) v1Manager2 := mock.newCgroupManager(config, testhelper.SharedLogger(t), pid) @@ -351,17 +351,17 @@ gitaly_cgroup_cpu_cfs_throttled_seconds_total{path="%s"} 0.001 ctx := testhelper.Context(t) - cmd := exec.CommandContext(ctx, "ls", "-hal", ".") + cmd := exec.CommandContext(ctx, cmdArgs[0], cmdArgs[1:]...) require.NoError(t, cmd.Start()) _, err := v1Manager1.AddCommand(cmd) require.NoError(t, err) - gitCmd1 := exec.CommandContext(ctx, "ls", "-hal", ".") + gitCmd1 := exec.CommandContext(ctx, cmdArgs[0], cmdArgs[1:]...) require.NoError(t, gitCmd1.Start()) _, err = v1Manager1.AddCommand(gitCmd1) require.NoError(t, err) - gitCmd2 := exec.CommandContext(ctx, "ls", "-hal", ".") + gitCmd2 := exec.CommandContext(ctx, cmdArgs[0], cmdArgs[1:]...) require.NoError(t, gitCmd2.Start()) _, err = v1Manager1.AddCommand(gitCmd2) require.NoError(t, err) diff --git a/internal/cgroups/v2_linux_test.go b/internal/cgroups/v2_linux_test.go index 347ce2498..67b5bc2dc 100644 --- a/internal/cgroups/v2_linux_test.go +++ b/internal/cgroups/v2_linux_test.go @@ -216,7 +216,7 @@ func TestAddCommandV2(t *testing.T) { require.NoError(t, v2Manager1.Setup()) ctx := testhelper.Context(t) - cmd2 := exec.CommandContext(ctx, "ls", "-hal", ".") + cmd2 := exec.CommandContext(ctx, cmdArgs[0], cmdArgs[1:]...) require.NoError(t, cmd2.Run()) v2Manager2 := mock.newCgroupManager(config, testhelper.SharedLogger(t), pid) @@ -330,17 +330,17 @@ gitaly_cgroup_procs_total{path="%s",subsystem="memory"} 1 ctx := testhelper.Context(t) - cmd := exec.CommandContext(ctx, "ls", "-hal", ".") + cmd := exec.CommandContext(ctx, cmdArgs[0], cmdArgs[1:]...) require.NoError(t, cmd.Start()) _, err := v2Manager1.AddCommand(cmd) require.NoError(t, err) - gitCmd1 := exec.CommandContext(ctx, "ls", "-hal", ".") + gitCmd1 := exec.CommandContext(ctx, cmdArgs[0], cmdArgs[1:]...) require.NoError(t, gitCmd1.Start()) _, err = v2Manager1.AddCommand(gitCmd1) require.NoError(t, err) - gitCmd2 := exec.CommandContext(ctx, "ls", "-hal", ".") + gitCmd2 := exec.CommandContext(ctx, cmdArgs[0], cmdArgs[1:]...) require.NoError(t, gitCmd2.Start()) _, err = v2Manager1.AddCommand(gitCmd2) require.NoError(t, err) |