Deflake PostFilter integration test

This commit is contained in:
Wei Huang 2020-10-22 13:48:50 -07:00
parent ededd08ba1
commit 6e7b20543c
No known key found for this signature in database
GPG Key ID: BE5E9752F8B6E005

View File

@ -56,7 +56,7 @@ type ScoreWithNormalizePlugin struct {
} }
type FilterPlugin struct { type FilterPlugin struct {
numFilterCalled int numFilterCalled int32
failFilter bool failFilter bool
rejectFilter bool rejectFilter bool
} }
@ -230,7 +230,7 @@ func (fp *FilterPlugin) reset() {
// Filter is a test function that returns an error or nil, depending on the // Filter is a test function that returns an error or nil, depending on the
// value of "failFilter". // value of "failFilter".
func (fp *FilterPlugin) Filter(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status { func (fp *FilterPlugin) Filter(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
fp.numFilterCalled++ atomic.AddInt32(&fp.numFilterCalled, 1)
if fp.failFilter { if fp.failFilter {
return framework.NewStatus(framework.Error, fmt.Sprintf("injecting failure for pod %v", pod.Name)) return framework.NewStatus(framework.Error, fmt.Sprintf("injecting failure for pod %v", pod.Name))
@ -582,25 +582,25 @@ func TestPreFilterPlugin(t *testing.T) {
// TestPostFilterPlugin tests invocation of postfilter plugins. // TestPostFilterPlugin tests invocation of postfilter plugins.
func TestPostFilterPlugin(t *testing.T) { func TestPostFilterPlugin(t *testing.T) {
numNodes := 1 var numNodes int32 = 1
tests := []struct { tests := []struct {
name string name string
numNodes int numNodes int32
rejectFilter bool rejectFilter bool
failScore bool failScore bool
rejectPostFilter bool rejectPostFilter bool
expectFilterNumCalled int expectFilterNumCalled int32
expectScoreNumCalled int32 expectScoreNumCalled int32
expectPostFilterNumCalled int expectPostFilterNumCalled int
}{ }{
{ {
name: "Filter passed and Score success", name: "Filter passed and Score success",
numNodes: 3, numNodes: 30,
rejectFilter: false, rejectFilter: false,
failScore: false, failScore: false,
rejectPostFilter: false, rejectPostFilter: false,
expectFilterNumCalled: 3, expectFilterNumCalled: 30,
expectScoreNumCalled: 3, expectScoreNumCalled: 30,
expectPostFilterNumCalled: 0, expectPostFilterNumCalled: 0,
}, },
{ {
@ -688,7 +688,7 @@ func TestPostFilterPlugin(t *testing.T) {
testCtx := initTestSchedulerForFrameworkTest( testCtx := initTestSchedulerForFrameworkTest(
t, t,
testutils.InitTestMaster(t, fmt.Sprintf("postfilter%v-", i), nil), testutils.InitTestMaster(t, fmt.Sprintf("postfilter%v-", i), nil),
tt.numNodes, int(tt.numNodes),
scheduler.WithProfiles(prof), scheduler.WithProfiles(prof),
scheduler.WithFrameworkOutOfTreeRegistry(registry), scheduler.WithFrameworkOutOfTreeRegistry(registry),
) )
@ -705,8 +705,8 @@ func TestPostFilterPlugin(t *testing.T) {
t.Errorf("Didn't expect the pod to be scheduled.") t.Errorf("Didn't expect the pod to be scheduled.")
} }
if filterPlugin.numFilterCalled < tt.expectFilterNumCalled { if numFilterCalled := atomic.LoadInt32(&filterPlugin.numFilterCalled); numFilterCalled < tt.expectFilterNumCalled {
t.Errorf("Expected the filter plugin to be called at least %v times, but got %v.", tt.expectFilterNumCalled, filterPlugin.numFilterCalled) t.Errorf("Expected the filter plugin to be called at least %v times, but got %v.", tt.expectFilterNumCalled, numFilterCalled)
} }
if numScoreCalled := atomic.LoadInt32(&scorePlugin.numScoreCalled); numScoreCalled < tt.expectScoreNumCalled { if numScoreCalled := atomic.LoadInt32(&scorePlugin.numScoreCalled); numScoreCalled < tt.expectScoreNumCalled {
t.Errorf("Expected the score plugin to be called at least %v times, but got %v.", tt.expectScoreNumCalled, numScoreCalled) 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) {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err) t.Errorf("Expected the pod to be scheduled. error: %v", err)
} }
if filterPlugin.numFilterCalled != tt.expectFilterNumCalled { if numFilterCalled := atomic.LoadInt32(&filterPlugin.numFilterCalled); numFilterCalled != tt.expectFilterNumCalled {
t.Errorf("Expected the filter plugin to be called %v times, but got %v.", tt.expectFilterNumCalled, filterPlugin.numFilterCalled) t.Errorf("Expected the filter plugin to be called %v times, but got %v.", tt.expectFilterNumCalled, numFilterCalled)
} }
if numScoreCalled := atomic.LoadInt32(&scorePlugin.numScoreCalled); numScoreCalled != tt.expectScoreNumCalled { if numScoreCalled := atomic.LoadInt32(&scorePlugin.numScoreCalled); numScoreCalled != tt.expectScoreNumCalled {
t.Errorf("Expected the score plugin to be called %v times, but got %v.", tt.expectScoreNumCalled, numScoreCalled) t.Errorf("Expected the score plugin to be called %v times, but got %v.", tt.expectScoreNumCalled, numScoreCalled)