Skip to content

Commit 2cee28e

Browse files
committed
pass test
1 parent 6c2ac67 commit 2cee28e

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

strategy/fill_global.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/projecteru2/core/types"
66
)
77

8+
// FillGlobalPlan try fill strategy and fallback to global strategy
89
func FillGlobalPlan(strategyInfo []Info, need, total, limit int, resourceType types.ResourceType) (map[string]int, error) {
910
originStrategyInfo := make([]Info, len(strategyInfo))
1011
copy(originStrategyInfo, strategyInfo)
@@ -13,6 +14,6 @@ func FillGlobalPlan(strategyInfo []Info, need, total, limit int, resourceType ty
1314
if err == nil {
1415
return deployMap, nil
1516
}
16-
log.Info("[FillGlobalPlan] fill plan failed, try global fill: %+v", err)
17+
log.Infof("[FillGlobalPlan] fill plan failed, try global fill: %+v", err)
1718
return GlobalPlan(originStrategyInfo, need, total, limit, resourceType)
1819
}

strategy/fillglobal_test.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package strategy
2+
3+
import (
4+
"testing"
5+
6+
"github.com/projecteru2/core/types"
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestFillGlobalPlan(t *testing.T) {
11+
// can fill
12+
strategyInfos := []Info{
13+
{
14+
Nodename: "n1",
15+
Capacity: 10,
16+
Count: 1,
17+
},
18+
{
19+
Nodename: "n2",
20+
Capacity: 10,
21+
Count: 0,
22+
},
23+
}
24+
deployMap, err := FillPlan(strategyInfos, 1, 2, 1, types.ResourceAll)
25+
assert.Nil(t, err)
26+
assert.EqualValues(t, 0, deployMap["n1"])
27+
assert.EqualValues(t, 1, deployMap["n2"])
28+
deployMap, err = FillGlobalPlan(strategyInfos, 1, 2, 1, types.ResourceAll)
29+
assert.Nil(t, err)
30+
assert.EqualValues(t, 0, deployMap["n1"])
31+
assert.EqualValues(t, 1, deployMap["n2"])
32+
33+
// can't fill
34+
strategyInfos = []Info{
35+
{
36+
Nodename: "n1",
37+
Capacity: 10,
38+
Count: 1,
39+
Usages: map[types.ResourceType]float64{types.ResourceAll: 0.1},
40+
Rates: map[types.ResourceType]float64{types.ResourceAll: 0.1},
41+
},
42+
}
43+
_, err = FillPlan(strategyInfos, 1, 2, 1, types.ResourceAll)
44+
assert.EqualError(t, err, "Cannot alloc a fill node plan, each node has enough workloads")
45+
deployMap, err = FillGlobalPlan(strategyInfos, 1, 2, 1, types.ResourceAll)
46+
assert.Nil(t, err)
47+
assert.EqualValues(t, 1, deployMap["n1"])
48+
}

strategy/strategy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const (
1818
Each = "EACH"
1919
// Global .
2020
Global = "GLOBAL"
21-
// Fill + Global
21+
// FillGlobal .
2222
FillGlobal = "FILLGLOBAL"
2323
// Dummy for calculate capacity
2424
Dummy = "DUMMY"

0 commit comments

Comments
 (0)