// WorkersStarted returns a channel that's closed when
// the top level workers have been started. This is
// provided for testing purposes.
func (a *MachineAgent) WorkersStarted() <-chan struct{}
return a.workersStarted
}
https://codereview.appspot.com/76120044/diff/40001/utils/gomaxprocs.go#newcode11
utils/gomaxprocs.go:11: var gomaxprocs = runtime.GOMAXPROCS
This seems a bit of overkill for such a function with such simple logic.
I'd just test that it does the right thing (even though it's not a full
test on a machine with a single cpu). It'll fail on any machine
with more than one CPU, which seems adequate to me. Is that overly
pragmatic?
https://codereview.appspot.com/76120044/diff/40001/utils/gomaxprocs.go#newcode20
utils/gomaxprocs.go:20: logger.Debugf("GOMAXPROCS already set in
environment to %q, %d internally",
I'm not that keen on utils functions producing log messages (and since
they're only at Debug level, they can't really be that important).
Honestly,
I'd just do:
I like that much better, thanks.
Some further simplification suggestions below.
https:/ /codereview. appspot. com/76120044/ diff/20001/ cmd/jujud/ main.go
File cmd/jujud/main.go (right):
https:/ /codereview. appspot. com/76120044/ diff/20001/ cmd/jujud/ main.go# newcode1 main.go: 1: // Copyright 2012-2014 Canonical Ltd.
cmd/jujud/
I think it's reasonable to leave the copyright dates alone. That's
certainly the explicit convention in Go core, and Juju de facto.
https:/ /codereview. appspot. com/76120044/ diff/40001/ cmd/jujud/ machine. go machine. go (right):
File cmd/jujud/
https:/ /codereview. appspot. com/76120044/ diff/40001/ cmd/jujud/ machine. go#newcode75 machine. go:75: workersStarted chan struct{}
cmd/jujud/
Perhaps some documentation for this might be appropriate, given
that it's only here for tests.
Or a method:
// WorkersStarted returns a channel that's closed when
// the top level workers have been started. This is
// provided for testing purposes.
func (a *MachineAgent) WorkersStarted() <-chan struct{}
return a.workersStarted
}
https:/ /codereview. appspot. com/76120044/ diff/40001/ cmd/jujud/ machine. go#newcode345 machine. go:345: useMultipleCPUs()
cmd/jujud/
If you took logging out of the utils package, you could add a log
message here instead:
logger. Debugf( "GOMAXPROCS set to %d", runtime. GOMAXPROCS( 0))
That's probably sufficient for diagnosing gomaxprocs-related problems.
https:/ /codereview. appspot. com/76120044/ diff/40001/ utils/export_ test.go test.go (right):
File utils/export_
https:/ /codereview. appspot. com/76120044/ diff/40001/ utils/export_ test.go# newcode9 test.go: 9: func OverrideCPUFunc s(maxprocsfunc func(int)
utils/export_
int, numCPUFunc func() int) func() {
Assuming we go with this, I'd do:
var (
GoMaxProcs = &gomaxprocs
NumCPU = &numcpu
)
then we can use PatchValue in the tests.
https:/ /codereview. appspot. com/76120044/ diff/40001/ utils/gomaxproc s.go
File utils/gomaxprocs.go (right):
https:/ /codereview. appspot. com/76120044/ diff/40001/ utils/gomaxproc s.go#newcode11 s.go:11: var gomaxprocs = runtime.GOMAXPROCS
utils/gomaxproc
This seems a bit of overkill for such a function with such simple logic.
I'd just test that it does the right thing (even though it's not a full
test on a machine with a single cpu). It'll fail on any machine
with more than one CPU, which seems adequate to me. Is that overly
pragmatic?
https:/ /codereview. appspot. com/76120044/ diff/40001/ utils/gomaxproc s.go#newcode16 s.go:16: // variable if it is set.
utils/gomaxproc
// UseMultipleCPUs sets GOMAXPROCS to the number of CPU
// cores unless overridden by the GOMAXPROCS environment
// variable.
?
https:/ /codereview. appspot. com/76120044/ diff/40001/ utils/gomaxproc s.go#newcode20 s.go:20: logger. Debugf( "GOMAXPROCS already set in
utils/gomaxproc
environment to %q, %d internally",
I'm not that keen on utils functions producing log messages (and since
they're only at Debug level, they can't really be that important).
Honestly,
I'd just do:
func UseMultipleCPUs() { "GOMAXPROCS" ) == "" {
runtime. GOMAXPROCS( runtime. NumCPU( ))
if os.Getenv(
}
}
and be done with it. Alternatively, if it lived in cmd/jujud then
logging might be more appropriate, as it can be more location-specific
there.
https:/ /codereview. appspot. com/76120044/ diff/40001/ utils/gomaxproc s_test. go s_test. go (right):
File utils/gomaxproc
https:/ /codereview. appspot. com/76120044/ diff/40001/ utils/gomaxproc s_test. go#newcode28 s_test. go:28: maxprocsfunc := func(n int) int {
utils/gomaxproc
or:
maxProcsFunc := func(n int) int {
s.setMaxProcs = n
if n != 0 {
}
return 1
}
then dispense with the channel and just
assert on s.setMaxProcs directly.
https:/ /codereview. appspot. com/76120044/