Skip to content

Commit 9ae50ca

Browse files
committed
fix test
1 parent 999acef commit 9ae50ca

File tree

3 files changed

+119
-1
lines changed

3 files changed

+119
-1
lines changed

pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import (
7676
metaserveragent "github.com/kubewharf/katalyst-core/pkg/metaserver/agent"
7777
"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/pod"
7878
"github.com/kubewharf/katalyst-core/pkg/metaserver/external"
79+
kcc "github.com/kubewharf/katalyst-core/pkg/metaserver/kcc"
7980
"github.com/kubewharf/katalyst-core/pkg/metrics"
8081
"github.com/kubewharf/katalyst-core/pkg/util/asyncworker"
8182
"github.com/kubewharf/katalyst-core/pkg/util/machine"
@@ -3226,7 +3227,8 @@ func makeMetaServer() *metaserver.MetaServer {
32263227
},
32273228
PodFetcher: &pod.PodFetcherStub{},
32283229
},
3229-
ExternalManager: external.InitExternalManager(&pod.PodFetcherStub{}),
3230+
ConfigurationManager: &kcc.DummyConfigurationManager{},
3231+
ExternalManager: external.InitExternalManager(&pod.PodFetcherStub{}),
32303232
}
32313233
}
32323234

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ package userwatermark
1919
import (
2020
"fmt"
2121
"sync"
22+
"sync/atomic"
2223
"testing"
24+
"time"
2325

2426
"github.com/bytedance/mockey"
2527
"github.com/stretchr/testify/assert"
@@ -43,6 +45,12 @@ import (
4345
// Guard all mockey usage in this package even when tests use t.Parallel().
4446
var mockeyMutex sync.Mutex
4547

48+
// Track currently running mockey tests to prevent concurrent mockey usage
49+
var (
50+
mockeyTestCount int32
51+
mockeyTestMutex sync.Mutex
52+
)
53+
4654
func generateUserWatermarkTestMetaServer(pods []*v1.Pod) *metaserver.MetaServer {
4755
podFetcher := &metapod.PodFetcherStub{PodList: pods}
4856

@@ -89,6 +97,21 @@ func TestUserWatermarkReclaimManager_Reconcile_Disabled(t *testing.T) {
8997

9098
func TestUserWatermarkReclaimManager_Reconcile_CreateReclaimers(t *testing.T) {
9199
t.Parallel()
100+
101+
// Ensure only one mockey test runs at a time
102+
mockeyTestMutex.Lock()
103+
for atomic.LoadInt32(&mockeyTestCount) > 0 {
104+
mockeyTestMutex.Unlock()
105+
time.Sleep(10 * time.Millisecond)
106+
mockeyTestMutex.Lock()
107+
}
108+
atomic.StoreInt32(&mockeyTestCount, 1)
109+
mockeyTestMutex.Unlock()
110+
111+
defer func() {
112+
atomic.StoreInt32(&mockeyTestCount, 0)
113+
}()
114+
92115
mockeyMutex.Lock()
93116
defer mockeyMutex.Unlock()
94117

@@ -153,6 +176,21 @@ func TestUserWatermarkReclaimManager_Reconcile_CreateReclaimers(t *testing.T) {
153176

154177
func TestUserWatermarkReclaimManager_Reconcile_GetPodListError(t *testing.T) {
155178
t.Parallel()
179+
180+
// Ensure only one mockey test runs at a time
181+
mockeyTestMutex.Lock()
182+
for atomic.LoadInt32(&mockeyTestCount) > 0 {
183+
mockeyTestMutex.Unlock()
184+
time.Sleep(10 * time.Millisecond)
185+
mockeyTestMutex.Lock()
186+
}
187+
atomic.StoreInt32(&mockeyTestCount, 1)
188+
mockeyTestMutex.Unlock()
189+
190+
defer func() {
191+
atomic.StoreInt32(&mockeyTestCount, 0)
192+
}()
193+
156194
mockeyMutex.Lock()
157195
defer mockeyMutex.Unlock()
158196

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package userwatermark
1919
import (
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+
3942
func 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

348396
func 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

424487
func 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

Comments
 (0)