Merge lp:~chipaca/ubuntu-push/watchticker into lp:ubuntu-push

Proposed by John Lenton
Status: Merged
Approved by: Samuele Pedroni
Approved revision: no longer in the source branch.
Merged at revision: 31
Proposed branch: lp:~chipaca/ubuntu-push/watchticker
Merge into: lp:ubuntu-push
Diff against target: 117 lines (+54/-10)
3 files modified
bus/connectivity/connectivity_test.go (+19/-9)
bus/testing/testing_endpoint.go (+9/-1)
bus/testing/testing_endpoint_test.go (+26/-0)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/watchticker
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+203639@code.launchpad.net

This proposal supersedes a proposal from 2014-01-27.

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.
Revision history for this message
Samuele Pedroni (pedronis) wrote : Posted in a previous version of this proposal

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 : Posted in a previous version of this proposal

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

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

Re-proposed against new branch that does all the old stuff and more! Well, just the more bit discussed with Samuele. And it doesn't depend on client.

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

76 + <-time.Tick(10 * time.Millisecond)

this can just be a Sleep again right? it's a fresh ticker each time

104 + // wait for the destructor to be called
105 +Out:
106 + for {
107 + select {
108 + case <-ch:
109 + break Out
110 + case <-time.Tick(time.Millisecond):
111 + }
112 + }

I don't understand this code, shouldn't it just be a:

select {
  case <- ch:
    break
  case <- time.After(TIMEOUT):
    FAIL!
}

without the busy loop

Revision history for this message
Samuele Pedroni (pedronis) :
review: Needs Information
Revision history for this message
John Lenton (chipaca) wrote :

Umm... right on both counts. Fixed.

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

looks good

review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :

The attempt to merge lp:~chipaca/ubuntu-push/watchticker into lp:ubuntu-push failed. Below is the output from the failed tests.

mkdir -p /mnt/tarmac/cache/ubuntu-push/go-ws/bin
mkdir -p /mnt/tarmac/cache/ubuntu-push/go-ws/pkg
go get -u launchpad.net/godeps
go get -d -u launchpad.net/gocheck launchpad.net/go-dbus/v1
/mnt/tarmac/cache/ubuntu-push/go-ws/bin/godeps -u dependencies.tsv
"/mnt/tarmac/cache/ubuntu-push/go-ws/src/launchpad.net/gocheck" now at <email address hidden>
go install launchpad.net/gocheck launchpad.net/go-dbus/v1
go test launchpad.net/ubuntu-push/...
ok launchpad.net/ubuntu-push/bus 0.056s
ok launchpad.net/ubuntu-push/bus/connectivity 2.689s
ok launchpad.net/ubuntu-push/bus/networkmanager 1.387s
ok launchpad.net/ubuntu-push/bus/notifications 1.139s
ok launchpad.net/ubuntu-push/bus/testing 1.158s
ok launchpad.net/ubuntu-push/bus/urldispatcher 1.175s
ok launchpad.net/ubuntu-push/config 0.648s
ok launchpad.net/ubuntu-push/logger 0.108s
ok launchpad.net/ubuntu-push/protocol 0.402s
ok launchpad.net/ubuntu-push/server 1.488s
ok launchpad.net/ubuntu-push/server/acceptance 0.359s
? launchpad.net/ubuntu-push/server/acceptance/cmd [no test files]
ok launchpad.net/ubuntu-push/server/api 0.671s
ok launchpad.net/ubuntu-push/server/broker 0.650s
ok launchpad.net/ubuntu-push/server/broker/simple 0.933s
? launchpad.net/ubuntu-push/server/broker/testing [no test files]
? launchpad.net/ubuntu-push/server/broker/testsuite [no test files]
? launchpad.net/ubuntu-push/server/dev [no test files]
ok launchpad.net/ubuntu-push/server/listener 11.924s

----------------------------------------------------------------------
FAIL: session_test.go:412: sessionSuite.TestSessionLoopExchangeNextPing

session_test.go:430:
    c.Check(time.Since(tack) < (3+5)*time.Millisecond, Equals, true)
... obtained bool = false
... expected bool = true

OOPS: 22 passed, 1 FAILED
--- FAIL: TestSession (2.49 seconds)
FAIL
FAIL launchpad.net/ubuntu-push/server/session 3.182s
ok launchpad.net/ubuntu-push/server/store 3.959s
? launchpad.net/ubuntu-push/testing [no test files]
ok launchpad.net/ubuntu-push/testing/condition 0.695s
ok launchpad.net/ubuntu-push/util 1.332s
ok launchpad.net/ubuntu-push/whoopsie/identifier 0.994s
ok launchpad.net/ubuntu-push/whoopsie/identifier/testing 2.002s

make: *** [check] Error 1

lp:~chipaca/ubuntu-push/watchticker updated
30. By John Lenton

[r=pedronis] Introducing AutoRetry, a generic AutoRetry.

31. By John Lenton

