Merge lp:~themue/juju-core/031-fix-resumer-test into lp:~go-bot/juju-core/trunk

Proposed by Frank Mueller
Status: Merged
Approved by: Frank Mueller
Approved revision: no longer in the source branch.
Merged at revision: 1351
Proposed branch: lp:~themue/juju-core/031-fix-resumer-test
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 47 lines (+19/-7)
1 file modified
worker/resumer/resumer_test.go (+19/-7)
To merge this branch: bzr merge lp:~themue/juju-core/031-fix-resumer-test
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+171342@code.launchpad.net

Commit message

resumer: fix test race

The resumer test might lead to a race (detected
by Roger). So changed it to taking and comparing
timestamps for each call of the resumer mock.

https://codereview.appspot.com/10550043/

Description of the change

resumer: fix test race

The resumer test might lead to a race (detected
by Roger). So changed it to taking and comparing
timestamps for each call of the resumer mock.

https://codereview.appspot.com/10550043/

To post a comment you must log in.
Revision history for this message
William Reade (fwereade) wrote :
Revision history for this message
Dimiter Naydenov (dimitern) wrote :

LGTM modulo a single suggestion.

https://codereview.appspot.com/10550043/diff/1/worker/resumer/resumer_test.go
File worker/resumer/resumer_test.go (right):

https://codereview.appspot.com/10550043/diff/1/worker/resumer/resumer_test.go#newcode47
worker/resumer/resumer_test.go:47: c.Assert(len(tr.timestamps) > 0,
Equals, true)
This code block is a bit obscure to my puny mind - can you put some
comment describing what we're actually doing here please?

https://codereview.appspot.com/10550043/

Revision history for this message
Frank Mueller (themue) wrote :

https://codereview.appspot.com/10550043/diff/1/worker/resumer/resumer_test.go
File worker/resumer/resumer_test.go (right):

https://codereview.appspot.com/10550043/diff/1/worker/resumer/resumer_test.go#newcode47
worker/resumer/resumer_test.go:47: c.Assert(len(tr.timestamps) > 0,
Equals, true)
On 2013/06/27 14:33:26, dimitern wrote:
> This code block is a bit obscure to my puny mind - can you put some
comment
> describing what we're actually doing here please?

Done.

https://codereview.appspot.com/10550043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'worker/resumer/resumer_test.go'
2--- worker/resumer/resumer_test.go 2013-06-21 00:19:44 +0000
3+++ worker/resumer/resumer_test.go 2013-06-27 18:05:33 +0000
4@@ -34,24 +34,36 @@
5 func (s *ResumerSuite) TestResumerCalls(c *C) {
6 // Shorter interval and mock help to count
7 // the resumer calls in a given timespan.
8- resumer.SetInterval(10 * time.Millisecond)
9+ testInterval := 10 * time.Millisecond
10+ resumer.SetInterval(testInterval)
11 defer resumer.RestoreInterval()
12
13- tr := &transactionResumerMock{0}
14+ tr := &transactionResumerMock{[]time.Time{}}
15 rr := resumer.NewResumer(tr)
16 defer func() { c.Assert(rr.Stop(), IsNil) }()
17
18- time.Sleep(55 * time.Millisecond)
19- c.Assert(tr.counter, Equals, 5)
20+ time.Sleep(10 * testInterval)
21+
22+ // Check that a numner of calls has happened with a time
23+ // difference somewhere between the interval and twice the
24+ // interval. A more precise time behavior cannot be
25+ // specified due to the load during the test.
26+ c.Assert(len(tr.timestamps) > 0, Equals, true)
27+ for i := 1; i < len(tr.timestamps); i++ {
28+ diff := tr.timestamps[i].Sub(tr.timestamps[i-1])
29+
30+ c.Assert(diff >= testInterval, Equals, true)
31+ c.Assert(diff <= 2*testInterval, Equals, true)
32+ }
33 }
34
35 // transactionResumerMock is used to check the
36 // calls of ResumeTransactions().
37 type transactionResumerMock struct {
38- counter int
39+ timestamps []time.Time
40 }
41
42-func (t *transactionResumerMock) ResumeTransactions() error {
43- t.counter++
44+func (tr *transactionResumerMock) ResumeTransactions() error {
45+ tr.timestamps = append(tr.timestamps, time.Now())
46 return nil
47 }

Subscribers

People subscribed via source and target branches

to status/vote changes: