mirror of https://github.com/docker/docs.git
Merge pull request #258 from jhamrick/test-binpacking
Add test that fails to execute the proper binpacking strategy
This commit is contained in:
commit
3668d7694a
|
|
@ -41,10 +41,9 @@ func (p *BinPackingPlacementStrategy) PlaceContainer(config *dockerclient.Contai
|
|||
if config.Memory > 0 {
|
||||
memoryScore = (node.ReservedMemory() + config.Memory) * 100 / nodeMemory
|
||||
}
|
||||
var total = ((cpuScore + memoryScore) / 200) * 100
|
||||
|
||||
if cpuScore <= 100 && memoryScore <= 100 {
|
||||
scores = append(scores, &score{node: node, score: total})
|
||||
scores = append(scores, &score{node: node, score: cpuScore + memoryScore})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -226,3 +226,36 @@ func TestPlaceContainerDemo(t *testing.T) {
|
|||
assert.Equal(t, node2.ID, node2bis.ID, "")
|
||||
assert.Equal(t, len(node2.Containers()), len(node2bis.Containers()), "")
|
||||
}
|
||||
|
||||
func TestComplexPlacement(t *testing.T) {
|
||||
s := &BinPackingPlacementStrategy{}
|
||||
|
||||
nodes := []*cluster.Node{}
|
||||
for i := 0; i < 2; i++ {
|
||||
nodes = append(nodes, createNode(fmt.Sprintf("node-%d", i), 4, 4))
|
||||
}
|
||||
|
||||
// add one container 2G
|
||||
config := createConfig(2, 0)
|
||||
node1, err := s.PlaceContainer(config, nodes)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, node1.AddContainer(createContainer("c1", config)))
|
||||
|
||||
// add one container 3G
|
||||
config = createConfig(3, 0)
|
||||
node2, err := s.PlaceContainer(config, nodes)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, node2.AddContainer(createContainer("c2", config)))
|
||||
|
||||
// check that they end up on separate nodes
|
||||
assert.NotEqual(t, node1.ID, node2.ID)
|
||||
|
||||
// add one container 1G
|
||||
config = createConfig(1, 0)
|
||||
node3, err := s.PlaceContainer(config, nodes)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, node3.AddContainer(createContainer("c3", config)))
|
||||
|
||||
// check that it ends up on the same node as the 3G
|
||||
assert.Equal(t, node2.ID, node3.ID)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue