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:
authorSami Hiltunen <shiltunen@gitlab.com>2023-08-22 14:46:13 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2023-08-31 09:29:18 +0300
commit97b4c2fdfb7fe78be017fd3819a1849039a02377 (patch)
treea8c1b8f1835227cb45f7d8c56148fe2dae97d165 /internal/cgroups
parenta3dedd2661cada20c703b79d93c6fbbb62d48f90 (diff)
Replace NewLogger calls with SharedLogger calls in tests
This commit wires the tests to call SharedLogger instead of NewLogger so they'll use the test case's shared logger. This way the log output is printed to the same logger and is ordered.
Diffstat (limited to 'internal/cgroups')
-rw-r--r--internal/cgroups/cgroups_linux_test.go2
-rw-r--r--internal/cgroups/v1_linux_test.go30
-rw-r--r--internal/cgroups/v2_linux_test.go26
3 files changed, 29 insertions, 29 deletions
diff --git a/internal/cgroups/cgroups_linux_test.go b/internal/cgroups/cgroups_linux_test.go
index 3ca07c6bd..c3e7e143d 100644
--- a/internal/cgroups/cgroups_linux_test.go
+++ b/internal/cgroups/cgroups_linux_test.go
@@ -11,5 +11,5 @@ import (
)
func TestNewManager(t *testing.T) {
- require.IsType(t, &NoopManager{}, NewManager(cgroups.Config{}, testhelper.NewLogger(t), 1))
+ require.IsType(t, &NoopManager{}, NewManager(cgroups.Config{}, testhelper.SharedLogger(t), 1))
}
diff --git a/internal/cgroups/v1_linux_test.go b/internal/cgroups/v1_linux_test.go
index cd97ffbfb..d8bc70383 100644
--- a/internal/cgroups/v1_linux_test.go
+++ b/internal/cgroups/v1_linux_test.go
@@ -38,11 +38,11 @@ func defaultCgroupsConfig() cgroups.Config {
func TestNewManagerV1(t *testing.T) {
cfg := cgroups.Config{Repositories: cgroups.Repositories{Count: 10}}
- manager := newCgroupManagerWithMode(cfg, testhelper.NewLogger(t), 1, cgrps.Legacy)
+ manager := newCgroupManagerWithMode(cfg, testhelper.SharedLogger(t), 1, cgrps.Legacy)
require.IsType(t, &cgroupV1Handler{}, manager.handler)
- manager = newCgroupManagerWithMode(cfg, testhelper.NewLogger(t), 1, cgrps.Hybrid)
+ manager = newCgroupManagerWithMode(cfg, testhelper.SharedLogger(t), 1, cgrps.Hybrid)
require.IsType(t, &cgroupV1Handler{}, manager.handler)
- manager = newCgroupManagerWithMode(cfg, testhelper.NewLogger(t), 1, cgrps.Unavailable)
+ manager = newCgroupManagerWithMode(cfg, testhelper.SharedLogger(t), 1, cgrps.Unavailable)
require.Nil(t, manager)
}
@@ -101,7 +101,7 @@ func TestSetup_ParentCgroups(t *testing.T) {
tt.cfg.HierarchyRoot = "gitaly"
tt.cfg.Mountpoint = mock.root
- v1Manager := mock.newCgroupManager(tt.cfg, testhelper.NewLogger(t), pid)
+ v1Manager := mock.newCgroupManager(tt.cfg, testhelper.SharedLogger(t), pid)
require.False(t, v1Manager.Ready())
require.NoError(t, v1Manager.Setup())
require.True(t, v1Manager.Ready())
@@ -184,7 +184,7 @@ func TestSetup_RepoCgroups(t *testing.T) {
cfg.HierarchyRoot = "gitaly"
cfg.Mountpoint = mock.root
- v1Manager := mock.newCgroupManager(cfg, testhelper.NewLogger(t), pid)
+ v1Manager := mock.newCgroupManager(cfg, testhelper.SharedLogger(t), pid)
require.False(t, v1Manager.Ready())
require.NoError(t, v1Manager.Setup())
@@ -226,14 +226,14 @@ func TestAddCommand(t *testing.T) {
config.Mountpoint = mock.root
pid := 1
- v1Manager1 := mock.newCgroupManager(config, testhelper.NewLogger(t), pid)
+ v1Manager1 := mock.newCgroupManager(config, testhelper.SharedLogger(t), pid)
require.NoError(t, v1Manager1.Setup())
ctx := testhelper.Context(t)
cmd2 := exec.CommandContext(ctx, "ls", "-hal", ".")
require.NoError(t, cmd2.Run())
- v1Manager2 := mock.newCgroupManager(config, testhelper.NewLogger(t), pid)
+ v1Manager2 := mock.newCgroupManager(config, testhelper.SharedLogger(t), pid)
t.Run("without overridden key", func(t *testing.T) {
_, err := v1Manager2.AddCommand(cmd2)
@@ -281,7 +281,7 @@ func TestCleanup(t *testing.T) {
cfg := defaultCgroupsConfig()
cfg.Mountpoint = mock.root
- v1Manager := mock.newCgroupManager(cfg, testhelper.NewLogger(t), pid)
+ v1Manager := mock.newCgroupManager(cfg, testhelper.SharedLogger(t), pid)
require.NoError(t, v1Manager.Setup())
require.NoError(t, v1Manager.Cleanup())
@@ -348,7 +348,7 @@ gitaly_cgroup_cpu_cfs_throttled_seconds_total{path="%s"} 0.001
config.Mountpoint = mock.root
config.MetricsEnabled = tt.metricsEnabled
- v1Manager1 := mock.newCgroupManager(config, testhelper.NewLogger(t), tt.pid)
+ v1Manager1 := mock.newCgroupManager(config, testhelper.SharedLogger(t), tt.pid)
mock.setupMockCgroupFiles(t, v1Manager1, mockCgroupFile{"memory.failcnt", "2"})
require.NoError(t, v1Manager1.Setup())
@@ -406,7 +406,7 @@ func TestPruneOldCgroups(t *testing.T) {
},
setup: func(t *testing.T, cfg cgroups.Config, mock *mockCgroup) int {
pid := 1
- cgroupManager := mock.newCgroupManager(cfg, testhelper.NewLogger(t), pid)
+ cgroupManager := mock.newCgroupManager(cfg, testhelper.SharedLogger(t), pid)
require.NoError(t, cgroupManager.Setup())
return pid
@@ -425,7 +425,7 @@ func TestPruneOldCgroups(t *testing.T) {
},
setup: func(t *testing.T, cfg cgroups.Config, mock *mockCgroup) int {
pid := 1
- cgroupManager := mock.newCgroupManager(cfg, testhelper.NewLogger(t), pid)
+ cgroupManager := mock.newCgroupManager(cfg, testhelper.SharedLogger(t), pid)
require.NoError(t, cgroupManager.Setup())
return 1
},
@@ -446,7 +446,7 @@ func TestPruneOldCgroups(t *testing.T) {
require.NoError(t, cmd.Run())
pid := cmd.Process.Pid
- cgroupManager := mock.newCgroupManager(cfg, testhelper.NewLogger(t), pid)
+ cgroupManager := mock.newCgroupManager(cfg, testhelper.SharedLogger(t), pid)
require.NoError(t, cgroupManager.Setup())
memoryRoot := filepath.Join(
@@ -474,7 +474,7 @@ func TestPruneOldCgroups(t *testing.T) {
setup: func(t *testing.T, cfg cgroups.Config, mock *mockCgroup) int {
pid := os.Getpid()
- cgroupManager := mock.newCgroupManager(cfg, testhelper.NewLogger(t), pid)
+ cgroupManager := mock.newCgroupManager(cfg, testhelper.SharedLogger(t), pid)
require.NoError(t, cgroupManager.Setup())
return pid
@@ -492,7 +492,7 @@ func TestPruneOldCgroups(t *testing.T) {
},
},
setup: func(t *testing.T, cfg cgroups.Config, mock *mockCgroup) int {
- cgroupManager := mock.newCgroupManager(cfg, testhelper.NewLogger(t), 0)
+ cgroupManager := mock.newCgroupManager(cfg, testhelper.SharedLogger(t), 0)
require.NoError(t, cgroupManager.Setup())
return 0
@@ -599,7 +599,7 @@ throttled_time 1000000`}, // 0.001 seconds
config.Repositories.CPUShares = 16
config.Mountpoint = mock.root
- v1Manager := mock.newCgroupManager(config, testhelper.NewLogger(t), 1)
+ v1Manager := mock.newCgroupManager(config, testhelper.SharedLogger(t), 1)
mock.setupMockCgroupFiles(t, v1Manager, tc.mockFiles...)
require.NoError(t, v1Manager.Setup())
diff --git a/internal/cgroups/v2_linux_test.go b/internal/cgroups/v2_linux_test.go
index 8985c7349..0215edb39 100644
--- a/internal/cgroups/v2_linux_test.go
+++ b/internal/cgroups/v2_linux_test.go
@@ -38,7 +38,7 @@ func defaultCgroupsV2Config() cgroups.Config {
func TestNewManagerV2(t *testing.T) {
cfg := cgroups.Config{Repositories: cgroups.Repositories{Count: 10}}
- manager := newCgroupManagerWithMode(cfg, testhelper.NewLogger(t), 1, cgrps.Unified)
+ manager := newCgroupManagerWithMode(cfg, testhelper.SharedLogger(t), 1, cgrps.Unified)
require.IsType(t, &cgroupV2Handler{}, manager.handler)
}
@@ -95,7 +95,7 @@ func TestSetup_ParentCgroupsV2(t *testing.T) {
tt.cfg.HierarchyRoot = "gitaly"
tt.cfg.Mountpoint = mock.root
- v2Manager := mock.newCgroupManager(tt.cfg, testhelper.NewLogger(t), pid)
+ v2Manager := mock.newCgroupManager(tt.cfg, testhelper.SharedLogger(t), pid)
mock.setupMockCgroupFiles(t, v2Manager)
require.False(t, v2Manager.Ready())
@@ -174,7 +174,7 @@ func TestSetup_RepoCgroupsV2(t *testing.T) {
cfg.Mountpoint = mock.root
cfg.Repositories = tt.cfg
- v2Manager := mock.newCgroupManager(cfg, testhelper.NewLogger(t), pid)
+ v2Manager := mock.newCgroupManager(cfg, testhelper.SharedLogger(t), pid)
mock.setupMockCgroupFiles(t, v2Manager)
require.False(t, v2Manager.Ready())
@@ -212,7 +212,7 @@ func TestAddCommandV2(t *testing.T) {
pid := 1
- v2Manager1 := mock.newCgroupManager(config, testhelper.NewLogger(t), pid)
+ v2Manager1 := mock.newCgroupManager(config, testhelper.SharedLogger(t), pid)
mock.setupMockCgroupFiles(t, v2Manager1)
require.NoError(t, v2Manager1.Setup())
@@ -221,7 +221,7 @@ func TestAddCommandV2(t *testing.T) {
cmd2 := exec.CommandContext(ctx, "ls", "-hal", ".")
require.NoError(t, cmd2.Run())
- v2Manager2 := mock.newCgroupManager(config, testhelper.NewLogger(t), pid)
+ v2Manager2 := mock.newCgroupManager(config, testhelper.SharedLogger(t), pid)
t.Run("without overridden key", func(t *testing.T) {
_, err := v2Manager2.AddCommand(cmd2)
@@ -265,7 +265,7 @@ func TestCleanupV2(t *testing.T) {
cfg := defaultCgroupsV2Config()
cfg.Mountpoint = mock.root
- v2Manager := mock.newCgroupManager(cfg, testhelper.NewLogger(t), pid)
+ v2Manager := mock.newCgroupManager(cfg, testhelper.SharedLogger(t), pid)
mock.setupMockCgroupFiles(t, v2Manager)
require.NoError(t, v2Manager.Setup())
@@ -327,7 +327,7 @@ gitaly_cgroup_procs_total{path="%s",subsystem="memory"} 1
config.Mountpoint = mock.root
config.MetricsEnabled = tt.metricsEnabled
- v2Manager1 := mock.newCgroupManager(config, testhelper.NewLogger(t), tt.pid)
+ v2Manager1 := mock.newCgroupManager(config, testhelper.SharedLogger(t), tt.pid)
mock.setupMockCgroupFiles(t, v2Manager1)
require.NoError(t, v2Manager1.Setup())
@@ -387,7 +387,7 @@ func TestPruneOldCgroupsV2(t *testing.T) {
setup: func(t *testing.T, cfg cgroups.Config, mock *mockCgroupV2) int {
pid := 1
- cgroupManager := mock.newCgroupManager(cfg, testhelper.NewLogger(t), pid)
+ cgroupManager := mock.newCgroupManager(cfg, testhelper.SharedLogger(t), pid)
mock.setupMockCgroupFiles(t, cgroupManager)
require.NoError(t, cgroupManager.Setup())
@@ -408,7 +408,7 @@ func TestPruneOldCgroupsV2(t *testing.T) {
setup: func(t *testing.T, cfg cgroups.Config, mock *mockCgroupV2) int {
pid := 1
- cgroupManager := mock.newCgroupManager(cfg, testhelper.NewLogger(t), pid)
+ cgroupManager := mock.newCgroupManager(cfg, testhelper.SharedLogger(t), pid)
mock.setupMockCgroupFiles(t, cgroupManager)
require.NoError(t, cgroupManager.Setup())
return 1
@@ -430,7 +430,7 @@ func TestPruneOldCgroupsV2(t *testing.T) {
require.NoError(t, cmd.Run())
pid := cmd.Process.Pid
- cgroupManager := mock.newCgroupManager(cfg, testhelper.NewLogger(t), pid)
+ cgroupManager := mock.newCgroupManager(cfg, testhelper.SharedLogger(t), pid)
mock.setupMockCgroupFiles(t, cgroupManager)
require.NoError(t, cgroupManager.Setup())
@@ -458,7 +458,7 @@ func TestPruneOldCgroupsV2(t *testing.T) {
setup: func(t *testing.T, cfg cgroups.Config, mock *mockCgroupV2) int {
pid := os.Getpid()
- cgroupManager := mock.newCgroupManager(cfg, testhelper.NewLogger(t), pid)
+ cgroupManager := mock.newCgroupManager(cfg, testhelper.SharedLogger(t), pid)
mock.setupMockCgroupFiles(t, cgroupManager)
require.NoError(t, cgroupManager.Setup())
@@ -477,7 +477,7 @@ func TestPruneOldCgroupsV2(t *testing.T) {
},
},
setup: func(t *testing.T, cfg cgroups.Config, mock *mockCgroupV2) int {
- cgroupManager := mock.newCgroupManager(cfg, testhelper.NewLogger(t), 0)
+ cgroupManager := mock.newCgroupManager(cfg, testhelper.SharedLogger(t), 0)
mock.setupMockCgroupFiles(t, cgroupManager)
require.NoError(t, cgroupManager.Setup())
@@ -571,7 +571,7 @@ throttled_usec 1000000`}, // 0.001 seconds
config.Repositories.CPUShares = 16
config.Mountpoint = mock.root
- v2Manager := mock.newCgroupManager(config, testhelper.NewLogger(t), 1)
+ v2Manager := mock.newCgroupManager(config, testhelper.SharedLogger(t), 1)
mock.setupMockCgroupFiles(t, v2Manager, tc.mockFiles...)
require.NoError(t, v2Manager.Setup())