e0af23dc |
// +build !windows |
ed39fbeb |
|
e0af23dc |
package daemon |
ed39fbeb |
import ( |
e0af23dc |
"io/ioutil"
"os" |
ed39fbeb |
"testing"
|
907407d0 |
"github.com/docker/engine-api/types/container" |
ed39fbeb |
)
|
e0af23dc |
func TestAdjustCPUShares(t *testing.T) {
tmp, err := ioutil.TempDir("", "docker-daemon-unix-test-")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmp)
daemon := &Daemon{
repository: tmp,
root: tmp,
}
|
7ac4232e |
hostConfig := &container.HostConfig{
Resources: container.Resources{CPUShares: linuxMinCPUShares - 1}, |
ed39fbeb |
} |
e0af23dc |
daemon.adaptContainerSettings(hostConfig, true) |
351f6b8e |
if hostConfig.CPUShares != linuxMinCPUShares {
t.Errorf("Expected CPUShares to be %d", linuxMinCPUShares) |
ed39fbeb |
}
|
351f6b8e |
hostConfig.CPUShares = linuxMaxCPUShares + 1 |
e0af23dc |
daemon.adaptContainerSettings(hostConfig, true) |
351f6b8e |
if hostConfig.CPUShares != linuxMaxCPUShares {
t.Errorf("Expected CPUShares to be %d", linuxMaxCPUShares) |
ed39fbeb |
}
|
5170a2c0 |
hostConfig.CPUShares = 0 |
e0af23dc |
daemon.adaptContainerSettings(hostConfig, true) |
5170a2c0 |
if hostConfig.CPUShares != 0 { |
351f6b8e |
t.Error("Expected CPUShares to be unchanged") |
ed39fbeb |
}
|
5170a2c0 |
hostConfig.CPUShares = 1024 |
e0af23dc |
daemon.adaptContainerSettings(hostConfig, true) |
5170a2c0 |
if hostConfig.CPUShares != 1024 { |
351f6b8e |
t.Error("Expected CPUShares to be unchanged") |
ed39fbeb |
}
}
|
351f6b8e |
func TestAdjustCPUSharesNoAdjustment(t *testing.T) { |
e0af23dc |
tmp, err := ioutil.TempDir("", "docker-daemon-unix-test-")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmp)
daemon := &Daemon{
repository: tmp,
root: tmp,
}
|
7ac4232e |
hostConfig := &container.HostConfig{
Resources: container.Resources{CPUShares: linuxMinCPUShares - 1}, |
ed39fbeb |
} |
e0af23dc |
daemon.adaptContainerSettings(hostConfig, false) |
351f6b8e |
if hostConfig.CPUShares != linuxMinCPUShares-1 {
t.Errorf("Expected CPUShares to be %d", linuxMinCPUShares-1) |
ed39fbeb |
}
|
351f6b8e |
hostConfig.CPUShares = linuxMaxCPUShares + 1 |
e0af23dc |
daemon.adaptContainerSettings(hostConfig, false) |
351f6b8e |
if hostConfig.CPUShares != linuxMaxCPUShares+1 {
t.Errorf("Expected CPUShares to be %d", linuxMaxCPUShares+1) |
ed39fbeb |
}
|
5170a2c0 |
hostConfig.CPUShares = 0 |
e0af23dc |
daemon.adaptContainerSettings(hostConfig, false) |
5170a2c0 |
if hostConfig.CPUShares != 0 { |
351f6b8e |
t.Error("Expected CPUShares to be unchanged") |
ed39fbeb |
}
|
5170a2c0 |
hostConfig.CPUShares = 1024 |
e0af23dc |
daemon.adaptContainerSettings(hostConfig, false) |
5170a2c0 |
if hostConfig.CPUShares != 1024 { |
351f6b8e |
t.Error("Expected CPUShares to be unchanged") |
ed39fbeb |
}
} |