[r=pedronis] Made bus.Endpoint's WatchSignal use an (exported) channel for waiting between sending values, if the channel is not nil.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bus/connectivity/connectivity_test.go'
--- bus/connectivity/connectivity_test.go 2014-01-28 22:18:39 +0000
+++ bus/connectivity/connectivity_test.go 2014-01-29 11:33:47 +0000
@@ -196,29 +196,39 @@
196 uint32(networkmanager.Disconnected),196 uint32(networkmanager.Disconnected),
197 )197 )
198198
199 testingbus.WatchTicker = make(chan bool)
200 defer func() { testingbus.WatchTicker = nil }()
201
199 out := make(chan bool)202 out := make(chan bool)
200 dt := time.Second / 10203 dt := time.Second / 10
201 timer := time.NewTimer(dt)204 timer := time.NewTimer(dt)
202 go ConnectedState(endp, cfg, nullog, out)205 go ConnectedState(endp, cfg, nullog, out)
203 var v bool206 var v bool
204 expecteds := []bool{207 expecteds := []struct {
205 false, // first state is always false208 p bool
206 true, // then it should be true as per ConnectedGlobal above209 s string
207 false, // then, false (upon receiving the next ConnectedGlobal)210 n int
208 true, // then it should be true (webcheck passed)211 }{
209 false, // then it should be false (Disconnected)212 {false, "first state is always false", 0},
210 false, // then it should be false again because it's restarted213 {true, "then it should be true as per ConnectedGlobal above", 0},
214 {false, "then, false (upon receiving the next ConnectedGlobal)", 1},
215 {true, "then it should be true (webcheck passed)", 0},
216 {false, "then it should be false (Disconnected)", 1},
217 {false, "then it should be false again because it's restarted", 1},
211 }218 }
212219
213 for i, expected := range expecteds {220 for i, expected := range expecteds {
221 for j := 0; j < expected.n; j++ {
222 testingbus.WatchTicker <- true
223 }
214 timer.Reset(dt)224 timer.Reset(dt)
215 select {225 select {
216 case v = <-out:226 case v = <-out:
217 break227 break
218 case <-timer.C:228 case <-timer.C:
219 c.Fatalf("Timed out before getting value (#%d)", i+1)229 c.Fatalf("Timed out before getting value (#%d: %s)", i+1, expected.s)
220 }230 }
221231
222 c.Check(v, Equals, expected)232 c.Check(v, Equals, expected.p, Commentf(expected.s))
223 }233 }
224}234}
225235
=== modified file 'bus/testing/testing_endpoint.go'
--- bus/testing/testing_endpoint.go 2014-01-27 12:41:54 +0000
+++ bus/testing/testing_endpoint.go 2014-01-29 11:33:47 +0000
@@ -49,6 +49,10 @@
49 return &testingEndpoint{dialCond, callCond, retvalses}49 return &testingEndpoint{dialCond, callCond, retvalses}
50}50}
5151
52// if WatchTickeris not nil, it is used instead of the default timeout
53// to wait while sending values over WatchSignal
54var WatchTicker chan bool
55
52// See Endpoint's WatchSignal. This WatchSignal will check its condition to56// See Endpoint's WatchSignal. This WatchSignal will check its condition to
53// decide whether to return an error, or provide each of its return values57// decide whether to return an error, or provide each of its return values
54func (tc *testingEndpoint) WatchSignal(member string, f func(...interface{}), d func()) error {58func (tc *testingEndpoint) WatchSignal(member string, f func(...interface{}), d func()) error {
@@ -56,7 +60,11 @@
56 go func() {60 go func() {
57 for _, v := range tc.retvals {61 for _, v := range tc.retvals {
58 f(v...)62 f(v...)
59 time.Sleep(10 * time.Millisecond)63 if WatchTicker != nil {
64 <-WatchTicker
65 } else {
66 time.Sleep(10 * time.Millisecond)
67 }
60 }68 }
61 d()69 d()
62 }()70 }()
6371
=== modified file 'bus/testing/testing_endpoint_test.go'
--- bus/testing/testing_endpoint_test.go 2014-01-27 12:41:54 +0000
+++ bus/testing/testing_endpoint_test.go 2014-01-29 11:33:47 +0000
@@ -101,6 +101,32 @@
101 c.Check(e, NotNil)101 c.Check(e, NotNil)
102}102}
103103
104// Test WatchSignal can use the WatchTicker instead of a timeout (if
105// the former is not nil)
106func (s *TestingEndpointSuite) TestWatchTicker(c *C) {
107 WatchTicker = make(chan bool, 3)
108 defer func() { WatchTicker = nil }()
109 WatchTicker <- true
110 WatchTicker <- true
111 WatchTicker <- true
112 c.Assert(len(WatchTicker), Equals, 3)
113
114 endp := NewTestingEndpoint(nil, condition.Work(true), 0, 0)
115 ch := make(chan int)
116 e := endp.WatchSignal("what", func(us ...interface{}) {}, func() { close(ch) })
117 c.Check(e, IsNil)
118
119 // wait for the destructor to be called
120 select {
121 case <-time.Tick(10 * time.Millisecond):
122 c.Fatal("timed out waiting for close on channel")
123 case <-ch:
124 }
125
126 // now if all went well, the ticker will have been tuck twice.
127 c.Assert(len(WatchTicker), Equals, 1)
128}
129
104// Tests that GetProperty() works130// Tests that GetProperty() works
105func (s *TestingEndpointSuite) TestGetProperty(c *C) {131func (s *TestingEndpointSuite) TestGetProperty(c *C) {
106 var m uint32 = 42132 var m uint32 = 42

Subscribers

People subscribed via source and target branches