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
1=== modified file 'bus/connectivity/connectivity_test.go'
2--- bus/connectivity/connectivity_test.go 2014-01-28 22:18:39 +0000
3+++ bus/connectivity/connectivity_test.go 2014-01-29 11:33:47 +0000
4@@ -196,29 +196,39 @@
5 uint32(networkmanager.Disconnected),
6 )
7
8+ testingbus.WatchTicker = make(chan bool)
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+ n int
27+ }{
28+ {false, "first state is always false", 0},
29+ {true, "then it should be true as per ConnectedGlobal above", 0},
30+ {false, "then, false (upon receiving the next ConnectedGlobal)", 1},
31+ {true, "then it should be true (webcheck passed)", 0},
32+ {false, "then it should be false (Disconnected)", 1},
33+ {false, "then it should be false again because it's restarted", 1},
34 }
35
36 for i, expected := range expecteds {
37+ for j := 0; j < expected.n; j++ {
38+ testingbus.WatchTicker <- true
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-29 11:33:47 +0000
57@@ -49,6 +49,10 @@
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+var WatchTicker chan bool
64+
65 // See Endpoint's WatchSignal. This WatchSignal will check its condition to
66 // decide whether to return an error, or provide each of its return values
67 func (tc *testingEndpoint) WatchSignal(member string, f func(...interface{}), d func()) error {
68@@ -56,7 +60,11 @@
69 go func() {
70 for _, v := range tc.retvals {
71 f(v...)
72- time.Sleep(10 * time.Millisecond)
73+ if WatchTicker != nil {
74+ <-WatchTicker
75+ } else {
76+ time.Sleep(10 * time.Millisecond)
77+ }
78 }
79 d()
80 }()
81
82=== modified file 'bus/testing/testing_endpoint_test.go'
83--- bus/testing/testing_endpoint_test.go 2014-01-27 12:41:54 +0000
84+++ bus/testing/testing_endpoint_test.go 2014-01-29 11:33:47 +0000
85@@ -101,6 +101,32 @@
86 c.Check(e, NotNil)
87 }
88
89+// Test WatchSignal can use the WatchTicker instead of a timeout (if
90+// the former is not nil)
91+func (s *TestingEndpointSuite) TestWatchTicker(c *C) {
92+ WatchTicker = make(chan bool, 3)
93+ defer func() { WatchTicker = nil }()
94+ WatchTicker <- true
95+ WatchTicker <- true
96+ WatchTicker <- true
97+ c.Assert(len(WatchTicker), Equals, 3)
98+
99+ endp := NewTestingEndpoint(nil, condition.Work(true), 0, 0)
100+ ch := make(chan int)
101+ e := endp.WatchSignal("what", func(us ...interface{}) {}, func() { close(ch) })
102+ c.Check(e, IsNil)
103+
104+ // wait for the destructor to be called
105+ select {
106+ case <-time.Tick(10 * time.Millisecond):
107+ c.Fatal("timed out waiting for close on channel")
108+ case <-ch:
109+ }
110+
111+ // now if all went well, the ticker will have been tuck twice.
112+ c.Assert(len(WatchTicker), Equals, 1)
113+}
114+
115 // Tests that GetProperty() works
116 func (s *TestingEndpointSuite) TestGetProperty(c *C) {
117 var m uint32 = 42

Subscribers

People subscribed via source and target branches