Merge lp:~chipaca/ubuntu-push/complex-client-session into lp:ubuntu-push

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: 45
Merged at revision: 37
Proposed branch: lp:~chipaca/ubuntu-push/complex-client-session
Merge into: lp:ubuntu-push
Prerequisite: lp:~chipaca/ubuntu-push/advanced-client-session
Diff against target: 140 lines (+93/-5)
2 files modified
client/session/session.go (+30/-1)
client/session/session_test.go (+63/-4)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/complex-client-session
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
John Lenton (community) Approve
Review via email: mp+204120@code.launchpad.net

Commit message

Broadcasting your horizons.

Description of the change

Client session, volume 3: Client session in the complex plane.

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

immaterial but for clarity, there's a AckMsg in protocol now:

33 + err := sess.proto.WriteMessage(protocol.PingPongMsg{Type: "ack"})

review: Approve
Revision history for this message
John Lenton (chipaca) :
review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :
Download full text (3.1 KiB)

The attempt to merge lp:~chipaca/ubuntu-push/complex-client-session 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.027s
ok launchpad.net/ubuntu-push/bus/connectivity 0.086s
ok launchpad.net/ubuntu-push/bus/networkmanager 0.065s
ok launchpad.net/ubuntu-push/bus/notifications 0.020s
ok launchpad.net/ubuntu-push/bus/testing 0.018s
ok launchpad.net/ubuntu-push/bus/urldispatcher 0.066s
ok launchpad.net/ubuntu-push/client/session 0.040s
ok launchpad.net/ubuntu-push/client/session/levelmap 0.005s
ok launchpad.net/ubuntu-push/config 0.009s
ok launchpad.net/ubuntu-push/logger 0.008s
ok launchpad.net/ubuntu-push/protocol 0.011s
ok launchpad.net/ubuntu-push/server 0.026s
ok launchpad.net/ubuntu-push/server/acceptance 0.008s
? launchpad.net/ubuntu-push/server/acceptance/cmd [no test files]
ok launchpad.net/ubuntu-push/server/api 0.035s
ok launchpad.net/ubuntu-push/server/broker 0.017s
ok launchpad.net/ubuntu-push/server/broker/simple 0.016s
? 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 0.497s

----------------------------------------------------------------------
FAIL: session_test.go:480: sessionSuite.TestSessionWire

session_test.go:511:
    c.Check(err, Equals, io.EOF)
... obtained *net.OpError = &net.OpError{Op:"read", Net:"tcp", Addr:(*net.TCPAddr)(0xc2100378a0), Err:(*net.timeoutError)(0x88f718)} ("read tcp 127.0.0.1:57857: i/o timeout")
... expected *errors.errorString = &errors.errorString{s:"EOF"} ("EOF")

session_test.go:514:
    // tracking
    c.Check(buf.String(), Matches, `.*connected.*\n.*registered DEV.*\n.*ended with: EOF\n`)
... value string = "" +
... "2014/01/31 14:57:34.417553 DEBUG session(7970372a523ef3) connected 127.0.0.1:57857\n" +
... "2014/01/31 14:57:34.417849 INFO session(7970372a523ef3) registered DEV\n" +
... "2014/01/31 14:57:34.430397 DEBUG session(7970372a523ef3) ended with: read tcp 127.0.0.1:57857: i/o timeout\n"
... regex string = ".*connected.*\\n.*registered DEV.*\\n.*ended with: EOF\\n"

OOPS: 22 passed, 1 FAILED
--- FAIL: TestSession (0.10 seconds)
FAIL
FAIL launchpad.net/ubuntu-push/server/session 0.131s
ok launchpad.net/ubuntu-push/server/store 0.019s
? launchpad.net/ubuntu-push/testing [no test files]
ok launchpad.net/ubuntu-push/testing/condition 0.009s
ok launchpad.net/ubuntu-push/util 0.052s
ok launchpad.net/ubuntu-push/whoopsie/identifier 0.018s
ok launchpad.net/ubuntu-push/whoopsie/identifier/testing 0.007s

