Merge lp:~chipaca/ubuntu-push/watchticker-goes-to-the-races into lp:ubuntu-push

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: 37
Merged at revision: 35
Proposed branch: lp:~chipaca/ubuntu-push/watchticker-goes-to-the-races
Merge into: lp:ubuntu-push
Prerequisite: lp:~chipaca/ubuntu-push/client-session
Diff against target: 128 lines (+27/-21)
4 files modified
bus/connectivity/connectivity_test.go (+3/-3)
bus/testing/testing_endpoint.go (+14/-10)
bus/testing/testing_endpoint_test.go (+7/-7)
tarmac_tests.sh (+3/-1)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/watchticker-goes-to-the-races
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+204232@code.launchpad.net

Commit message

get rid of a race in the bus/testing watchticker thing

Description of the change

Get rid of a race in the bus/testing watchticker thing.

To post a comment you must log in.
Revision history for this message
Samuele Pedroni (pedronis) wrote :

58 +func SetWatchTicker(tc bus.Endpoint, watchTicker chan bool) {

this guy need a description now that the global has gone

should we experiment putting make check-race in the tarmac_tests.sh (after plain make check):

=== modified file 'tarmac_tests.sh'
--- tarmac_tests.sh 2014-01-14 15:35:20 +0000
+++ tarmac_tests.sh 2014-01-31 13:42:33 +0000
@@ -2,4 +2,5 @@
 # For running tests in Jenkins by Tarmac
 set -e
 make bootstrap && make check
+make check-race
 make check-format

Revision history for this message
John Lenton (chipaca) wrote :

Adding a description.

If tarmac is 64 bits, yes!

36. By John Lenton

docs for SetWatchTicker

Revision history for this message
Samuele Pedroni (pedronis) :
review: Approve
37. By John Lenton

changed the tarmac script to call check-race

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bus/connectivity/connectivity_test.go'
2--- bus/connectivity/connectivity_test.go 2014-01-28 22:41:55 +0000
3+++ bus/connectivity/connectivity_test.go 2014-01-31 13:56:32 +0000
4@@ -196,8 +196,8 @@
5 uint32(networkmanager.Disconnected),
6 )
7
8- testingbus.WatchTicker = make(chan bool)
9- defer func() { testingbus.WatchTicker = nil }()
10+ watchTicker := make(chan bool)
11+ testingbus.SetWatchTicker(endp, watchTicker)
12
13 out := make(chan bool)
14 dt := time.Second / 10
15@@ -219,7 +219,7 @@
16
17 for i, expected := range expecteds {
18 for j := 0; j < expected.n; j++ {
19- testingbus.WatchTicker <- true
20+ watchTicker <- true
21 }
22 timer.Reset(dt)
23 select {
24
25=== modified file 'bus/testing/testing_endpoint.go'
26--- bus/testing/testing_endpoint.go 2014-01-29 11:33:36 +0000
27+++ bus/testing/testing_endpoint.go 2014-01-31 13:56:32 +0000
28@@ -27,9 +27,10 @@
29 )
30
31 type testingEndpoint struct {
32- dialCond condition.Interface
33- callCond condition.Interface
34- retvals [][]interface{}
35+ dialCond condition.Interface
36+ callCond condition.Interface
37+ retvals [][]interface{}
38+ watchTicker chan bool
39 }
40
41 // Build a bus.Endpoint that calls OK() on its condition before returning
42@@ -38,7 +39,7 @@
43 // NOTE: Call() always returns the first return value; Watch() will provide
44 // each of them in turn, irrespective of whether Call has been called.
45 func NewMultiValuedTestingEndpoint(dialCond condition.Interface, callCond condition.Interface, retvalses ...[]interface{}) bus.Endpoint {
46- return &testingEndpoint{dialCond, callCond, retvalses}
47+ return &testingEndpoint{dialCond, callCond, retvalses, nil}
48 }
49
50 func NewTestingEndpoint(dialCond condition.Interface, callCond condition.Interface, retvals ...interface{}) bus.Endpoint {
51@@ -46,12 +47,15 @@
52 for i, x := range retvals {
53 retvalses[i] = []interface{}{x}
54 }
55- return &testingEndpoint{dialCond, callCond, retvalses}
56+ return &testingEndpoint{dialCond, callCond, retvalses, nil}
57 }
58
59-// if WatchTickeris not nil, it is used instead of the default timeout
60-// to wait while sending values over WatchSignal
61-var WatchTicker chan bool
62+// If SetWatchTicker is called with a non-nil watchTicker, it is used
63+// instead of the default timeout to wait while sending values over
64+// WatchSignal. Set it to nil again to restore default behaviour.
65+func SetWatchTicker(tc bus.Endpoint, watchTicker chan bool) {
66+ tc.(*testingEndpoint).watchTicker = watchTicker
67+}
68
69 // See Endpoint's WatchSignal. This WatchSignal will check its condition to
70 // decide whether to return an error, or provide each of its return values
71@@ -60,8 +64,8 @@
72 go func() {
73 for _, v := range tc.retvals {
74 f(v...)
75- if WatchTicker != nil {
76- <-WatchTicker
77+ if tc.watchTicker != nil {
78+ <-tc.watchTicker
79 } else {
80 time.Sleep(10 * time.Millisecond)
81 }
82
83=== modified file 'bus/testing/testing_endpoint_test.go'
84--- bus/testing/testing_endpoint_test.go 2014-01-29 11:33:36 +0000
85+++ bus/testing/testing_endpoint_test.go 2014-01-31 13:56:32 +0000
86@@ -104,14 +104,14 @@
87 // Test WatchSignal can use the WatchTicker instead of a timeout (if
88 // the former is not nil)
89 func (s *TestingEndpointSuite) TestWatchTicker(c *C) {
90- WatchTicker = make(chan bool, 3)
91- defer func() { WatchTicker = nil }()
92- WatchTicker <- true
93- WatchTicker <- true
94- WatchTicker <- true
95- c.Assert(len(WatchTicker), Equals, 3)
96+ watchTicker := make(chan bool, 3)
97+ watchTicker <- true
98+ watchTicker <- true
99+ watchTicker <- true
100+ c.Assert(len(watchTicker), Equals, 3)
101
102 endp := NewTestingEndpoint(nil, condition.Work(true), 0, 0)
103+ SetWatchTicker(endp, watchTicker)
104 ch := make(chan int)
105 e := endp.WatchSignal("what", func(us ...interface{}) {}, func() { close(ch) })
106 c.Check(e, IsNil)
107@@ -124,7 +124,7 @@
108 }
109
110 // now if all went well, the ticker will have been tuck twice.
111- c.Assert(len(WatchTicker), Equals, 1)
112+ c.Assert(len(watchTicker), Equals, 1)
113 }
114
115 // Tests that GetProperty() works
116
117=== modified file 'tarmac_tests.sh'
118--- tarmac_tests.sh 2014-01-14 15:35:20 +0000
119+++ tarmac_tests.sh 2014-01-31 13:56:32 +0000
120@@ -1,5 +1,7 @@
121 #!/bin/bash
122 # For running tests in Jenkins by Tarmac
123 set -e
124-make bootstrap && make check
125+make bootstrap
126+make check
127+make check-race
128 make check-format

Subscribers

People subscribed via source and target branches