Fix a racing issue in FakeFilterPlugin

Filter() is called simultaneously, so the member of its (fake) implementation
cannot be written without lock.

The issue can be triggered by:

go test k8s.io/kubernetes/pkg/scheduler/core --race --count=50
This commit is contained in:
Wei Huang 2019-08-07 10:33:44 -07:00
parent 82a981fc39
commit b6b2838a95
No known key found for this signature in database
GPG Key ID: BE5E9752F8B6E005

View File

@ -22,6 +22,7 @@ import (
"reflect"
"strconv"
"strings"
"sync/atomic"
"testing"
"time"
@ -142,7 +143,7 @@ var emptyFramework, _ = framework.NewFramework(EmptyPluginRegistry, nil, []sched
// FakeFilterPlugin is a test filter plugin used by default scheduler.
type FakeFilterPlugin struct {
numFilterCalled int
numFilterCalled int32
failFilter bool
}
@ -162,7 +163,7 @@ func (fp *FakeFilterPlugin) reset() {
// Filter is a test function that returns an error or nil, depending on the
// value of "failFilter".
func (fp *FakeFilterPlugin) Filter(pc *framework.PluginContext, pod *v1.Pod, nodeName string) *framework.Status {
fp.numFilterCalled++
atomic.AddInt32(&fp.numFilterCalled, 1)
if fp.failFilter {
return framework.NewStatus(framework.Unschedulable, fmt.Sprintf("injecting failure for pod %v", pod.Name))
@ -171,7 +172,7 @@ func (fp *FakeFilterPlugin) Filter(pc *framework.PluginContext, pod *v1.Pod, nod
return nil
}
// NewFilterPlugin is the factory for filtler plugin.
// NewFilterPlugin is the factory for filter plugin.
func NewFilterPlugin(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
return filterPlugin, nil
}