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
=== modified file 'worker/resumer/resumer_test.go'
--- worker/resumer/resumer_test.go 2013-06-21 00:19:44 +0000
+++ worker/resumer/resumer_test.go 2013-06-27 18:05:33 +0000
@@ -34,24 +34,36 @@
34func (s *ResumerSuite) TestResumerCalls(c *C) {34func (s *ResumerSuite) TestResumerCalls(c *C) {
35 // Shorter interval and mock help to count35 // Shorter interval and mock help to count
36 // the resumer calls in a given timespan.36 // the resumer calls in a given timespan.
37 resumer.SetInterval(10 * time.Millisecond)37 testInterval := 10 * time.Millisecond
38 resumer.SetInterval(testInterval)
38 defer resumer.RestoreInterval()39 defer resumer.RestoreInterval()
3940
40 tr := &transactionResumerMock{0}41 tr := &transactionResumerMock{[]time.Time{}}
41 rr := resumer.NewResumer(tr)42 rr := resumer.NewResumer(tr)
42 defer func() { c.Assert(rr.Stop(), IsNil) }()43 defer func() { c.Assert(rr.Stop(), IsNil) }()
4344
44 time.Sleep(55 * time.Millisecond)45 time.Sleep(10 * testInterval)
45 c.Assert(tr.counter, Equals, 5)46
47 // Check that a numner of calls has happened with a time
48 // difference somewhere between the interval and twice the
49 // interval. A more precise time behavior cannot be
50 // specified due to the load during the test.
51 c.Assert(len(tr.timestamps) > 0, Equals, true)
52 for i := 1; i < len(tr.timestamps); i++ {
53 diff := tr.timestamps[i].Sub(tr.timestamps[i-1])
54
55 c.Assert(diff >= testInterval, Equals, true)
56 c.Assert(diff <= 2*testInterval, Equals, true)
57 }
46}58}
4759
48// transactionResumerMock is used to check the60// transactionResumerMock is used to check the
49// calls of ResumeTransactions().61// calls of ResumeTransactions().
50type transactionResumerMock struct {62type transactionResumerMock struct {
51 counter int63 timestamps []time.Time
52}64}
5365
54func (t *transactionResumerMock) ResumeTransactions() error {66func (tr *transactionResumerMock) ResumeTransactions() error {
55 t.counter++67 tr.timestamps = append(tr.timestamps, time.Now())
56 return nil68 return nil
57}69}

Subscribers

People subscribed via source and target branches

to status/vote changes: