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
1=== modified file 'client/session/session.go'
2--- client/session/session.go 2014-01-31 14:06:31 +0000
3+++ client/session/session.go 2014-01-31 16:06:58 +0000
4@@ -35,6 +35,12 @@
5 // something something something
6 }
7
8+type serverMsg struct {
9+ Type string `json:"T"`
10+ protocol.BroadcastMsg
11+ protocol.NotificationsMsg
12+}
13+
14 // ClienSession holds a client<->server session and its configuration.
15 type ClientSession struct {
16 // configuration
17@@ -112,6 +118,29 @@
18 func (sess *ClientSession) handlePing() error {
19 sess.proto.SetDeadline(time.Now().Add(sess.ExchangeTimeout))
20 err := sess.proto.WriteMessage(protocol.PingPongMsg{Type: "pong"})
21- sess.Log.Debugf("Ping.")
22+ if err == nil {
23+ sess.Log.Debugf("ping.")
24+ } else {
25+ sess.Log.Errorf("unable to pong: %s", err)
26+ }
27 return err
28 }
29+
30+// handle "broadcast" messages
31+func (sess *ClientSession) handleBroadcast(bcast *serverMsg) error {
32+ sess.proto.SetDeadline(time.Now().Add(sess.ExchangeTimeout))
33+ err := sess.proto.WriteMessage(protocol.AckMsg{"ack"})
34+ if err != nil {
35+ return err
36+ }
37+ sess.Log.Debugf("broadcast chan:%v app:%v topLevel:%d payloads:%s",
38+ bcast.ChanId, bcast.AppId, bcast.TopLevel, bcast.Payloads)
39+ if bcast.ChanId == protocol.SystemChannelId {
40+ // the system channel id, the only one we care about for now
41+ sess.Levels.Set(bcast.ChanId, bcast.TopLevel)
42+ sess.MsgCh <- &Notification{}
43+ } else {
44+ sess.Log.Debugf("what is this weird channel, %s?", bcast.ChanId)
45+ }
46+ return nil
47+}
48
49=== modified file 'client/session/session_test.go'
50--- client/session/session_test.go 2014-01-31 14:15:47 +0000
51+++ client/session/session_test.go 2014-01-31 16:06:58 +0000
52@@ -263,18 +263,19 @@
53
54 func (s *msgSuite) SetUpTest(c *C) {
55 var err error
56- s.sess, err = NewSession("", nil, 0, "wah", debuglog)
57+ s.sess, err = NewSession("", nil, time.Millisecond, "wah", debuglog)
58 c.Assert(err, IsNil)
59- s.sess.Connection = &testConn{Name: "TestRun* (small r)"}
60+ s.sess.Connection = &testConn{Name: "TestHandle*"}
61 s.errCh = make(chan error, 1)
62 s.upCh = make(chan interface{}, 5)
63 s.downCh = make(chan interface{}, 5)
64 s.sess.proto = &testProtocol{up: s.upCh, down: s.downCh}
65+ // make the message channel buffered
66+ s.sess.MsgCh = make(chan *Notification, 5)
67 }
68
69 func (s *msgSuite) TestHandlePingWorks(c *C) {
70 s.upCh <- nil // no error
71- s.sess.ExchangeTimeout = time.Millisecond
72 c.Check(s.sess.handlePing(), IsNil)
73 c.Assert(len(s.downCh), Equals, 2)
74 c.Check(<-s.downCh, Equals, "deadline 1ms")
75@@ -287,6 +288,64 @@
76
77 c.Check(s.sess.handlePing(), Equals, failure)
78 c.Assert(len(s.downCh), Equals, 2)
79- c.Check(<-s.downCh, Equals, "deadline 0")
80+ c.Check(<-s.downCh, Equals, "deadline 1ms")
81 c.Check(<-s.downCh, Equals, protocol.PingPongMsg{Type: "pong"})
82 }
83+
84+/****************************************************************
85+ handleBroadcast() tests
86+****************************************************************/
87+
88+func (s *msgSuite) TestHandleBroadcastWorks(c *C) {
89+ msg := serverMsg{"broadcast",
90+ protocol.BroadcastMsg{
91+ Type: "broadcast",
92+ AppId: "--ignored--",
93+ ChanId: "0",
94+ TopLevel: 2,
95+ Payloads: []json.RawMessage{json.RawMessage(`{"b":1}`)},
96+ }, protocol.NotificationsMsg{}}
97+ go func() { s.errCh <- s.sess.handleBroadcast(&msg) }()
98+ c.Check(takeNext(s.downCh), Equals, "deadline 1ms")
99+ c.Check(takeNext(s.downCh), Equals, protocol.AckMsg{"ack"})
100+ s.upCh <- nil // ack ok
101+ c.Check(<-s.errCh, Equals, nil)
102+ c.Assert(len(s.sess.MsgCh), Equals, 1)
103+ c.Check(<-s.sess.MsgCh, Equals, &Notification{})
104+ // and finally, the session keeps track of the levels
105+ c.Check(s.sess.Levels.GetAll(), DeepEquals, map[string]int64{"0": 2})
106+}
107+
108+func (s *msgSuite) TestHandleBroadcastBadAckWrite(c *C) {
109+ msg := serverMsg{"broadcast",
110+ protocol.BroadcastMsg{
111+ Type: "broadcast",
112+ AppId: "APP",
113+ ChanId: "0",
114+ TopLevel: 2,
115+ Payloads: []json.RawMessage{json.RawMessage(`{"b":1}`)},
116+ }, protocol.NotificationsMsg{}}
117+ go func() { s.errCh <- s.sess.handleBroadcast(&msg) }()
118+ c.Check(takeNext(s.downCh), Equals, "deadline 1ms")
119+ c.Check(takeNext(s.downCh), Equals, protocol.AckMsg{"ack"})
120+ failure := errors.New("ACK ACK ACK")
121+ s.upCh <- failure
122+ c.Assert(<-s.errCh, Equals, failure)
123+}
124+
125+func (s *msgSuite) TestHandleBroadcastWrongChannel(c *C) {
126+ msg := serverMsg{"broadcast",
127+ protocol.BroadcastMsg{
128+ Type: "broadcast",
129+ AppId: "APP",
130+ ChanId: "something awful",
131+ TopLevel: 2,
132+ Payloads: []json.RawMessage{json.RawMessage(`{"b":1}`)},
133+ }, protocol.NotificationsMsg{}}
134+ go func() { s.errCh <- s.sess.handleBroadcast(&msg) }()
135+ c.Check(takeNext(s.downCh), Equals, "deadline 1ms")
136+ c.Check(takeNext(s.downCh), Equals, protocol.AckMsg{"ack"})
137+ s.upCh <- nil // ack ok
138+ c.Check(<-s.errCh, IsNil)
139+ c.Check(len(s.sess.MsgCh), Equals, 0)
140+}

Subscribers

People subscribed via source and target branches