server_linux_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // +build linux
  2. package server
  3. import (
  4. "testing"
  5. "github.com/docker/docker/pkg/version"
  6. "github.com/docker/docker/runconfig"
  7. )
  8. func TestAdjustCPUSharesOldApi(t *testing.T) {
  9. apiVersion := version.Version("1.18")
  10. hostConfig := &runconfig.HostConfig{
  11. CPUShares: linuxMinCPUShares - 1,
  12. }
  13. adjustCPUShares(apiVersion, hostConfig)
  14. if hostConfig.CPUShares != linuxMinCPUShares {
  15. t.Errorf("Expected CPUShares to be %d", linuxMinCPUShares)
  16. }
  17. hostConfig.CPUShares = linuxMaxCPUShares + 1
  18. adjustCPUShares(apiVersion, hostConfig)
  19. if hostConfig.CPUShares != linuxMaxCPUShares {
  20. t.Errorf("Expected CPUShares to be %d", linuxMaxCPUShares)
  21. }
  22. hostConfig.CPUShares = 0
  23. adjustCPUShares(apiVersion, hostConfig)
  24. if hostConfig.CPUShares != 0 {
  25. t.Error("Expected CPUShares to be unchanged")
  26. }
  27. hostConfig.CPUShares = 1024
  28. adjustCPUShares(apiVersion, hostConfig)
  29. if hostConfig.CPUShares != 1024 {
  30. t.Error("Expected CPUShares to be unchanged")
  31. }
  32. }
  33. func TestAdjustCPUSharesNoAdjustment(t *testing.T) {
  34. apiVersion := version.Version("1.19")
  35. hostConfig := &runconfig.HostConfig{
  36. CPUShares: linuxMinCPUShares - 1,
  37. }
  38. adjustCPUShares(apiVersion, hostConfig)
  39. if hostConfig.CPUShares != linuxMinCPUShares-1 {
  40. t.Errorf("Expected CPUShares to be %d", linuxMinCPUShares-1)
  41. }
  42. hostConfig.CPUShares = linuxMaxCPUShares + 1
  43. adjustCPUShares(apiVersion, hostConfig)
  44. if hostConfig.CPUShares != linuxMaxCPUShares+1 {
  45. t.Errorf("Expected CPUShares to be %d", linuxMaxCPUShares+1)
  46. }
  47. hostConfig.CPUShares = 0
  48. adjustCPUShares(apiVersion, hostConfig)
  49. if hostConfig.CPUShares != 0 {
  50. t.Error("Expected CPUShares to be unchanged")
  51. }
  52. hostConfig.CPUShares = 1024
  53. adjustCPUShares(apiVersion, hostConfig)
  54. if hostConfig.CPUShares != 1024 {
  55. t.Error("Expected CPUShares to be unchanged")
  56. }
  57. }