Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ut for scheduler framework #85188

Merged
merged 1 commit into from Nov 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
155 changes: 155 additions & 0 deletions pkg/scheduler/framework/v1alpha1/framework_test.go
Expand Up @@ -585,6 +585,161 @@ func TestPreFilterPlugins(t *testing.T) {

}

func TestFilterPlugins(t *testing.T) {
charleszheng44 marked this conversation as resolved.
Show resolved Hide resolved
tests := []struct {
name string
plugins []*TestPlugin
wantCode Code
}{
{
name: "SuccessFilter",
plugins: []*TestPlugin{
{
name: "TestPlugin",
inj: injectedResult{FilterStatus: int(Success)},
},
},
wantCode: Success,
},
{
name: "ErrorFilter",
plugins: []*TestPlugin{
{
name: "TestPlugin",
inj: injectedResult{FilterStatus: int(Error)},
},
},
wantCode: Error,
},
{
name: "UnschedulableFilter",
plugins: []*TestPlugin{
{
name: "TestPlugin",
inj: injectedResult{FilterStatus: int(Unschedulable)},
},
},
wantCode: Unschedulable,
},
{
name: "UnschedulableAndUnresolvableFilter",
plugins: []*TestPlugin{
{
name: "TestPlugin",
inj: injectedResult{
FilterStatus: int(UnschedulableAndUnresolvable)},
},
},
wantCode: UnschedulableAndUnresolvable,
},
// followings tests cover multiple-plugins scenarios
{
name: "ErrorAndErrorFilters",
plugins: []*TestPlugin{
{
name: "TestPlugin1",
inj: injectedResult{FilterStatus: int(Error)},
},

{
name: "TestPlugin2",
inj: injectedResult{FilterStatus: int(Error)},
},
},
wantCode: Error,
},
{
name: "SuccessAndSuccessFilters",
plugins: []*TestPlugin{
{
name: "TestPlugin1",
inj: injectedResult{FilterStatus: int(Success)},
},

{
name: "TestPlugin2",
inj: injectedResult{FilterStatus: int(Success)},
},
},
wantCode: Success,
},
{
name: "ErrorAndSuccessFilters",
plugins: []*TestPlugin{
{
name: "TestPlugin1",
inj: injectedResult{FilterStatus: int(Error)},
},
{
name: "TestPlugin2",
inj: injectedResult{FilterStatus: int(Success)},
},
},
wantCode: Error,
},
{
name: "SuccessAndErrorFilters",
plugins: []*TestPlugin{
{

name: "TestPlugin1",
inj: injectedResult{FilterStatus: int(Success)},
},
{
name: "TestPlugin2",
inj: injectedResult{FilterStatus: int(Error)},
},
},
wantCode: Error,
},
{
name: "SuccessAndUnschedulableFilters",
plugins: []*TestPlugin{
{
name: "TestPlugin1",
inj: injectedResult{FilterStatus: int(Success)},
},

{
name: "TestPlugin2",
inj: injectedResult{FilterStatus: int(Unschedulable)},
},
},
wantCode: Unschedulable,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
registry := Registry{}
cfgPls := &config.Plugins{Filter: &config.PluginSet{}}
for _, pl := range tt.plugins {
// register all plugins
tmpPl := pl
if err := registry.Register(pl.name,
func(_ *runtime.Unknown, _ FrameworkHandle) (Plugin, error) {
return tmpPl, nil
}); err != nil {
t.Fatalf("fail to register filter plugin (%s)", pl.name)
}
// append plugins to filter pluginset
cfgPls.Filter.Enabled = append(
cfgPls.Filter.Enabled,
config.Plugin{Name: pl.name})
}

f, err := NewFramework(registry, cfgPls, emptyArgs)
if err != nil {
t.Fatalf("fail to create framework: %s", err)
}
status := f.RunFilterPlugins(context.TODO(), nil, pod, nil)
if status.Code() != tt.wantCode {
t.Errorf("Wrong status code. got: %v, want:%v", status.Code(), tt.wantCode)
}
})
}
}

func TestRecordingMetrics(t *testing.T) {
tests := []struct {
name string
Expand Down