-
Notifications
You must be signed in to change notification settings - Fork 89
/
gomaxprocs_test.go
51 lines (42 loc) · 1.18 KB
/
gomaxprocs_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
// Copyright 2014 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package utils_test
import (
"os"
"github.com/juju/testing"
gc "gopkg.in/check.v1"
"github.com/juju/utils/v4"
)
type gomaxprocsSuite struct {
testing.IsolationSuite
setmaxprocs chan int
numCPUResponse int
setMaxProcs int
}
var _ = gc.Suite(&gomaxprocsSuite{})
func (s *gomaxprocsSuite) SetUpTest(c *gc.C) {
s.IsolationSuite.SetUpTest(c)
// always stub out GOMAXPROCS so we don't actually change anything
s.numCPUResponse = 2
s.setMaxProcs = -1
maxProcsFunc := func(n int) int {
s.setMaxProcs = n
return 1
}
numCPUFunc := func() int { return s.numCPUResponse }
s.PatchValue(utils.GOMAXPROCS, maxProcsFunc)
s.PatchValue(utils.NumCPU, numCPUFunc)
s.PatchEnvironment("GOMAXPROCS", "")
}
func (s *gomaxprocsSuite) TestUseMultipleCPUsDoesNothingWhenGOMAXPROCSSet(c *gc.C) {
os.Setenv("GOMAXPROCS", "1")
utils.UseMultipleCPUs()
c.Check(s.setMaxProcs, gc.Equals, 0)
}
func (s *gomaxprocsSuite) TestUseMultipleCPUsWhenEnabled(c *gc.C) {
utils.UseMultipleCPUs()
c.Check(s.setMaxProcs, gc.Equals, 2)
s.numCPUResponse = 4
utils.UseMultipleCPUs()
c.Check(s.setMaxProcs, gc.Equals, 4)
}