2015-06-03 19:01:53 +00:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/pkg/version"
|
|
|
|
"github.com/docker/docker/runconfig"
|
|
|
|
)
|
|
|
|
|
2015-07-21 05:15:44 +00:00
|
|
|
func TestAdjustCPUSharesOldApi(t *testing.T) {
|
2015-06-03 19:01:53 +00:00
|
|
|
apiVersion := version.Version("1.18")
|
|
|
|
hostConfig := &runconfig.HostConfig{
|
2015-07-21 05:15:44 +00:00
|
|
|
CPUShares: linuxMinCPUShares - 1,
|
2015-06-03 19:01:53 +00:00
|
|
|
}
|
2015-07-21 05:15:44 +00:00
|
|
|
adjustCPUShares(apiVersion, hostConfig)
|
|
|
|
if hostConfig.CPUShares != linuxMinCPUShares {
|
|
|
|
t.Errorf("Expected CPUShares to be %d", linuxMinCPUShares)
|
2015-06-03 19:01:53 +00:00
|
|
|
}
|
|
|
|
|
2015-07-21 05:15:44 +00:00
|
|
|
hostConfig.CPUShares = linuxMaxCPUShares + 1
|
|
|
|
adjustCPUShares(apiVersion, hostConfig)
|
|
|
|
if hostConfig.CPUShares != linuxMaxCPUShares {
|
|
|
|
t.Errorf("Expected CPUShares to be %d", linuxMaxCPUShares)
|
2015-06-03 19:01:53 +00:00
|
|
|
}
|
|
|
|
|
2015-07-25 09:11:45 +00:00
|
|
|
hostConfig.CPUShares = 0
|
2015-07-21 05:15:44 +00:00
|
|
|
adjustCPUShares(apiVersion, hostConfig)
|
2015-07-25 09:11:45 +00:00
|
|
|
if hostConfig.CPUShares != 0 {
|
2015-07-21 05:15:44 +00:00
|
|
|
t.Error("Expected CPUShares to be unchanged")
|
2015-06-03 19:01:53 +00:00
|
|
|
}
|
|
|
|
|
2015-07-25 09:11:45 +00:00
|
|
|
hostConfig.CPUShares = 1024
|
2015-07-21 05:15:44 +00:00
|
|
|
adjustCPUShares(apiVersion, hostConfig)
|
2015-07-25 09:11:45 +00:00
|
|
|
if hostConfig.CPUShares != 1024 {
|
2015-07-21 05:15:44 +00:00
|
|
|
t.Error("Expected CPUShares to be unchanged")
|
2015-06-03 19:01:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-21 05:15:44 +00:00
|
|
|
func TestAdjustCPUSharesNoAdjustment(t *testing.T) {
|
2015-06-03 19:01:53 +00:00
|
|
|
apiVersion := version.Version("1.19")
|
|
|
|
hostConfig := &runconfig.HostConfig{
|
2015-07-21 05:15:44 +00:00
|
|
|
CPUShares: linuxMinCPUShares - 1,
|
2015-06-03 19:01:53 +00:00
|
|
|
}
|
2015-07-21 05:15:44 +00:00
|
|
|
adjustCPUShares(apiVersion, hostConfig)
|
|
|
|
if hostConfig.CPUShares != linuxMinCPUShares-1 {
|
|
|
|
t.Errorf("Expected CPUShares to be %d", linuxMinCPUShares-1)
|
2015-06-03 19:01:53 +00:00
|
|
|
}
|
|
|
|
|
2015-07-21 05:15:44 +00:00
|
|
|
hostConfig.CPUShares = linuxMaxCPUShares + 1
|
|
|
|
adjustCPUShares(apiVersion, hostConfig)
|
|
|
|
if hostConfig.CPUShares != linuxMaxCPUShares+1 {
|
|
|
|
t.Errorf("Expected CPUShares to be %d", linuxMaxCPUShares+1)
|
2015-06-03 19:01:53 +00:00
|
|
|
}
|
|
|
|
|
2015-07-25 09:11:45 +00:00
|
|
|
hostConfig.CPUShares = 0
|
2015-07-21 05:15:44 +00:00
|
|
|
adjustCPUShares(apiVersion, hostConfig)
|
2015-07-25 09:11:45 +00:00
|
|
|
if hostConfig.CPUShares != 0 {
|
2015-07-21 05:15:44 +00:00
|
|
|
t.Error("Expected CPUShares to be unchanged")
|
2015-06-03 19:01:53 +00:00
|
|
|
}
|
|
|
|
|
2015-07-25 09:11:45 +00:00
|
|
|
hostConfig.CPUShares = 1024
|
2015-07-21 05:15:44 +00:00
|
|
|
adjustCPUShares(apiVersion, hostConfig)
|
2015-07-25 09:11:45 +00:00
|
|
|
if hostConfig.CPUShares != 1024 {
|
2015-07-21 05:15:44 +00:00
|
|
|
t.Error("Expected CPUShares to be unchanged")
|
2015-06-03 19:01:53 +00:00
|
|
|
}
|
|
|
|
}
|