forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
57 lines (52 loc) · 1.15 KB
/
utils_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package utils
import (
"fmt"
"runtime"
"testing"
)
func TestAdjustGoMaxProcs(t *testing.T) {
// Test default settings
curr := runtime.GOMAXPROCS(-1)
numCPUs := runtime.NumCPU()
// This func both checks for an error of AdjustGoMaxProcs, plus
// ensures that the value it sets is the one that is expected
checker := func(setting, expected int) error {
if err := AdjustGoMaxProcs(setting); err != nil {
return err
}
if i := runtime.GOMAXPROCS(expected); i != expected {
return fmt.Errorf("expected %d, got %d", expected, i)
}
return nil
}
tester := []struct {
Setting int
Expected int
}{
{
// Test setting to current runtime val
Setting: curr,
Expected: curr,
},
{
// Test setting to num of logical CPUs
Setting: numCPUs,
Expected: numCPUs,
},
{
// Test crazy value and make sure it defaults to numCPUs
Setting: 1000,
Expected: numCPUs,
},
{
// Test another crazy value and make sure it defaults to numCPUs
Setting: -1,
Expected: numCPUs,
},
}
for x := range tester {
if err := checker(tester[x].Setting, tester[x].Expected); err != nil {
t.Errorf("%d failed. %s", x, err)
}
}
}