@@ -19,6 +19,7 @@ package userwatermark
1919import (
2020 "context"
2121 "fmt"
22+ "sync/atomic"
2223 "testing"
2324 "time"
2425
@@ -36,6 +37,8 @@ import (
3637 "github.com/kubewharf/katalyst-core/pkg/util/machine"
3738)
3839
40+ // Import shared variables from manager_test.go
41+
3942func newTestDynamicConf () * dynamicconfig.DynamicAgentConfiguration {
4043 // NewDynamicAgentConfiguration already initializes a non-nil
4144 // UserWatermarkConfiguration via NewConfiguration().
@@ -205,6 +208,21 @@ func TestGetContainerCgroupPath_SuccessAndError(t *testing.T) {
205208
206209 t .Run ("success" , func (t * testing.T ) {
207210 t .Parallel ()
211+
212+ // Ensure only one mockey test runs at a time
213+ mockeyTestMutex .Lock ()
214+ for atomic .LoadInt32 (& mockeyTestCount ) > 0 {
215+ mockeyTestMutex .Unlock ()
216+ time .Sleep (10 * time .Millisecond )
217+ mockeyTestMutex .Lock ()
218+ }
219+ atomic .StoreInt32 (& mockeyTestCount , 1 )
220+ mockeyTestMutex .Unlock ()
221+
222+ defer func () {
223+ atomic .StoreInt32 (& mockeyTestCount , 0 )
224+ }()
225+
208226 mockeyMutex .Lock ()
209227 defer mockeyMutex .Unlock ()
210228
@@ -239,6 +257,21 @@ func TestGetCGroupMemoryLimitAndUsage(t *testing.T) {
239257
240258 t .Run ("success" , func (t * testing.T ) {
241259 t .Parallel ()
260+
261+ // Ensure only one mockey test runs at a time
262+ mockeyTestMutex .Lock ()
263+ for atomic .LoadInt32 (& mockeyTestCount ) > 0 {
264+ mockeyTestMutex .Unlock ()
265+ time .Sleep (10 * time .Millisecond )
266+ mockeyTestMutex .Lock ()
267+ }
268+ atomic .StoreInt32 (& mockeyTestCount , 1 )
269+ mockeyTestMutex .Unlock ()
270+
271+ defer func () {
272+ atomic .StoreInt32 (& mockeyTestCount , 0 )
273+ }()
274+
242275 mockeyMutex .Lock ()
243276 defer mockeyMutex .Unlock ()
244277
@@ -289,6 +322,21 @@ func TestGetCGroupMemoryStats(t *testing.T) {
289322
290323 t .Run ("success" , func (t * testing.T ) {
291324 t .Parallel ()
325+
326+ // Ensure only one mockey test runs at a time
327+ mockeyTestMutex .Lock ()
328+ for atomic .LoadInt32 (& mockeyTestCount ) > 0 {
329+ mockeyTestMutex .Unlock ()
330+ time .Sleep (10 * time .Millisecond )
331+ mockeyTestMutex .Lock ()
332+ }
333+ atomic .StoreInt32 (& mockeyTestCount , 1 )
334+ mockeyTestMutex .Unlock ()
335+
336+ defer func () {
337+ atomic .StoreInt32 (& mockeyTestCount , 0 )
338+ }()
339+
292340 mockeyMutex .Lock ()
293341 defer mockeyMutex .Unlock ()
294342
@@ -347,6 +395,21 @@ func TestReachedHighWatermark(t *testing.T) {
347395
348396func TestUserWatermarkReclaimer_ReclaimSuccess (t * testing.T ) {
349397 t .Parallel ()
398+
399+ // Ensure only one mockey test runs at a time
400+ mockeyTestMutex .Lock ()
401+ for atomic .LoadInt32 (& mockeyTestCount ) > 0 {
402+ mockeyTestMutex .Unlock ()
403+ time .Sleep (10 * time .Millisecond )
404+ mockeyTestMutex .Lock ()
405+ }
406+ atomic .StoreInt32 (& mockeyTestCount , 1 )
407+ mockeyTestMutex .Unlock ()
408+
409+ defer func () {
410+ atomic .StoreInt32 (& mockeyTestCount , 0 )
411+ }()
412+
350413 mockeyMutex .Lock ()
351414 defer mockeyMutex .Unlock ()
352415
@@ -423,6 +486,21 @@ func TestUserWatermarkReclaimer_ReclaimSuccess(t *testing.T) {
423486
424487func TestUserWatermarkReclaimer_ReclaimGetStatsFailed (t * testing.T ) {
425488 t .Parallel ()
489+
490+ // Ensure only one mockey test runs at a time
491+ mockeyTestMutex .Lock ()
492+ for atomic .LoadInt32 (& mockeyTestCount ) > 0 {
493+ mockeyTestMutex .Unlock ()
494+ time .Sleep (10 * time .Millisecond )
495+ mockeyTestMutex .Lock ()
496+ }
497+ atomic .StoreInt32 (& mockeyTestCount , 1 )
498+ mockeyTestMutex .Unlock ()
499+
500+ defer func () {
501+ atomic .StoreInt32 (& mockeyTestCount , 0 )
502+ }()
503+
426504 mockeyMutex .Lock ()
427505 defer mockeyMutex .Unlock ()
428506
0 commit comments