Merge lp://staging/~jameinel/juju-core/timing-test into lp://staging/~juju/juju-core/trunk
Status: | Merged |
---|---|
Merge reported by: | John A Meinel |
Merged at revision: | not available |
Proposed branch: | lp://staging/~jameinel/juju-core/timing-test |
Merge into: | lp://staging/~juju/juju-core/trunk |
Diff against target: |
104 lines (+46/-20) 1 file modified
cmd/juju/plugin_test.go (+46/-20) |
To merge this branch: | bzr merge lp://staging/~jameinel/juju-core/timing-test |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+169155@code.staging.launchpad.net |
Description of the change
cmd/juju: Make a test deterministic
TestGatherDescr
on my system. Rather than just increasing the timeout arbitrarily, I changed
the code to be more 'event' based. Each plugin requires another plugin to
have started before that plugin will return. Thus, if we don't start the
plugins in parallel, the plugin will deadlock.
Because the failure mode is 'deadlock', I wrapped the call in a select timeout.
This means that if it *does* fail, we have a garbage goroutine and process
lying around (but it should never fail).
On the plus side, this makes it actually run faster, since each subprocess doesn't
waste time sleeping just so we can measure it. (from 350ms down to normally
around 15ms.)
This is the only test that was failing (based on occasional timing hiccups)
for me, which allows us to have this in tarmac.
Reviewers: mp+169155_ code.launchpad. net,
Message:
Please take a look.
Description:
cmd/juju: Make a test deterministic
TestGatherDescr iptionsInParall el was timing dependent, and occasionally
failed
on my system. Rather than just increasing the timeout arbitrarily, I
changed
the code to be more 'event' based. Each plugin requires another plugin
to
have started before that plugin will return. Thus, if we don't start the
plugins in parallel, the plugin will deadlock.
Because the failure mode is 'deadlock', I wrapped the call in a select
timeout.
This means that if it *does* fail, we have a garbage goroutine and
process
lying around (but it should never fail).
On the plus side, this makes it actually run faster, since each
subprocess doesn't
waste time sleeping just so we can measure it. (from 350ms down to
normally
around 15ms.)
This is the only test that was failing (based on occasional timing
hiccups)
for me, which allows us to have this in tarmac.
https:/ /code.launchpad .net/~jameinel/ juju-core/ timing- test/+merge/ 169155
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/10234047/
Affected files: plugin_ test.go
A [revision details]
M cmd/juju/
Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>
Index: cmd/juju/ plugin_ test.go plugin_ test.go' plugin_ test.go 2013-05-22 21:47:11 +0000 plugin_ test.go 2013-06-13 10:32:38 +0000
=== modified file 'cmd/juju/
--- cmd/juju/
+++ cmd/juju/
@@ -92,21 +92,31 @@
}
func (suite *PluginSuite) TestGatherDescr iptionsInParall el(c *C) { lugin(PluginPar ams{Name: "foo", Sleep: 100 * lugin(PluginPar ams{Name: "bar", Sleep: 150 * lugin(PluginPar ams{Name: "baz", Sleep: 300 * lugin(PluginPar ams{Name: "error", ExitStatus: 1, Sleep: lugin(PluginPar ams{Name: "slow", Sleep: 200 * ptions( ) lugin(PluginPar ams{Name: "foo", Creates: "foo", lugin(PluginPar ams{Name: "bar", Creates: "bar", lugin(PluginPar ams{Name: "baz", Creates: "baz", lugin(PluginPar ams{Name: "error", ExitStatus: 1, ptions would deadlock, tion)
- suite.makeFullP
time.Millisecond})
- suite.makeFullP
time.Millisecond})
- suite.makeFullP
time.Millisecond})
- suite.makeFullP
100 * time.Millisecond})
- suite.makeFullP
time.Millisecond})
-
- start := time.Now()
- results := GetPluginDescri
- elapsed := time.Since(start)
-
- // 300 for baz above + 50ms wiggle room
- expectedDuration := 350 * time.Millisecond
-
- c.Assert(results, HasLen, 5)
- c.Check(elapsed, DurationLessThan, expectedDuration)
+ // Each plugin depends on another one being started before they will
complete.
+ // Thus if we don't start them in parallel, we would deadlock
+ suite.makeFullP
DependsOn: "bar"})
+ suite.makeFullP
DependsOn: "baz"})
+ suite.makeFullP
DependsOn: "error"})
+ suite.makeFullP
Creates: "error", DependsOn: "foo"})
+
+ // If the code was wrong, GetPluginDescri
+ // so timeout after a short while
+ resultChan := make(chan []PluginDescrip
+ go func()...