Skip to content

Commit 999acef

Browse files
committed
test fix
1 parent d1b6cc9 commit 999acef

File tree

3 files changed

+25
-33
lines changed

3 files changed

+25
-33
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package userwatermark
1818

1919
import (
20-
"sync"
2120
"testing"
2221

2322
"github.com/stretchr/testify/assert"
@@ -33,8 +32,6 @@ const (
3332
TestSingleReclaimSize = 4096
3433
)
3534

36-
var calculatorMutex sync.Mutex
37-
3835
func NewDefaultMemoryWatermarkCalculator() *WatermarkCalculator {
3936
return NewMemoryWatermarkCalculator(TestCGroupPath, TestWatermarkScaleFactor, TestSingleReclaimFactor, TestSingleReclaimSize)
4037
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ import (
3939
"github.com/kubewharf/katalyst-core/pkg/util/native"
4040
)
4141

42-
var managerMutex sync.Mutex
42+
// mockey maintains a process-wide patch registry; Patch/UnPatchAll is not race-safe.
43+
// Guard all mockey usage in this package even when tests use t.Parallel().
44+
var mockeyMutex sync.Mutex
4345

4446
func generateUserWatermarkTestMetaServer(pods []*v1.Pod) *metaserver.MetaServer {
4547
podFetcher := &metapod.PodFetcherStub{PodList: pods}
@@ -87,8 +89,8 @@ func TestUserWatermarkReclaimManager_Reconcile_Disabled(t *testing.T) {
8789

8890
func TestUserWatermarkReclaimManager_Reconcile_CreateReclaimers(t *testing.T) {
8991
t.Parallel()
90-
managerMutex.Lock()
91-
defer managerMutex.Unlock()
92+
mockeyMutex.Lock()
93+
defer mockeyMutex.Unlock()
9294

9395
defer mockey.UnPatchAll()
9496
qosConfig := generic.NewQoSConfiguration()
@@ -151,8 +153,8 @@ func TestUserWatermarkReclaimManager_Reconcile_CreateReclaimers(t *testing.T) {
151153

152154
func TestUserWatermarkReclaimManager_Reconcile_GetPodListError(t *testing.T) {
153155
t.Parallel()
154-
managerMutex.Lock()
155-
defer managerMutex.Unlock()
156+
mockeyMutex.Lock()
157+
defer mockeyMutex.Unlock()
156158

157159
defer mockey.UnPatchAll()
158160

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

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package userwatermark
1919
import (
2020
"context"
2121
"fmt"
22-
"sync"
2322
"testing"
2423
"time"
2524

@@ -37,8 +36,6 @@ import (
3736
"github.com/kubewharf/katalyst-core/pkg/util/machine"
3837
)
3938

40-
var reclaimMutex = sync.Mutex{}
41-
4239
func newTestDynamicConf() *dynamicconfig.DynamicAgentConfiguration {
4340
// NewDynamicAgentConfiguration already initializes a non-nil
4441
// UserWatermarkConfiguration via NewConfiguration().
@@ -208,8 +205,8 @@ func TestGetContainerCgroupPath_SuccessAndError(t *testing.T) {
208205

209206
t.Run("success", func(t *testing.T) {
210207
t.Parallel()
211-
reclaimMutex.Lock()
212-
defer reclaimMutex.Unlock()
208+
mockeyMutex.Lock()
209+
defer mockeyMutex.Unlock()
213210

214211
defer mockey.UnPatchAll()
215212

@@ -223,8 +220,8 @@ func TestGetContainerCgroupPath_SuccessAndError(t *testing.T) {
223220

224221
t.Run("error", func(t *testing.T) {
225222
t.Parallel()
226-
reclaimMutex.Lock()
227-
defer reclaimMutex.Unlock()
223+
mockeyMutex.Lock()
224+
defer mockeyMutex.Unlock()
228225

229226
defer mockey.UnPatchAll()
230227

@@ -242,8 +239,8 @@ func TestGetCGroupMemoryLimitAndUsage(t *testing.T) {
242239

243240
t.Run("success", func(t *testing.T) {
244241
t.Parallel()
245-
reclaimMutex.Lock()
246-
defer reclaimMutex.Unlock()
242+
mockeyMutex.Lock()
243+
defer mockeyMutex.Unlock()
247244

248245
defer mockey.UnPatchAll()
249246

@@ -258,8 +255,8 @@ func TestGetCGroupMemoryLimitAndUsage(t *testing.T) {
258255

259256
t.Run("error", func(t *testing.T) {
260257
t.Parallel()
261-
reclaimMutex.Lock()
262-
defer reclaimMutex.Unlock()
258+
mockeyMutex.Lock()
259+
defer mockeyMutex.Unlock()
263260

264261
defer mockey.UnPatchAll()
265262

@@ -273,8 +270,8 @@ func TestGetCGroupMemoryLimitAndUsage(t *testing.T) {
273270

274271
t.Run("nilStats", func(t *testing.T) {
275272
t.Parallel()
276-
reclaimMutex.Lock()
277-
defer reclaimMutex.Unlock()
273+
mockeyMutex.Lock()
274+
defer mockeyMutex.Unlock()
278275

279276
defer mockey.UnPatchAll()
280277

@@ -292,8 +289,8 @@ func TestGetCGroupMemoryStats(t *testing.T) {
292289

293290
t.Run("success", func(t *testing.T) {
294291
t.Parallel()
295-
reclaimMutex.Lock()
296-
defer reclaimMutex.Unlock()
292+
mockeyMutex.Lock()
293+
defer mockeyMutex.Unlock()
297294

298295
defer mockey.UnPatchAll()
299296

@@ -321,8 +318,8 @@ func TestGetCGroupMemoryStats(t *testing.T) {
321318

322319
t.Run("error", func(t *testing.T) {
323320
t.Parallel()
324-
reclaimMutex.Lock()
325-
defer reclaimMutex.Unlock()
321+
mockeyMutex.Lock()
322+
defer mockeyMutex.Unlock()
326323

327324
defer mockey.UnPatchAll()
328325

@@ -350,12 +347,8 @@ func TestReachedHighWatermark(t *testing.T) {
350347

351348
func TestUserWatermarkReclaimer_ReclaimSuccess(t *testing.T) {
352349
t.Parallel()
353-
calculatorMutex.Lock()
354-
defer calculatorMutex.Unlock()
355-
managerMutex.Lock()
356-
defer managerMutex.Unlock()
357-
reclaimMutex.Lock()
358-
defer reclaimMutex.Unlock()
350+
mockeyMutex.Lock()
351+
defer mockeyMutex.Unlock()
359352

360353
defer mockey.UnPatchAll()
361354

@@ -430,8 +423,8 @@ func TestUserWatermarkReclaimer_ReclaimSuccess(t *testing.T) {
430423

431424
func TestUserWatermarkReclaimer_ReclaimGetStatsFailed(t *testing.T) {
432425
t.Parallel()
433-
reclaimMutex.Lock()
434-
defer reclaimMutex.Unlock()
426+
mockeyMutex.Lock()
427+
defer mockeyMutex.Unlock()
435428

436429
defer mockey.UnPatchAll()
437430

0 commit comments

Comments
 (0)