Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(41)

Delta Between Two Patch Sets: utils/gomaxprocs_test.go

Issue 76120044: cmd/juju/machine: Enable GOMAXPROCS(NumCPU)
Left Patch Set: cmd/juju/machine: Enable GOMAXPROCS(NumCPU) Created 11 years ago
Right Patch Set: cmd/juju/machine: Enable GOMAXPROCS(NumCPU) Created 11 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« utils/gomaxprocs.go ('K') | « utils/gomaxprocs.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2014 Canonical Ltd. 1 // Copyright 2014 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package utils_test 4 package utils_test
5 5
6 import ( 6 import (
7 "os" 7 "os"
8 8
9 gc "launchpad.net/gocheck" 9 gc "launchpad.net/gocheck"
10 10
11 "launchpad.net/juju-core/testing/testbase" 11 "launchpad.net/juju-core/testing/testbase"
12 "launchpad.net/juju-core/utils" 12 "launchpad.net/juju-core/utils"
13 ) 13 )
14 14
15 type gomaxprocsSuite struct { 15 type gomaxprocsSuite struct {
16 testbase.LoggingSuite 16 testbase.LoggingSuite
17 setmaxprocs chan int 17 setmaxprocs chan int
18 numCPUResponse int 18 numCPUResponse int
19 setMaxProcs int
19 } 20 }
20 21
21 var _ = gc.Suite(&gomaxprocsSuite{}) 22 var _ = gc.Suite(&gomaxprocsSuite{})
22 23
23 func (s *gomaxprocsSuite) SetUpTest(c *gc.C) { 24 func (s *gomaxprocsSuite) SetUpTest(c *gc.C) {
24 s.LoggingSuite.SetUpTest(c) 25 s.LoggingSuite.SetUpTest(c)
25 // always stub out GOMAXPROCS so we don't actually change anything 26 // always stub out GOMAXPROCS so we don't actually change anything
26 s.numCPUResponse = 2 27 s.numCPUResponse = 2
27 » s.setmaxprocs = make(chan int, 1) 28 » s.setMaxProcs = -1
28 » maxprocsfunc := func(n int) int { 29 » maxProcsFunc := func(n int) int {
29 » » c.Logf("sending %d on setmaxprocs", n) 30 » » s.setMaxProcs = n
30 » » s.setmaxprocs <- n
31 return 1 31 return 1
32 } 32 }
33 numCPUFunc := func() int { return s.numCPUResponse } 33 numCPUFunc := func() int { return s.numCPUResponse }
34 » cleanup := utils.OverrideGOMAXPROCSFuncs(maxprocsfunc, numCPUFunc) 34 » s.PatchValue(utils.GOMAXPROCS, maxProcsFunc)
35 » s.AddCleanup(func(c *gc.C) { c.Logf("running cleanup"); cleanup() }) 35 » s.PatchValue(utils.NumCPU, numCPUFunc)
36 s.PatchEnvironment("GOMAXPROCS", "") 36 s.PatchEnvironment("GOMAXPROCS", "")
37 } 37 }
38 38
39 func (s *gomaxprocsSuite) TestUseMultipleCPUsDoesNothingWhenGOMAXPROCSSet(c *gc. C) { 39 func (s *gomaxprocsSuite) TestUseMultipleCPUsDoesNothingWhenGOMAXPROCSSet(c *gc. C) {
40 os.Setenv("GOMAXPROCS", "1") 40 os.Setenv("GOMAXPROCS", "1")
41 utils.UseMultipleCPUs() 41 utils.UseMultipleCPUs()
42 » c.Check(<-s.setmaxprocs, gc.Equals, 0) 42 » c.Check(s.setMaxProcs, gc.Equals, 0)
43 } 43 }
44 44
45 func (s *gomaxprocsSuite) TestUseMultipleCPUsWhenEnabled(c *gc.C) { 45 func (s *gomaxprocsSuite) TestUseMultipleCPUsWhenEnabled(c *gc.C) {
46 utils.UseMultipleCPUs() 46 utils.UseMultipleCPUs()
47 » c.Check(<-s.setmaxprocs, gc.Equals, 2) 47 » c.Check(s.setMaxProcs, gc.Equals, 2)
48 s.numCPUResponse = 4 48 s.numCPUResponse = 4
49 utils.UseMultipleCPUs() 49 utils.UseMultipleCPUs()
50 » c.Check(<-s.setmaxprocs, gc.Equals, 4) 50 » c.Check(s.setMaxProcs, gc.Equals, 4)
51 } 51 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b