2015-06-03 15:01:53 -04:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/pkg/version"
|
|
|
|
"github.com/docker/docker/runconfig"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAdjustCpuSharesOldApi(t *testing.T) {
|
|
|
|
apiVersion := version.Version("1.18")
|
|
|
|
hostConfig := &runconfig.HostConfig{
|
2015-07-25 05:11:45 -04:00
|
|
|
CPUShares: linuxMinCpuShares - 1,
|
2015-06-03 15:01:53 -04:00
|
|
|
}
|
|
|
|
adjustCpuShares(apiVersion, hostConfig)
|
2015-07-25 05:11:45 -04:00
|
|
|
if hostConfig.CPUShares != linuxMinCpuShares {
|
2015-06-03 15:01:53 -04:00
|
|
|
t.Errorf("Expected CpuShares to be %d", linuxMinCpuShares)
|
|
|
|
}
|
|
|
|
|
2015-07-25 05:11:45 -04:00
|
|
|
hostConfig.CPUShares = linuxMaxCpuShares + 1
|
2015-06-03 15:01:53 -04:00
|
|
|
adjustCpuShares(apiVersion, hostConfig)
|
2015-07-25 05:11:45 -04:00
|
|
|
if hostConfig.CPUShares != linuxMaxCpuShares {
|
2015-06-03 15:01:53 -04:00
|
|
|
t.Errorf("Expected CpuShares to be %d", linuxMaxCpuShares)
|
|
|
|
}
|
|
|
|
|
2015-07-25 05:11:45 -04:00
|
|
|
hostConfig.CPUShares = 0
|
2015-06-03 15:01:53 -04:00
|
|
|
adjustCpuShares(apiVersion, hostConfig)
|
2015-07-25 05:11:45 -04:00
|
|
|
if hostConfig.CPUShares != 0 {
|
2015-06-03 15:01:53 -04:00
|
|
|
t.Error("Expected CpuShares to be unchanged")
|
|
|
|
}
|
|
|
|
|
2015-07-25 05:11:45 -04:00
|
|
|
hostConfig.CPUShares = 1024
|
2015-06-03 15:01:53 -04:00
|
|
|
adjustCpuShares(apiVersion, hostConfig)
|
2015-07-25 05:11:45 -04:00
|
|
|
if hostConfig.CPUShares != 1024 {
|
2015-06-03 15:01:53 -04:00
|
|
|
t.Error("Expected CpuShares to be unchanged")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAdjustCpuSharesNoAdjustment(t *testing.T) {
|
|
|
|
apiVersion := version.Version("1.19")
|
|
|
|
hostConfig := &runconfig.HostConfig{
|
2015-07-25 05:11:45 -04:00
|
|
|
CPUShares: linuxMinCpuShares - 1,
|
2015-06-03 15:01:53 -04:00
|
|
|
}
|
|
|
|
adjustCpuShares(apiVersion, hostConfig)
|
2015-07-25 05:11:45 -04:00
|
|
|
if hostConfig.CPUShares != linuxMinCpuShares-1 {
|
2015-06-03 15:01:53 -04:00
|
|
|
t.Errorf("Expected CpuShares to be %d", linuxMinCpuShares-1)
|
|
|
|
}
|
|
|
|
|
2015-07-25 05:11:45 -04:00
|
|
|
hostConfig.CPUShares = linuxMaxCpuShares + 1
|
2015-06-03 15:01:53 -04:00
|
|
|
adjustCpuShares(apiVersion, hostConfig)
|
2015-07-25 05:11:45 -04:00
|
|
|
if hostConfig.CPUShares != linuxMaxCpuShares+1 {
|
2015-06-03 15:01:53 -04:00
|
|
|
t.Errorf("Expected CpuShares to be %d", linuxMaxCpuShares+1)
|
|
|
|
}
|
|
|
|
|
2015-07-25 05:11:45 -04:00
|
|
|
hostConfig.CPUShares = 0
|
2015-06-03 15:01:53 -04:00
|
|
|
adjustCpuShares(apiVersion, hostConfig)
|
2015-07-25 05:11:45 -04:00
|
|
|
if hostConfig.CPUShares != 0 {
|
2015-06-03 15:01:53 -04:00
|
|
|
t.Error("Expected CpuShares to be unchanged")
|
|
|
|
}
|
|
|
|
|
2015-07-25 05:11:45 -04:00
|
|
|
hostConfig.CPUShares = 1024
|
2015-06-03 15:01:53 -04:00
|
|
|
adjustCpuShares(apiVersion, hostConfig)
|
2015-07-25 05:11:45 -04:00
|
|
|
if hostConfig.CPUShares != 1024 {
|
2015-06-03 15:01:53 -04:00
|
|
|
t.Error("Expected CpuShares to be unchanged")
|
|
|
|
}
|
|
|
|
}
|