Skip to content

Commit 6e7b205

Browse files
committed
Deflake PostFilter integration test
1 parent ededd08 commit 6e7b205

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

test/integration/scheduler/framework_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type ScoreWithNormalizePlugin struct {
5656
}
5757

5858
type FilterPlugin struct {
59-
numFilterCalled int
59+
numFilterCalled int32
6060
failFilter bool
6161
rejectFilter bool
6262
}
@@ -230,7 +230,7 @@ func (fp *FilterPlugin) reset() {
230230
// Filter is a test function that returns an error or nil, depending on the
231231
// value of "failFilter".
232232
func (fp *FilterPlugin) Filter(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
233-
fp.numFilterCalled++
233+
atomic.AddInt32(&fp.numFilterCalled, 1)
234234

235235
if fp.failFilter {
236236
return framework.NewStatus(framework.Error, fmt.Sprintf("injecting failure for pod %v", pod.Name))
@@ -582,25 +582,25 @@ func TestPreFilterPlugin(t *testing.T) {
582582

583583
// TestPostFilterPlugin tests invocation of postfilter plugins.
584584
func TestPostFilterPlugin(t *testing.T) {
585-
numNodes := 1
585+
var numNodes int32 = 1
586586
tests := []struct {
587587
name string
588-
numNodes int
588+
numNodes int32
589589
rejectFilter bool
590590
failScore bool
591591
rejectPostFilter bool
592-
expectFilterNumCalled int
592+
expectFilterNumCalled int32
593593
expectScoreNumCalled int32
594594
expectPostFilterNumCalled int
595595
}{
596596
{
597597
name: "Filter passed and Score success",
598-
numNodes: 3,
598+
numNodes: 30,
599599
rejectFilter: false,
600600
failScore: false,
601601
rejectPostFilter: false,
602-
expectFilterNumCalled: 3,
603-
expectScoreNumCalled: 3,
602+
expectFilterNumCalled: 30,
603+
expectScoreNumCalled: 30,
604604
expectPostFilterNumCalled: 0,
605605
},
606606
{
@@ -688,7 +688,7 @@ func TestPostFilterPlugin(t *testing.T) {
688688
testCtx := initTestSchedulerForFrameworkTest(
689689
t,
690690
testutils.InitTestMaster(t, fmt.Sprintf("postfilter%v-", i), nil),
691-
tt.numNodes,
691+
int(tt.numNodes),
692692
scheduler.WithProfiles(prof),
693693
scheduler.WithFrameworkOutOfTreeRegistry(registry),
694694
)
@@ -705,8 +705,8 @@ func TestPostFilterPlugin(t *testing.T) {
705705
t.Errorf("Didn't expect the pod to be scheduled.")
706706
}
707707

708-
if filterPlugin.numFilterCalled < tt.expectFilterNumCalled {
709-
t.Errorf("Expected the filter plugin to be called at least %v times, but got %v.", tt.expectFilterNumCalled, filterPlugin.numFilterCalled)
708+
if numFilterCalled := atomic.LoadInt32(&filterPlugin.numFilterCalled); numFilterCalled < tt.expectFilterNumCalled {
709+
t.Errorf("Expected the filter plugin to be called at least %v times, but got %v.", tt.expectFilterNumCalled, numFilterCalled)
710710
}
711711
if numScoreCalled := atomic.LoadInt32(&scorePlugin.numScoreCalled); numScoreCalled < tt.expectScoreNumCalled {
712712
t.Errorf("Expected the score plugin to be called at least %v times, but got %v.", tt.expectScoreNumCalled, numScoreCalled)
@@ -718,8 +718,8 @@ func TestPostFilterPlugin(t *testing.T) {
718718
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
719719
t.Errorf("Expected the pod to be scheduled. error: %v", err)
720720
}
721-
if filterPlugin.numFilterCalled != tt.expectFilterNumCalled {
722-
t.Errorf("Expected the filter plugin to be called %v times, but got %v.", tt.expectFilterNumCalled, filterPlugin.numFilterCalled)
721+
if numFilterCalled := atomic.LoadInt32(&filterPlugin.numFilterCalled); numFilterCalled != tt.expectFilterNumCalled {
722+
t.Errorf("Expected the filter plugin to be called %v times, but got %v.", tt.expectFilterNumCalled, numFilterCalled)
723723
}
724724
if numScoreCalled := atomic.LoadInt32(&scorePlugin.numScoreCalled); numScoreCalled != tt.expectScoreNumCalled {
725725
t.Errorf("Expected the score plugin to be called %v times, but got %v.", tt.expectScoreNumCalled, numScoreCalled)

0 commit comments

Comments
 (0)