make: *** [check...

Read more...

Revision history for this message
Samuele Pedroni (pedronis) :
review: Needs Fixing
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :

Voting does not meet specified criteria. Required: Approve >= 1, Disapprove == 0, Needs Fixing == 0, Needs Information == 0, Resubmit == 0, Pending == 0. Got: 1 Approve, 1 Needs Fixing.

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

AckMsg still needs to specify a type

Revision history for this message
Samuele Pedroni (pedronis) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'client/session/session.go'
--- client/session/session.go 2014-01-31 14:06:31 +0000
+++ client/session/session.go 2014-01-31 16:06:58 +0000
@@ -35,6 +35,12 @@
35 // something something something35 // something something something
36}36}
3737
38type serverMsg struct {
39 Type string `json:"T"`
40 protocol.BroadcastMsg
41 protocol.NotificationsMsg
42}
43
38// ClienSession holds a client<->server session and its configuration.44// ClienSession holds a client<->server session and its configuration.
39type ClientSession struct {45type ClientSession struct {
40 // configuration46 // configuration
@@ -112,6 +118,29 @@
112func (sess *ClientSession) handlePing() error {118func (sess *ClientSession) handlePing() error {
113 sess.proto.SetDeadline(time.Now().Add(sess.ExchangeTimeout))119 sess.proto.SetDeadline(time.Now().Add(sess.ExchangeTimeout))
114 err := sess.proto.WriteMessage(protocol.PingPongMsg{Type: "pong"})120 err := sess.proto.WriteMessage(protocol.PingPongMsg{Type: "pong"})
115 sess.Log.Debugf("Ping.")121 if err == nil {
122 sess.Log.Debugf("ping.")
123 } else {
124 sess.Log.Errorf("unable to pong: %s", err)
125 }
116 return err126 return err
117}127}
128
129// handle "broadcast" messages
130func (sess *ClientSession) handleBroadcast(bcast *serverMsg) error {
131 sess.proto.SetDeadline(time.Now().Add(sess.ExchangeTimeout))
132 err := sess.proto.WriteMessage(protocol.AckMsg{"ack"})
133 if err != nil {
134 return err
135 }
136 sess.Log.Debugf("broadcast chan:%v app:%v topLevel:%d payloads:%s",
137 bcast.ChanId, bcast.AppId, bcast.TopLevel, bcast.Payloads)
138 if bcast.ChanId == protocol.SystemChannelId {
139 // the system channel id, the only one we care about for now
140 sess.Levels.Set(bcast.ChanId, bcast.TopLevel)
141 sess.MsgCh <- &Notification{}
142 } else {
143 sess.Log.Debugf("what is this weird channel, %s?", bcast.ChanId)
144 }
145 return nil
146}
118147
=== modified file 'client/session/session_test.go'
--- client/session/session_test.go 2014-01-31 14:15:47 +0000
+++ client/session/session_test.go 2014-01-31 16:06:58 +0000
@@ -263,18 +263,19 @@
263263
264func (s *msgSuite) SetUpTest(c *C) {264func (s *msgSuite) SetUpTest(c *C) {
265 var err error265 var err error
266 s.sess, err = NewSession("", nil, 0, "wah", debuglog)266 s.sess, err = NewSession("", nil, time.Millisecond, "wah", debuglog)
267 c.Assert(err, IsNil)267 c.Assert(err, IsNil)
268 s.sess.Connection = &testConn{Name: "TestRun* (small r)"}268 s.sess.Connection = &testConn{Name: "TestHandle*"}
269 s.errCh = make(chan error, 1)269 s.errCh = make(chan error, 1)
270 s.upCh = make(chan interface{}, 5)270 s.upCh = make(chan interface{}, 5)
271 s.downCh = make(chan interface{}, 5)271 s.downCh = make(chan interface{}, 5)
272 s.sess.proto = &testProtocol{up: s.upCh, down: s.downCh}272 s.sess.proto = &testProtocol{up: s.upCh, down: s.downCh}
273 // make the message channel buffered
274 s.sess.MsgCh = make(chan *Notification, 5)
273}275}
274276
275func (s *msgSuite) TestHandlePingWorks(c *C) {277func (s *msgSuite) TestHandlePingWorks(c *C) {
276 s.upCh <- nil // no error278 s.upCh <- nil // no error
277 s.sess.ExchangeTimeout = time.Millisecond
278 c.Check(s.sess.handlePing(), IsNil)279 c.Check(s.sess.handlePing(), IsNil)
279 c.Assert(len(s.downCh), Equals, 2)280 c.Assert(len(s.downCh), Equals, 2)
280 c.Check(<-s.downCh, Equals, "deadline 1ms")281 c.Check(<-s.downCh, Equals, "deadline 1ms")
@@ -287,6 +288,64 @@
287288
288 c.Check(s.sess.handlePing(), Equals, failure)289 c.Check(s.sess.handlePing(), Equals, failure)
289 c.Assert(len(s.downCh), Equals, 2)290 c.Assert(len(s.downCh), Equals, 2)
290 c.Check(<-s.downCh, Equals, "deadline 0")291 c.Check(<-s.downCh, Equals, "deadline 1ms")
291 c.Check(<-s.downCh, Equals, protocol.PingPongMsg{Type: "pong"})292 c.Check(<-s.downCh, Equals, protocol.PingPongMsg{Type: "pong"})
292}293}
294
295/****************************************************************
296 handleBroadcast() tests
297****************************************************************/
298
299func (s *msgSuite) TestHandleBroadcastWorks(c *C) {
300 msg := serverMsg{"broadcast",
301 protocol.BroadcastMsg{
302 Type: "broadcast",
303 AppId: "--ignored--",
304 ChanId: "0",
305 TopLevel: 2,
306 Payloads: []json.RawMessage{json.RawMessage(`{"b":1}`)},
307 }, protocol.NotificationsMsg{}}
308 go func() { s.errCh <- s.sess.handleBroadcast(&msg) }()
309 c.Check(takeNext(s.downCh), Equals, "deadline 1ms")
310 c.Check(takeNext(s.downCh), Equals, protocol.AckMsg{"ack"})
311 s.upCh <- nil // ack ok
312 c.Check(<-s.errCh, Equals, nil)
313 c.Assert(len(s.sess.MsgCh), Equals, 1)
314 c.Check(<-s.sess.MsgCh, Equals, &Notification{})
315 // and finally, the session keeps track of the levels
316 c.Check(s.sess.Levels.GetAll(), DeepEquals, map[string]int64{"0": 2})
317}
318
319func (s *msgSuite) TestHandleBroadcastBadAckWrite(c *C) {
320 msg := serverMsg{"broadcast",
321 protocol.BroadcastMsg{
322 Type: "broadcast",
323 AppId: "APP",
324 ChanId: "0",
325 TopLevel: 2,
326 Payloads: []json.RawMessage{json.RawMessage(`{"b":1}`)},
327 }, protocol.NotificationsMsg{}}
328 go func() { s.errCh <- s.sess.handleBroadcast(&msg) }()
329 c.Check(takeNext(s.downCh), Equals, "deadline 1ms")
330 c.Check(takeNext(s.downCh), Equals, protocol.AckMsg{"ack"})
331 failure := errors.New("ACK ACK ACK")
332 s.upCh <- failure
333 c.Assert(<-s.errCh, Equals, failure)
334}
335
336func (s *msgSuite) TestHandleBroadcastWrongChannel(c *C) {
337 msg := serverMsg{"broadcast",
338 protocol.BroadcastMsg{
339 Type: "broadcast",
340 AppId: "APP",
341 ChanId: "something awful",
342 TopLevel: 2,
343 Payloads: []json.RawMessage{json.RawMessage(`{"b":1}`)},
344 }, protocol.NotificationsMsg{}}
345 go func() { s.errCh <- s.sess.handleBroadcast(&msg) }()
346 c.Check(takeNext(s.downCh), Equals, "deadline 1ms")
347 c.Check(takeNext(s.downCh), Equals, protocol.AckMsg{"ack"})
348 s.upCh <- nil // ack ok
349 c.Check(<-s.errCh, IsNil)
350 c.Check(len(s.sess.MsgCh), Equals, 0)
351}

Subscribers

People subscribed via source and target branches