mirror of https://github.com/docker/docs.git
Add more unit tests for spread strategy
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
05f9a6a6fb
commit
ab113e7750
|
@ -8,6 +8,44 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestSpreadPlaceDifferentNodeSize(t *testing.T) {
|
||||||
|
s := &SpreadPlacementStrategy{}
|
||||||
|
|
||||||
|
nodes := []*node.Node{
|
||||||
|
createNode(fmt.Sprintf("node-0"), 64, 21),
|
||||||
|
createNode(fmt.Sprintf("node-1"), 128, 42),
|
||||||
|
}
|
||||||
|
|
||||||
|
// add 60 containers
|
||||||
|
for i := 0; i < 60; i++ {
|
||||||
|
config := createConfig(0, 0)
|
||||||
|
node := selectTopNode(t, s, config, nodes)
|
||||||
|
assert.NoError(t, node.AddContainer(createContainer(fmt.Sprintf("c%d", i), config)))
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, len(nodes[0].Containers), 30)
|
||||||
|
assert.Equal(t, len(nodes[1].Containers), 30)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSpreadPlaceDifferentNodeSizeCPUs(t *testing.T) {
|
||||||
|
s := &SpreadPlacementStrategy{}
|
||||||
|
|
||||||
|
nodes := []*node.Node{
|
||||||
|
createNode(fmt.Sprintf("node-0"), 64, 21),
|
||||||
|
createNode(fmt.Sprintf("node-1"), 128, 42),
|
||||||
|
}
|
||||||
|
|
||||||
|
// add 60 containers 1CPU
|
||||||
|
for i := 0; i < 60; i++ {
|
||||||
|
config := createConfig(0, 1)
|
||||||
|
node := selectTopNode(t, s, config, nodes)
|
||||||
|
assert.NoError(t, node.AddContainer(createContainer(fmt.Sprintf("c%d", i), config)))
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, len(nodes[0].Containers), 20)
|
||||||
|
assert.Equal(t, len(nodes[1].Containers), 40)
|
||||||
|
}
|
||||||
|
|
||||||
func TestSpreadPlaceEqualWeight(t *testing.T) {
|
func TestSpreadPlaceEqualWeight(t *testing.T) {
|
||||||
s := &SpreadPlacementStrategy{}
|
s := &SpreadPlacementStrategy{}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue