Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy paththreads_test.go
More file actions
Latest commit
59 lines (54 loc) · 1.37 KB
/
Copy paththreads_test.go
File metadata and controls
59 lines (54 loc) · 1.37 KB
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
58
59
package devstatscode
import (
"fmt"
"os"
"testing"
lib "github.com/cncf/devstatscode"
)
funcTestGetThreadsNum(t*testing.T) {
// Environment context parse
varctx lib.Ctx
ctx.Init()
ctx.TestMode=true
// Get actual number of threads available
nThreads:=lib.GetThreadsNum(&ctx)
// Set context's ST/NCPUs manually (don't need to repeat tests from context_test.go)
vartestCases= []struct {
STbool
NCPUsint
expectedint
}{
{ST: false, NCPUs: 0, expected: nThreads},
{ST: false, NCPUs: 1, expected: 1},
{ST: false, NCPUs: -1, expected: nThreads},
{ST: false, NCPUs: 2, expected: 2},
{ST: true, NCPUs: 0, expected: 1},
{ST: true, NCPUs: 1, expected: 1},
{ST: true, NCPUs: -1, expected: 1},
{ST: true, NCPUs: 2, expected: 2},
{ST: true, NCPUs: nThreads+1, expected: nThreads},
}
// Execute test cases
forindex, test:=rangetestCases {
ctx.ST=test.ST
ctx.NCPUs=test.NCPUs
expected:=test.expected
iftest.ST {
os.Setenv("GHA2DB_ST", "1")
} else {
os.Unsetenv("GHA2DB_ST")
}
iftest.NCPUs>0 {
os.Setenv("GHA2DB_NCPUS", fmt.Sprintf("%d", test.NCPUs))
} else {
os.Unsetenv("GHA2DB_NCPUS")
}
got:=lib.GetThreadsNum(&ctx)
ifgot!=expected {
t.Errorf(
"test number %d, expected to return %d threads, got %d (default is %d on this machine)",
index+1, expected, got, nThreads,
)
}
}
}