Skip to content

Commit f9f147c

Browse files
committed
fix test
1 parent 9ae50ca commit f9f147c

File tree

2 files changed

+75
-14
lines changed

2 files changed

+75
-14
lines changed

pkg/agent/qrm-plugins/memory/dynamicpolicy/userwatermark/manager_test.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ func TestUserWatermarkReclaimManager_Reconcile_CreateReclaimers(t *testing.T) {
124124
conf.UserWatermarkConfiguration.ServiceLabel = "svc-label"
125125

126126
// add a cgroup level configuration
127-
cgPath := "/sys/fs/cgroup/memory/custom"
127+
cgPath := "/sys/fs/cgroup/memory/custom-test-create"
128128
conf.UserWatermarkConfiguration.CgroupConfig[cgPath] = userwmconfig.NewReclaimConfigDetail(conf.UserWatermarkConfiguration.DefaultConfig)
129129

130130
podObj := &v1.Pod{
131131
ObjectMeta: metav1.ObjectMeta{
132-
UID: "pod-uid-1",
133-
Name: "test-pod",
132+
UID: "pod-uid-1-test-create",
133+
Name: "test-pod-create",
134134
Namespace: "default",
135135
Annotations: map[string]string{
136136
katalystapiconsts.PodAnnotationQoSLevelKey: katalystapiconsts.PodAnnotationQoSLevelSharedCores,
@@ -144,7 +144,7 @@ func TestUserWatermarkReclaimManager_Reconcile_CreateReclaimers(t *testing.T) {
144144
ContainerStatuses: []v1.ContainerStatus{
145145
{
146146
Name: "c1",
147-
ContainerID: "containerd://cid-1",
147+
ContainerID: "containerd://cid-1-test-create",
148148
Ready: true,
149149
},
150150
},
@@ -156,7 +156,7 @@ func TestUserWatermarkReclaimManager_Reconcile_CreateReclaimers(t *testing.T) {
156156
// patch container cgroup path helper to avoid touching real cgroups
157157
mockey.Mock(common.GetContainerAbsCgroupPath).
158158
To(func(_ string, podUID, containerID string) (string, error) {
159-
return "/sys/fs/cgroup/memory/test-cgroup", nil
159+
return "/sys/fs/cgroup/memory/test-cgroup-create", nil
160160
}).Build()
161161

162162
m := NewUserWatermarkReclaimManager(qosConfig, dynamicConf, metrics.DummyMetrics{}, ms)
@@ -240,33 +240,34 @@ func TestUserWatermarkReclaimManager_Reconcile_CleanupStaleReclaimers(t *testing
240240

241241
m := NewUserWatermarkReclaimManager(qosConfig, dynamicConf, metrics.DummyMetrics{}, ms)
242242

243-
podContainerKey := katalystcoreconsts.PodContainerName("pod-1,container-1")
244-
cgPath := "/sys/fs/cgroup/memory/old"
243+
// Generate unique keys to avoid potential conflicts with other parallel tests
244+
podContainerKey := katalystcoreconsts.PodContainerName("pod-1,container-1-test-cleanup")
245+
cgPath := "/sys/fs/cgroup/memory/old-test-cleanup"
245246

246247
frContainer := &fakeReclaimer{}
247248
frCgroup := &fakeReclaimer{}
248249

250+
// Directly set the state since we're testing the reconcile logic
249251
m.containerReclaimer[podContainerKey] = frContainer
250252
m.cgroupPathReclaimer[cgPath] = frCgroup
251-
252253
m.started[string(podContainerKey)] = true
253254
m.started[cgPath] = true
254255

255256
// no CgroupConfig for cgPath, and no pods => both reclaimers should be cleaned
256257
m.reconcile()
257258

258259
_, exist := m.containerReclaimer[podContainerKey]
259-
assert.False(t, exist)
260+
assert.False(t, exist, "container reclaimer should be cleaned up")
260261

261262
_, exist = m.cgroupPathReclaimer[cgPath]
262-
assert.False(t, exist)
263+
assert.False(t, exist, "cgroup path reclaimer should be cleaned up")
263264

264265
_, exist = m.started[string(podContainerKey)]
265-
assert.False(t, exist)
266+
assert.False(t, exist, "container started flag should be removed")
266267

267268
_, exist = m.started[cgPath]
268-
assert.False(t, exist)
269+
assert.False(t, exist, "cgroup path started flag should be removed")
269270

270-
assert.True(t, frContainer.stopped)
271-
assert.True(t, frCgroup.stopped)
271+
assert.True(t, frContainer.stopped, "container reclaimer should be stopped")
272+
assert.True(t, frCgroup.stopped, "cgroup path reclaimer should be stopped")
272273
}

pkg/agent/qrm-plugins/memory/dynamicpolicy/userwatermark/reclaimer_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,21 @@ func TestGetContainerCgroupPath_SuccessAndError(t *testing.T) {
238238

239239
t.Run("error", func(t *testing.T) {
240240
t.Parallel()
241+
242+
// Ensure only one mockey test runs at a time
243+
mockeyTestMutex.Lock()
244+
for atomic.LoadInt32(&mockeyTestCount) > 0 {
245+
mockeyTestMutex.Unlock()
246+
time.Sleep(10 * time.Millisecond)
247+
mockeyTestMutex.Lock()
248+
}
249+
atomic.StoreInt32(&mockeyTestCount, 1)
250+
mockeyTestMutex.Unlock()
251+
252+
defer func() {
253+
atomic.StoreInt32(&mockeyTestCount, 0)
254+
}()
255+
241256
mockeyMutex.Lock()
242257
defer mockeyMutex.Unlock()
243258

@@ -288,6 +303,21 @@ func TestGetCGroupMemoryLimitAndUsage(t *testing.T) {
288303

289304
t.Run("error", func(t *testing.T) {
290305
t.Parallel()
306+
307+
// Ensure only one mockey test runs at a time
308+
mockeyTestMutex.Lock()
309+
for atomic.LoadInt32(&mockeyTestCount) > 0 {
310+
mockeyTestMutex.Unlock()
311+
time.Sleep(10 * time.Millisecond)
312+
mockeyTestMutex.Lock()
313+
}
314+
atomic.StoreInt32(&mockeyTestCount, 1)
315+
mockeyTestMutex.Unlock()
316+
317+
defer func() {
318+
atomic.StoreInt32(&mockeyTestCount, 0)
319+
}()
320+
291321
mockeyMutex.Lock()
292322
defer mockeyMutex.Unlock()
293323

@@ -303,6 +333,21 @@ func TestGetCGroupMemoryLimitAndUsage(t *testing.T) {
303333

304334
t.Run("nilStats", func(t *testing.T) {
305335
t.Parallel()
336+
337+
// Ensure only one mockey test runs at a time
338+
mockeyTestMutex.Lock()
339+
for atomic.LoadInt32(&mockeyTestCount) > 0 {
340+
mockeyTestMutex.Unlock()
341+
time.Sleep(10 * time.Millisecond)
342+
mockeyTestMutex.Lock()
343+
}
344+
atomic.StoreInt32(&mockeyTestCount, 1)
345+
mockeyTestMutex.Unlock()
346+
347+
defer func() {
348+
atomic.StoreInt32(&mockeyTestCount, 0)
349+
}()
350+
306351
mockeyMutex.Lock()
307352
defer mockeyMutex.Unlock()
308353

@@ -366,6 +411,21 @@ func TestGetCGroupMemoryStats(t *testing.T) {
366411

367412
t.Run("error", func(t *testing.T) {
368413
t.Parallel()
414+
415+
// Ensure only one mockey test runs at a time
416+
mockeyTestMutex.Lock()
417+
for atomic.LoadInt32(&mockeyTestCount) > 0 {
418+
mockeyTestMutex.Unlock()
419+
time.Sleep(10 * time.Millisecond)
420+
mockeyTestMutex.Lock()
421+
}
422+
atomic.StoreInt32(&mockeyTestCount, 1)
423+
mockeyTestMutex.Unlock()
424+
425+
defer func() {
426+
atomic.StoreInt32(&mockeyTestCount, 0)
427+
}()
428+
369429
mockeyMutex.Lock()
370430
defer mockeyMutex.Unlock()
371431

0 commit comments

Comments
 (0)