mirror of
https://github.com/caddyserver/caddy.git
synced 2025-02-02 22:27:10 +01:00
fixed test failure.
When CPU is 1 core, expected value (int(0.5 * float32(maxCPU))) is zero. But runtime.GOMAXPROCS(-1) returns always 1.
This commit is contained in:
parent
fc6afe2a8b
commit
91ac2c58fa
1 changed files with 5 additions and 1 deletions
|
@ -8,6 +8,10 @@ import (
|
||||||
func TestSetCPU(t *testing.T) {
|
func TestSetCPU(t *testing.T) {
|
||||||
currentCPU := runtime.GOMAXPROCS(-1)
|
currentCPU := runtime.GOMAXPROCS(-1)
|
||||||
maxCPU := runtime.NumCPU()
|
maxCPU := runtime.NumCPU()
|
||||||
|
halfCPU := int(0.5 * float32(maxCPU))
|
||||||
|
if halfCPU < 1 {
|
||||||
|
halfCPU = 1
|
||||||
|
}
|
||||||
for i, test := range []struct {
|
for i, test := range []struct {
|
||||||
input string
|
input string
|
||||||
output int
|
output int
|
||||||
|
@ -17,7 +21,7 @@ func TestSetCPU(t *testing.T) {
|
||||||
{"-1", currentCPU, true},
|
{"-1", currentCPU, true},
|
||||||
{"0", currentCPU, true},
|
{"0", currentCPU, true},
|
||||||
{"100%", maxCPU, false},
|
{"100%", maxCPU, false},
|
||||||
{"50%", int(0.5 * float32(maxCPU)), false},
|
{"50%", halfCPU, false},
|
||||||
{"110%", currentCPU, true},
|
{"110%", currentCPU, true},
|
||||||
{"-10%", currentCPU, true},
|
{"-10%", currentCPU, true},
|
||||||
{"invalid input", currentCPU, true},
|
{"invalid input", currentCPU, true},
|
||||||
|
|
Loading…
Reference in a new issue