Fix poolmanager sets 0 timeout for function specialization (#1439)

This commit is contained in:
Ta-Ching Chen
2019-11-26 19:22:49 +08:00
committed by GitHub
parent e38baeec36
commit 7e8e968013
7 changed files with 229 additions and 111 deletions
+73 -49
View File
@@ -29,37 +29,40 @@ import (
func TestGetInvokeStrategy(t *testing.T) {
cases := []struct {
name string
testArgs map[string]interface{}
existingInvokeStrategy *fv1.InvokeStrategy
expectedResult *fv1.InvokeStrategy
expectError bool
}{
{
// case: use default executor poolmgr
name: "use default executor poolmgr",
testArgs: map[string]interface{}{},
existingInvokeStrategy: nil,
expectedResult: &fv1.InvokeStrategy{
StrategyType: fv1.StrategyTypeExecution,
ExecutionStrategy: fv1.ExecutionStrategy{
ExecutorType: fv1.ExecutorTypePoolmgr,
ExecutorType: fv1.ExecutorTypePoolmgr,
SpecializationTimeout: 120,
},
},
expectError: false,
},
{
// case: executor type set to poolmgr
name: "executor type set to poolmgr",
testArgs: map[string]interface{}{flagkey.FnExecutorType: string(fv1.ExecutorTypePoolmgr)},
existingInvokeStrategy: nil,
expectedResult: &fv1.InvokeStrategy{
StrategyType: fv1.StrategyTypeExecution,
ExecutionStrategy: fv1.ExecutionStrategy{
ExecutorType: fv1.ExecutorTypePoolmgr,
ExecutorType: fv1.ExecutorTypePoolmgr,
SpecializationTimeout: 120,
},
},
expectError: false,
},
{
// case: executor type set to newdeploy
name: "executor type set to newdeploy",
testArgs: map[string]interface{}{flagkey.FnExecutorType: string(fv1.ExecutorTypeNewdeploy)},
existingInvokeStrategy: nil,
expectedResult: &fv1.InvokeStrategy{
@@ -75,7 +78,7 @@ func TestGetInvokeStrategy(t *testing.T) {
expectError: false,
},
{
// case: executor type change from poolmgr to newdeploy
name: "executor type change from poolmgr to newdeploy",
testArgs: map[string]interface{}{flagkey.FnExecutorType: string(fv1.ExecutorTypeNewdeploy)},
existingInvokeStrategy: &fv1.InvokeStrategy{
StrategyType: fv1.StrategyTypeExecution,
@@ -96,7 +99,7 @@ func TestGetInvokeStrategy(t *testing.T) {
expectError: false,
},
{
// case: executor type change from newdeploy to poolmgr
name: "executor type change from newdeploy to poolmgr",
testArgs: map[string]interface{}{flagkey.FnExecutorType: string(fv1.ExecutorTypePoolmgr)},
existingInvokeStrategy: &fv1.InvokeStrategy{
StrategyType: fv1.StrategyTypeExecution,
@@ -111,13 +114,14 @@ func TestGetInvokeStrategy(t *testing.T) {
expectedResult: &fv1.InvokeStrategy{
StrategyType: fv1.StrategyTypeExecution,
ExecutionStrategy: fv1.ExecutionStrategy{
ExecutorType: fv1.ExecutorTypePoolmgr,
ExecutorType: fv1.ExecutorTypePoolmgr,
SpecializationTimeout: fv1.DefaultSpecializationTimeOut,
},
},
expectError: false,
},
{
// case: minscale < maxscale
name: "minscale < maxscale",
testArgs: map[string]interface{}{
flagkey.FnExecutorType: string(fv1.ExecutorTypeNewdeploy),
flagkey.ReplicasMinscale: 2,
@@ -137,7 +141,7 @@ func TestGetInvokeStrategy(t *testing.T) {
expectError: false,
},
{
// case: minscale > maxscale
name: "minscale > maxscale",
testArgs: map[string]interface{}{
flagkey.FnExecutorType: string(fv1.ExecutorTypeNewdeploy),
flagkey.ReplicasMinscale: 5,
@@ -148,17 +152,26 @@ func TestGetInvokeStrategy(t *testing.T) {
expectError: true,
},
{
// case: maxscale not specified
name: "maxscale not specified",
testArgs: map[string]interface{}{
flagkey.FnExecutorType: string(fv1.ExecutorTypeNewdeploy),
flagkey.ReplicasMinscale: 5,
},
existingInvokeStrategy: nil,
expectedResult: nil,
expectError: true,
expectedResult: &fv1.InvokeStrategy{
StrategyType: fv1.StrategyTypeExecution,
ExecutionStrategy: fv1.ExecutionStrategy{
ExecutorType: fv1.ExecutorTypeNewdeploy,
MinScale: 5,
MaxScale: 5,
TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE,
SpecializationTimeout: fv1.DefaultSpecializationTimeOut,
},
},
expectError: false,
},
{
// case: minscale not specified
name: "minscale not specified",
testArgs: map[string]interface{}{
flagkey.FnExecutorType: string(fv1.ExecutorTypeNewdeploy),
flagkey.ReplicasMaxscale: 3,
@@ -177,7 +190,7 @@ func TestGetInvokeStrategy(t *testing.T) {
expectError: false,
},
{
// case: maxscale set to 0
name: "maxscale set to 0",
testArgs: map[string]interface{}{
flagkey.FnExecutorType: string(fv1.ExecutorTypeNewdeploy),
flagkey.ReplicasMaxscale: 0,
@@ -187,7 +200,26 @@ func TestGetInvokeStrategy(t *testing.T) {
expectError: true,
},
{
// case: maxscale set to 9 when existing is 5
name: "update minscale with value larger than existing maxScale",
testArgs: map[string]interface{}{
flagkey.FnExecutorType: string(fv1.ExecutorTypeNewdeploy),
flagkey.ReplicasMinscale: 9,
},
existingInvokeStrategy: &fv1.InvokeStrategy{
StrategyType: fv1.StrategyTypeExecution,
ExecutionStrategy: fv1.ExecutionStrategy{
ExecutorType: fv1.ExecutorTypeNewdeploy,
MinScale: 2,
MaxScale: 5,
TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE,
SpecializationTimeout: fv1.DefaultSpecializationTimeOut,
},
},
expectedResult: nil,
expectError: true,
},
{
name: "maxscale set to 9 when existing is 5",
testArgs: map[string]interface{}{
flagkey.FnExecutorType: string(fv1.ExecutorTypeNewdeploy),
flagkey.ReplicasMaxscale: 9,
@@ -215,7 +247,7 @@ func TestGetInvokeStrategy(t *testing.T) {
expectError: false,
},
{
// case: change nothing for existing strategy
name: "change nothing for existing strategy",
testArgs: map[string]interface{}{
flagkey.FnExecutorType: string(fv1.ExecutorTypeNewdeploy),
},
@@ -242,7 +274,7 @@ func TestGetInvokeStrategy(t *testing.T) {
expectError: false,
},
{
// case: set target cpu percentage
name: "set target cpu percentage",
testArgs: map[string]interface{}{
flagkey.FnExecutorType: string(fv1.ExecutorTypeNewdeploy),
flagkey.RuntimeTargetcpu: 50,
@@ -261,7 +293,7 @@ func TestGetInvokeStrategy(t *testing.T) {
expectError: false,
},
{
// case: change target cpu percentage
name: "change target cpu percentage",
testArgs: map[string]interface{}{
flagkey.FnExecutorType: string(fv1.ExecutorTypeNewdeploy),
flagkey.RuntimeTargetcpu: 20,
@@ -289,7 +321,7 @@ func TestGetInvokeStrategy(t *testing.T) {
expectError: false,
},
{
// case: change specializationtimeout
name: "change specializationtimeout",
testArgs: map[string]interface{}{
flagkey.FnExecutorType: string(fv1.ExecutorTypeNewdeploy),
flagkey.FnSpecializationTimeout: 200,
@@ -316,17 +348,7 @@ func TestGetInvokeStrategy(t *testing.T) {
expectError: false,
},
{
// case: specializationtimeout should not work for poolmgr
testArgs: map[string]interface{}{
flagkey.FnExecutorType: string(fv1.ExecutorTypePoolmgr),
flagkey.FnSpecializationTimeout: 10,
},
existingInvokeStrategy: nil,
expectedResult: nil,
expectError: true,
},
{
// case: specializationtimeout should not be less than 120
name: "specializationtimeout should not be less than 120",
testArgs: map[string]interface{}{
flagkey.FnExecutorType: string(fv1.ExecutorTypeNewdeploy),
flagkey.FnSpecializationTimeout: 90,
@@ -337,25 +359,27 @@ func TestGetInvokeStrategy(t *testing.T) {
},
}
for i, c := range cases {
fmt.Printf("=== Test Case %v ===\n", i)
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
flags := dummy.TestFlagSet()
flags := dummy.TestFlagSet()
for k, v := range c.testArgs {
flags.Set(k, v)
}
strategy, err := getInvokeStrategy(flags, c.existingInvokeStrategy)
if c.expectError {
assert.NotNil(t, err)
if err != nil {
fmt.Println(err)
for k, v := range c.testArgs {
flags.Set(k, v)
}
} else {
assert.Nil(t, err)
assert.NoError(t, strategy.Validate(), fmt.Sprintf("Failed at test case %v", i))
assert.Equal(t, *c.expectedResult, *strategy)
}
strategy, err := getInvokeStrategy(flags, c.existingInvokeStrategy)
if c.expectError {
assert.NotNil(t, err)
if err != nil {
fmt.Println(err)
}
} else {
assert.Nil(t, err)
if err == nil {
assert.NoError(t, strategy.Validate())
assert.Equal(t, *c.expectedResult, *strategy)
}
}
})
}
}