Merge lp:~chipaca/ubuntu-push/bus-endpoint-wachticker into lp:ubuntu-push

Proposed by John Lenton
Status: Superseded
Proposed branch: lp:~chipaca/ubuntu-push/bus-endpoint-wachticker
Merge into: lp:ubuntu-push
Prerequisite: lp:~chipaca/ubuntu-push/actual-client-v0
Diff against target: 123 lines (+60/-10)
3 files modified
bus/connectivity/connectivity_test.go (+19/-9)
bus/testing/testing_endpoint.go (+12/-1)
bus/testing/testing_endpoint_test.go (+29/-0)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/bus-endpoint-wachticker
Reviewer Review Type Date Requested Status
Ubuntu Push Hackers Pending
Review via email: mp+203386@code.launchpad.net

This proposal has been superseded by a proposal from 2014-01-28.

Commit message

made bus.Endpoint's WatchSignal use an (exported) channel for waiting between sending values, if the channel is not nil.

Description of the change

made bus.Endpoint's WatchSignal use an (exported) channel for waiting between sending values, if the channel is not nil.

To post a comment you must log in.
32. By John Lenton

Merged actual-client-v0 into bus-endpoint-wachticker.

33. By John Lenton

got rid of useless chicken scratchings

Revision history for this message
Samuele Pedroni (pedronis) wrote :

66 +var WatchTicker chan rune

using a rune here is a bit confusing, maybe

type TickT rune

const Tick TickT = 'x'

chan TickT

37 + for _, b := range expected.ticks {
38 + testingbus.WatchTicker <- b
39 + }

that's cute but also fairly obscure, also b sounds like a byte or boolean, not rune, expected ticks cool be just a bool no? or are always ticking once or not

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

or it could be an int, and we send over that many bools.

Unmerged revisions

33. By John Lenton

got rid of useless chicken scratchings

32. By John Lenton

Merged actual-client-v0 into bus-endpoint-wachticker.

31. By John Lenton

made bus.Endpoint's WatchSignal use an (exported) channel for waiting between sending values, if the channel is not nil.

30. By John Lenton

Used an anon struct to get more information about each iter through the loop in connnectivity_test's TestRun.

29. By John Lenton

merged pipeline; conflict in the redialer fixed

28. By John Lenton

moved client config to etc

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-27 18:45:28 +0000
3+++ bus/connectivity/connectivity_test.go 2014-01-27 18:45:28 +0000
4@@ -196,29 +196,39 @@
5 uint32(networkmanager.Disconnected),
6 )
7
8+ testingbus.WatchTicker = make(chan rune)
9+ defer func() { testingbus.WatchTicker = nil }()
10+
11 out := make(chan bool)
12 dt := time.Second / 10
13 timer := time.NewTimer(dt)
14 go ConnectedState(endp, cfg, nullog, out)
15 var v bool
16- expecteds := []bool{
17- false, // first state is always false
18- true, // then it should be true as per ConnectedGlobal above
19- false, // then, false (upon receiving the next ConnectedGlobal)
20- true, // then it should be true (webcheck passed)
21- false, // then it should be false (Disconnected)
22- false, // then it should be false again because it's restarted
23+ expecteds := []struct {
24+ p bool
25+ s string
26+ ticks string
27+ }{
28+ {false, "first state is always false", ""},
29+ {true, "then it should be true as per ConnectedGlobal above", ""},
30+ {false, "then, false (upon receiving the next ConnectedGlobal)", "x"},
31+ {true, "then it should be true (webcheck passed)", ""},
32+ {false, "then it should be false (Disconnected)", "x"},
33+ {false, "then it should be false again because it's restarted", "x"},
34 }
35
36 for i, expected := range expecteds {
37+ for _, b := range expected.ticks {
38+ testingbus.WatchTicker <- b
39+ }
40 timer.Reset(dt)
41 select {
42 case v = <-out:
43 break
44 case <-timer.C:
45- c.Fatalf("Timed out before getting value (#%d)", i+1)
46+ c.Fatalf("Timed out before getting value (#%d: %s)", i+1, expected.s)
47 }
48
49- c.Check(v, Equals, expected)
50+ c.Check(v, Equals, expected.p, Commentf(expected.s))
51 }
52 }
53
54=== modified file 'bus/testing/testing_endpoint.go'
55--- bus/testing/testing_endpoint.go 2014-01-27 12:41:54 +0000
56+++ bus/testing/testing_endpoint.go 2014-01-27 18:45:28 +0000
57@@ -49,6 +49,13 @@
58 return &testingEndpoint{dialCond, callCond, retvalses}
59 }
60
61+// if WatchTickeris not nil, it is used instead of the default timeout
62+// to wait while sending values over WatchSignal
63+//
64+// It's chan rune merely for convenience to testers; the value is
65+// discarded.
66+var WatchTicker chan rune
67+
68 // See Endpoint's WatchSignal. This WatchSignal will check its condition to
69 // decide whether to return an error, or provide each of its return values
70 func (tc *testingEndpoint) WatchSignal(member string, f func(...interface{}), d func()) error {
71@@ -56,7 +63,11 @@
72 go func() {
73 for _, v := range tc.retvals {
74 f(v...)
75- time.Sleep(10 * time.Millisecond)
76+ if WatchTicker != nil {
77+ <-WatchTicker
78+ } else {
79+ <-time.Tick(10 * time.Millisecond)
80+ }
81 }
82 d()
83 }()
84
85=== modified file 'bus/testing/testing_endpoint_test.go'
86--- bus/testing/testing_endpoint_test.go 2014-01-27 12:41:54 +0000
87+++ bus/testing/testing_endpoint_test.go 2014-01-27 18:45:28 +0000
88@@ -101,6 +101,35 @@
89 c.Check(e, NotNil)
90 }
91
92+// Test WatchSignal can use the WatchTicker instead of a timeout (if
93+// the former is not nil)
94+func (s *TestingEndpointSuite) TestWatchTicker(c *C) {
95+ WatchTicker = make(chan rune, 3)
96+ defer func() { WatchTicker = nil }()
97+ WatchTicker <- 'x'
98+ WatchTicker <- 'x'
99+ WatchTicker <- 'x'
100+ c.Assert(len(WatchTicker), Equals, 3)
101+
102+ endp := NewTestingEndpoint(nil, condition.Work(true), 0, 0)
103+ ch := make(chan int)
104+ e := endp.WatchSignal("what", func(us ...interface{}) {}, func() { close(ch) })
105+ c.Check(e, IsNil)
106+
107+ // wait for the destructor to be called
108+Out:
109+ for {
110+ select {
111+ case <-ch:
112+ break Out
113+ case <-time.Tick(time.Millisecond):
114+ }
115+ }
116+
117+ // now if all went well, the ticker will have been tuck twice.
118+ c.Assert(len(WatchTicker), Equals, 1)
119+}
120+
121 // Tests that GetProperty() works
122 func (s *TestingEndpointSuite) TestGetProperty(c *C) {
123 var m uint32 = 42

Subscribers

People subscribed via source and target branches