Merge lp:~pedronis/ubuntu-push/robust-tests-1.3 into lp:ubuntu-push

Proposed by Samuele Pedroni
Status: Superseded
Proposed branch: lp:~pedronis/ubuntu-push/robust-tests-1.3
Merge into: lp:ubuntu-push
Diff against target: 841 lines (+219/-90)
19 files modified
.precommit (+21/-19)
PACKAGE_DEPS (+1/-0)
client/service/service.go (+2/-0)
client/service/service_test.go (+28/-5)
client/session/session.go (+3/-3)
client/session/session_test.go (+5/-5)
debian/config.json (+1/-1)
docs/_common.txt (+43/-0)
docs/example-client/main.qml (+34/-17)
docs/example-client/manifest.json (+1/-1)
docs/lowlevel.txt (+2/-0)
launch_helper/kindpool.go (+3/-2)
launch_helper/legacy/legacy.go (+3/-4)
messaging/messaging_test.go (+14/-7)
server/acceptance/suites/helpers.go (+7/-6)
server/api/handlers.go (+15/-1)
server/api/handlers_test.go (+22/-6)
server/broker/testsuite/suite.go (+11/-11)
server/listener/listener_test.go (+3/-2)
To merge this branch: bzr merge lp:~pedronis/ubuntu-push/robust-tests-1.3
Reviewer Review Type Date Requested Status
Ubuntu Push Hackers Pending
Review via email: mp+242827@code.launchpad.net

Commit message

make tests more robust in the face of 1.3

Description of the change

make tests more robust in the face of 1.3

- avoid map order issues
- -race slows down some tests so that small timeouts were problematic => increase timeout
- Reader Read can return data and EOF error together => use helpers

To post a comment you must log in.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.precommit'
--- .precommit 2014-01-23 10:03:39 +0000
+++ .precommit 2014-11-25 18:40:27 +0000
@@ -5,25 +5,27 @@
5# And put this here-document in ~/.bazaar/plugins/precommit_script.py:5# And put this here-document in ~/.bazaar/plugins/precommit_script.py:
6<<EOF6<<EOF
7import os7import os
8import subprocess8
9from bzrlib.mutabletree import MutableTree9if not os.getenv("SKIP_COMMIT_HOOK"):
10from bzrlib import errors10 import subprocess
1111 from bzrlib.mutabletree import MutableTree
12def start_commit_hook(*_):12 from bzrlib import errors
13 """This hook will execute '.precommit' script from root path of the bazaar13
14 branch. Commit will be canceled if precommit fails."""14 def start_commit_hook(*_):
1515 """This hook will execute '.precommit' script from root path of the bazaar
16 # this hook only makes sense if a precommit file exist.16 branch. Commit will be canceled if precommit fails."""
17 if not os.path.exists(".precommit"):17
18 return18 # this hook only makes sense if a precommit file exist.
19 try:19 if not os.path.exists(".precommit"):
20 subprocess.check_call(os.path.abspath(".precommit"))20 return
21 # if precommit fails (process return not zero) cancel commit.21 try:
22 except subprocess.CalledProcessError:22 subprocess.check_call(os.path.abspath(".precommit"))
23 raise errors.BzrError("pre commit check failed.")23 # if precommit fails (process return not zero) cancel commit.
2424 except subprocess.CalledProcessError:
25MutableTree.hooks.install_named_hook('start_commit', start_commit_hook,25 raise errors.BzrError("pre commit check failed (set SKIP_COMMIT_HOOK to skip).")
26 'Run "precommit" script on start_commit')26
27 MutableTree.hooks.install_named_hook('start_commit', start_commit_hook,
28 'Run "precommit" script on start_commit')
27EOF29EOF
2830
29make check-format # or whatever31make check-format # or whatever
3032
=== modified file 'PACKAGE_DEPS'
--- PACKAGE_DEPS 2014-09-05 10:48:36 +0000
+++ PACKAGE_DEPS 2014-11-25 18:40:27 +0000
@@ -12,3 +12,4 @@
12libclick-0.4-dev12libclick-0.4-dev
13liburl-dispatcher1-dev13liburl-dispatcher1-dev
14libaccounts-glib-dev14libaccounts-glib-dev
15system-image-dbus
1516
=== modified file 'client/service/service.go'
--- client/service/service.go 2014-11-03 13:36:00 +0000
+++ client/service/service.go 2014-11-25 18:40:27 +0000
@@ -140,6 +140,8 @@
140 case resp.StatusCode >= http.StatusInternalServerError:140 case resp.StatusCode >= http.StatusInternalServerError:
141 // XXX retry on 503141 // XXX retry on 503
142 return nil, ErrBadServer142 return nil, ErrBadServer
143 case resp.StatusCode == http.StatusUnauthorized:
144 return nil, ErrBadAuth
143 default:145 default:
144 return nil, ErrBadRequest146 return nil, ErrBadRequest
145 }147 }
146148
=== modified file 'client/service/service_test.go'
--- client/service/service_test.go 2014-08-06 09:01:59 +0000
+++ client/service/service_test.go 2014-11-25 18:40:27 +0000
@@ -19,6 +19,7 @@
19import (19import (
20 "encoding/json"20 "encoding/json"
21 "fmt"21 "fmt"
22 "io"
22 "net/http"23 "net/http"
23 "net/http/httptest"24 "net/http/httptest"
24 "os"25 "os"
@@ -179,7 +180,8 @@
179func (ss *serviceSuite) TestRegistrationWorks(c *C) {180func (ss *serviceSuite) TestRegistrationWorks(c *C) {
180 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {181 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
181 buf := make([]byte, 256)182 buf := make([]byte, 256)
182 n, e := r.Body.Read(buf)183 n := r.ContentLength
184 _, e := io.ReadFull(r.Body, buf[:n])
183 c.Assert(e, IsNil)185 c.Assert(e, IsNil)
184 req := registrationRequest{}186 req := registrationRequest{}
185 c.Assert(json.Unmarshal(buf[:n], &req), IsNil)187 c.Assert(json.Unmarshal(buf[:n], &req), IsNil)
@@ -240,6 +242,23 @@
240 c.Check(err, ErrorMatches, "unable to request registration: .*")242 c.Check(err, ErrorMatches, "unable to request registration: .*")
241}243}
242244
245func (ss *serviceSuite) TestManageRegFailsOn401(c *C) {
246 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
247 http.Error(w, "Unauthorized", 401)
248 }))
249 defer ts.Close()
250 setup := &PushServiceSetup{
251 DeviceId: "fake-device-id",
252 RegURL: helpers.ParseURL(ts.URL),
253 AuthGetter: func(string) string { return "tok" },
254 }
255 svc := NewPushService(setup, ss.log)
256 svc.Bus = ss.bus
257 reg, err := svc.register(aPackageOnBus, []interface{}{anAppId}, nil)
258 c.Check(err, Equals, ErrBadAuth)
259 c.Check(reg, IsNil)
260}
261
243func (ss *serviceSuite) TestManageRegFailsOn40x(c *C) {262func (ss *serviceSuite) TestManageRegFailsOn40x(c *C) {
244 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {263 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
245 http.Error(w, "I'm a teapot", 418)264 http.Error(w, "I'm a teapot", 418)
@@ -277,7 +296,8 @@
277func (ss *serviceSuite) TestManageRegFailsOnBadJSON(c *C) {296func (ss *serviceSuite) TestManageRegFailsOnBadJSON(c *C) {
278 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {297 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
279 buf := make([]byte, 256)298 buf := make([]byte, 256)
280 n, e := r.Body.Read(buf)299 n := r.ContentLength
300 _, e := io.ReadFull(r.Body, buf[:n])
281 c.Assert(e, IsNil)301 c.Assert(e, IsNil)
282 req := registrationRequest{}302 req := registrationRequest{}
283 c.Assert(json.Unmarshal(buf[:n], &req), IsNil)303 c.Assert(json.Unmarshal(buf[:n], &req), IsNil)
@@ -303,7 +323,8 @@
303func (ss *serviceSuite) TestManageRegFailsOnBadJSONDocument(c *C) {323func (ss *serviceSuite) TestManageRegFailsOnBadJSONDocument(c *C) {
304 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {324 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
305 buf := make([]byte, 256)325 buf := make([]byte, 256)
306 n, e := r.Body.Read(buf)326 n := r.ContentLength
327 _, e := io.ReadFull(r.Body, buf[:n])
307 c.Assert(e, IsNil)328 c.Assert(e, IsNil)
308 req := registrationRequest{}329 req := registrationRequest{}
309 c.Assert(json.Unmarshal(buf[:n], &req), IsNil)330 c.Assert(json.Unmarshal(buf[:n], &req), IsNil)
@@ -329,7 +350,8 @@
329func (ss *serviceSuite) TestDBusUnregisterWorks(c *C) {350func (ss *serviceSuite) TestDBusUnregisterWorks(c *C) {
330 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {351 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
331 buf := make([]byte, 256)352 buf := make([]byte, 256)
332 n, e := r.Body.Read(buf)353 n := r.ContentLength
354 _, e := io.ReadFull(r.Body, buf[:n])
333 c.Assert(e, IsNil)355 c.Assert(e, IsNil)
334 req := registrationRequest{}356 req := registrationRequest{}
335 c.Assert(json.Unmarshal(buf[:n], &req), IsNil)357 c.Assert(json.Unmarshal(buf[:n], &req), IsNil)
@@ -356,7 +378,8 @@
356 invoked := make(chan bool, 1)378 invoked := make(chan bool, 1)
357 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {379 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
358 buf := make([]byte, 256)380 buf := make([]byte, 256)
359 n, e := r.Body.Read(buf)381 n := r.ContentLength
382 _, e := io.ReadFull(r.Body, buf[:n])
360 c.Assert(e, IsNil)383 c.Assert(e, IsNil)
361 req := registrationRequest{}384 req := registrationRequest{}
362 c.Assert(json.Unmarshal(buf[:n], &req), IsNil)385 c.Assert(json.Unmarshal(buf[:n], &req), IsNil)
363386
=== modified file 'client/session/session.go'
--- client/session/session.go 2014-11-03 13:36:00 +0000
+++ client/session/session.go 2014-11-25 18:40:27 +0000
@@ -430,7 +430,7 @@
430 return err430 return err
431 }431 }
432 sess.clearShouldDelay()432 sess.clearShouldDelay()
433 sess.Log.Debugf("broadcast chan:%v app:%v topLevel:%d payloads:%s",433 sess.Log.Infof("broadcast chan:%v app:%v topLevel:%d payloads:%s",
434 bcast.ChanId, bcast.AppId, bcast.TopLevel, bcast.Payloads)434 bcast.ChanId, bcast.AppId, bcast.TopLevel, bcast.Payloads)
435 if bcast.ChanId == protocol.SystemChannelId {435 if bcast.ChanId == protocol.SystemChannelId {
436 // the system channel id, the only one we care about for now436 // the system channel id, the only one we care about for now
@@ -438,7 +438,7 @@
438 sess.BroadcastCh <- sess.decodeBroadcast(bcast)438 sess.BroadcastCh <- sess.decodeBroadcast(bcast)
439 sess.Log.Debugf("sent bcast over")439 sess.Log.Debugf("sent bcast over")
440 } else {440 } else {
441 sess.Log.Debugf("what is this weird channel, %#v?", bcast.ChanId)441 sess.Log.Errorf("what is this weird channel, %#v?", bcast.ChanId)
442 }442 }
443 return nil443 return nil
444}444}
@@ -468,7 +468,7 @@
468 if to == nil {468 if to == nil {
469 continue469 continue
470 }470 }
471 sess.Log.Debugf("unicast app:%v msg:%s payload:%s",471 sess.Log.Infof("unicast app:%v msg:%s payload:%s",
472 notif.AppId, notif.MsgId, notif.Payload)472 notif.AppId, notif.MsgId, notif.Payload)
473 sess.Log.Debugf("sending ucast over")473 sess.Log.Debugf("sending ucast over")
474 sess.NotificationsCh <- AddressedNotification{to, notif}474 sess.NotificationsCh <- AddressedNotification{to, notif}
475475
=== modified file 'client/session/session_test.go'
--- client/session/session_test.go 2014-11-03 13:36:00 +0000
+++ client/session/session_test.go 2014-11-25 18:40:27 +0000
@@ -1480,7 +1480,7 @@
1480}1480}
14811481
1482var (1482var (
1483 dialTestTimeout = 100 * time.Millisecond1483 dialTestTimeout = 300 * time.Millisecond
1484 dialTestConf = ClientSessionConfig{1484 dialTestConf = ClientSessionConfig{
1485 ExchangeTimeout: dialTestTimeout,1485 ExchangeTimeout: dialTestTimeout,
1486 PEM: helpers.TestCertPEMBlock,1486 PEM: helpers.TestCertPEMBlock,
@@ -1584,7 +1584,7 @@
15841584
1585 // 2. "connect" (but on the fake protcol above! woo)1585 // 2. "connect" (but on the fake protcol above! woo)
15861586
1587 c.Check(takeNext(downCh), Equals, "deadline 100ms")1587 c.Check(takeNext(downCh), Equals, fmt.Sprintf("deadline %v", dialTestTimeout))
1588 _, ok := takeNext(downCh).(protocol.ConnectMsg)1588 _, ok := takeNext(downCh).(protocol.ConnectMsg)
1589 c.Check(ok, Equals, true)1589 c.Check(ok, Equals, true)
1590 upCh <- nil // no error1590 upCh <- nil // no error
@@ -1597,7 +1597,7 @@
1597 // 3. "loop"1597 // 3. "loop"
15981598
1599 // ping works,1599 // ping works,
1600 c.Check(takeNext(downCh), Equals, "deadline 110ms")1600 c.Check(takeNext(downCh), Equals, fmt.Sprintf("deadline %v", dialTestTimeout+10*time.Millisecond))
1601 upCh <- protocol.PingPongMsg{Type: "ping"}1601 upCh <- protocol.PingPongMsg{Type: "ping"}
1602 c.Check(takeNext(downCh), Equals, protocol.PingPongMsg{Type: "pong"})1602 c.Check(takeNext(downCh), Equals, protocol.PingPongMsg{Type: "pong"})
1603 upCh <- nil1603 upCh <- nil
@@ -1613,7 +1613,7 @@
1613 TopLevel: 2,1613 TopLevel: 2,
1614 Payloads: []json.RawMessage{json.RawMessage(`{"b":1}`)},1614 Payloads: []json.RawMessage{json.RawMessage(`{"b":1}`)},
1615 }1615 }
1616 c.Check(takeNext(downCh), Equals, "deadline 110ms")1616 c.Check(takeNext(downCh), Equals, fmt.Sprintf("deadline %v", dialTestTimeout+10*time.Millisecond))
1617 upCh <- b1617 upCh <- b
1618 c.Check(takeNext(downCh), Equals, protocol.AckMsg{"ack"})1618 c.Check(takeNext(downCh), Equals, protocol.AckMsg{"ack"})
1619 upCh <- nil1619 upCh <- nil
@@ -1625,7 +1625,7 @@
1625 c.Check(levels, DeepEquals, map[string]int64{"0": 2})1625 c.Check(levels, DeepEquals, map[string]int64{"0": 2})
16261626
1627 // and ping still work even after that.1627 // and ping still work even after that.
1628 c.Check(takeNext(downCh), Equals, "deadline 110ms")1628 c.Check(takeNext(downCh), Equals, fmt.Sprintf("deadline %v", dialTestTimeout+10*time.Millisecond))
1629 upCh <- protocol.PingPongMsg{Type: "ping"}1629 upCh <- protocol.PingPongMsg{Type: "ping"}
1630 c.Check(takeNext(downCh), Equals, protocol.PingPongMsg{Type: "pong"})1630 c.Check(takeNext(downCh), Equals, protocol.PingPongMsg{Type: "pong"})
1631 failure := errors.New("pongs")1631 failure := errors.New("pongs")
16321632
=== modified file 'debian/config.json'
--- debian/config.json 2014-08-21 10:47:12 +0000
+++ debian/config.json 2014-11-25 18:40:27 +0000
@@ -12,7 +12,7 @@
12 "recheck_timeout": "10m",12 "recheck_timeout": "10m",
13 "connectivity_check_url": "http://start.ubuntu.com/connectivity-check.html",13 "connectivity_check_url": "http://start.ubuntu.com/connectivity-check.html",
14 "connectivity_check_md5": "4589f42e1546aa47ca181e5d949d310b",14 "connectivity_check_md5": "4589f42e1546aa47ca181e5d949d310b",
15 "log_level": "debug",15 "log_level": "info",
16 "fallback_vibration": {"pattern": [100, 100], "repeat": 2},16 "fallback_vibration": {"pattern": [100, 100], "repeat": 2},
17 "fallback_sound": "sounds/ubuntu/notifications/Slick.ogg",17 "fallback_sound": "sounds/ubuntu/notifications/Slick.ogg",
18 "poll_interval": "5m",18 "poll_interval": "5m",
1919
=== modified file 'docs/_common.txt'
--- docs/_common.txt 2014-10-09 16:06:52 +0000
+++ docs/_common.txt 2014-11-25 18:40:27 +0000
@@ -185,3 +185,46 @@
185:clear_pending: Discards all previous pending notifications. Usually in response to getting a "too-many-pending" error.185:clear_pending: Discards all previous pending notifications. Usually in response to getting a "too-many-pending" error.
186:replace_tag: If there's a pending notification with the same tag, delete it before queuing this new one.186:replace_tag: If there's a pending notification with the same tag, delete it before queuing this new one.
187:data: A JSON object.187:data: A JSON object.
188
189Limitations of the Server API
190-----------------------------
191
192The push notification infrastructure is meant to help ensuring timely
193delivery of application notifications if the device is online or
194timely informing the device user about application notifications that
195were pending when the device comes back online. This in the face of
196applications not being allowed to be running all the time, and
197avoiding the resource cost of many applications all polling different services
198frequently.
199
200The push notification infrastructure is architected to guarantee at
201least best-effort with respect to these goals and beyond it, on the
202other end applications should not expect to be able to use and only
203rely on the push notification infrastructure to store application
204messages if they want ensure all their notification or messages are
205delivered, the infrastructure is not intended to be the only long term
206"inbox" storage for an application.
207
208To preserve overall throughput the infrastructure imposes some limits
209on applications:
210
211 * message data payload is limited to 2K
212
213 * when inserted all messages need to specify an expiration date after
214 which they can be dropped and not delivered
215
216 * an application is limited in the number of messages per token
217 (application/user/device combination) that can be undelivered/pending at the
218 same time (100 currently)
219
220replace_tag can be used to implement notifications for which the newest
221one replace the previous one if pending.
222
223clear_pending can be used to be deal with a pending message limit
224reached, possibly substituting the current undelivered messages with a
225more generic one.
226
227Applications using the push notification HTTP API should be robust
228against receiving 503 errors, retrying after waiting with increasing
229back-off. Later rate limits (signaled with the 429 status) may also come
230into play.
188231
=== modified file 'docs/example-client/main.qml'
--- docs/example-client/main.qml 2014-09-10 14:38:40 +0000
+++ docs/example-client/main.qml 2014-11-25 18:40:27 +0000
@@ -26,9 +26,42 @@
26 property alias nickEnabled: nickEdit.enabled26 property alias nickEnabled: nickEdit.enabled
27 }27 }
2828
29 states: [
30 State {
31 name: "no-push-token"
32 when: (pushClient.token == "")
33 PropertyChanges { target: nickEdit; readOnly: true}
34 PropertyChanges { target: nickEdit; focus: true}
35 PropertyChanges { target: messageEdit; enabled: false}
36 PropertyChanges { target: loginButton; enabled: false}
37 PropertyChanges { target: loginButton; text: "Login"}
38 },
39 State {
40 name: "push-token-not-registered"
41 when: ((pushClient.token != "") && (chatClient.registered == false))
42 PropertyChanges { target: nickEdit; readOnly: false}
43 PropertyChanges { target: nickEdit; text: ""}
44 PropertyChanges { target: nickEdit; focus: true}
45 PropertyChanges { target: messageEdit; enabled: false}
46 PropertyChanges { target: loginButton; enabled: true}
47 PropertyChanges { target: loginButton; text: "Login"}
48 },
49 State {
50 name: "registered"
51 when: ((pushClient.token != "") && (chatClient.registered == true))
52 PropertyChanges { target: nickEdit; readOnly: true}
53 PropertyChanges { target: nickEdit; text: "Your nick is " + chatClient.nick}
54 PropertyChanges { target: messageEdit; focus: true}
55 PropertyChanges { target: messageEdit; enabled: true}
56 PropertyChanges { target: loginButton; enabled: true}
57 PropertyChanges { target: loginButton; text: "Logout"}
58 }
59 ]
60
61 state: "no-push-token"
62
29 ChatClient {63 ChatClient {
30 id: chatClient64 id: chatClient
31 onRegisteredChanged: {nickEdit.registered()}
32 onError: {messageList.handle_error(msg)}65 onError: {messageList.handle_error(msg)}
33 token: pushClient.token66 token: pushClient.token
34 }67 }
@@ -44,7 +77,6 @@
4477
45 TextField {78 TextField {
46 id: nickEdit79 id: nickEdit
47 focus: true
48 placeholderText: "Your nickname"80 placeholderText: "Your nickname"
49 inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText | Qt.ImhPreferLowercase81 inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText | Qt.ImhPreferLowercase
50 anchors.left: parent.left82 anchors.left: parent.left
@@ -53,31 +85,17 @@
53 anchors.leftMargin: units.gu(.5)85 anchors.leftMargin: units.gu(.5)
54 anchors.rightMargin: units.gu(1)86 anchors.rightMargin: units.gu(1)
55 anchors.topMargin: units.gu(.5)87 anchors.topMargin: units.gu(.5)
56 function registered() {
57 readOnly = true
58 text = "Your nick is " + chatClient.nick
59 messageEdit.focus = true
60 messageEdit.enabled = true
61 loginButton.text = "Logout"
62 }
63 onAccepted: { loginButton.clicked() }88 onAccepted: { loginButton.clicked() }
64 }89 }
6590
66 Button {91 Button {
67 id: loginButton92 id: loginButton
68 text: chatClient.rgistered? "Logout": "Login"
69 anchors.top: nickEdit.top93 anchors.top: nickEdit.top
70 anchors.right: parent.right94 anchors.right: parent.right
71 anchors.rightMargin: units.gu(.5)95 anchors.rightMargin: units.gu(.5)
72 onClicked: {96 onClicked: {
73 if (chatClient.nick) { // logout97 if (chatClient.nick) { // logout
74 chatClient.nick = ""98 chatClient.nick = ""
75 text = "Login"
76 nickEdit.enabled = true
77 nickEdit.readOnly = false
78 nickEdit.text = ""
79 nickEdit.focus = true
80 messageEdit.enabled = false
81 } else { // login99 } else { // login
82 chatClient.nick = nickEdit.text100 chatClient.nick = nickEdit.text
83 }101 }
@@ -94,7 +112,6 @@
94 anchors.rightMargin: units.gu(.5)112 anchors.rightMargin: units.gu(.5)
95 anchors.leftMargin: units.gu(.5)113 anchors.leftMargin: units.gu(.5)
96 placeholderText: "Your message"114 placeholderText: "Your message"
97 enabled: false
98 onAccepted: {115 onAccepted: {
99 console.log("sending " + text)116 console.log("sending " + text)
100 var idx = text.indexOf(":")117 var idx = text.indexOf(":")
101118
=== modified file 'docs/example-client/manifest.json'
--- docs/example-client/manifest.json 2014-09-10 14:38:31 +0000
+++ docs/example-client/manifest.json 2014-11-25 18:40:27 +0000
@@ -15,5 +15,5 @@
15 "maintainer": "Roberto Alsina <roberto.alsina@canonical.com>",15 "maintainer": "Roberto Alsina <roberto.alsina@canonical.com>",
16 "name": "com.ubuntu.developer.ralsina.hello",16 "name": "com.ubuntu.developer.ralsina.hello",
17 "title": "Hello",17 "title": "Hello",
18 "version": "0.4.2"18 "version": "0.4.3"
19}19}
2020
=== modified file 'docs/lowlevel.txt'
--- docs/lowlevel.txt 2014-10-15 16:34:25 +0000
+++ docs/lowlevel.txt 2014-11-25 18:40:27 +0000
@@ -57,6 +57,8 @@
57The Register method takes as argument the APP_ID (in the example, com.ubuntu.music_music) and returns a token identifying the user57The Register method takes as argument the APP_ID (in the example, com.ubuntu.music_music) and returns a token identifying the user
58and device. For this to succeed the user **must** have an Ubuntu One account configured in the device.58and device. For this to succeed the user **must** have an Ubuntu One account configured in the device.
5959
60In the case the Register method returns a "bad auth" error, the application should inform the user to generate new Ubuntu One tokens.
61
60The APP_ID is as described in the `ApplicationId documentation <https://wiki.ubuntu.com/AppStore/Interfaces/ApplicationId>`__62The APP_ID is as described in the `ApplicationId documentation <https://wiki.ubuntu.com/AppStore/Interfaces/ApplicationId>`__
61except that the version is treated as optional. Therefore both ``com.ubuntu.music_music`` and ``com.ubuntu.music_music_1.3.496``63except that the version is treated as optional. Therefore both ``com.ubuntu.music_music`` and ``com.ubuntu.music_music_1.3.496``
62are valid. Keep in mind that while both versioned and unversioned APP_IDs are valid, they are still different and will affect64are valid. Keep in mind that while both versioned and unversioned APP_IDs are valid, they are still different and will affect
6365
=== modified file 'launch_helper/kindpool.go'
--- launch_helper/kindpool.go 2014-08-20 12:42:51 +0000
+++ launch_helper/kindpool.go 2014-11-25 18:40:27 +0000
@@ -294,12 +294,13 @@
294 }294 }
295 payload, err := ioutil.ReadFile(args.FileOut)295 payload, err := ioutil.ReadFile(args.FileOut)
296 if err != nil {296 if err != nil {
297 pool.log.Errorf("unable to read output from helper: %v", err)297 pool.log.Errorf("unable to read output from %v helper: %v", args.AppId, err)
298 } else {298 } else {
299 pool.log.Infof("%v helper output: %#v", args.AppId, payload)
299 res := &HelperResult{Input: args.Input}300 res := &HelperResult{Input: args.Input}
300 err = json.Unmarshal(payload, &res.HelperOutput)301 err = json.Unmarshal(payload, &res.HelperOutput)
301 if err != nil {302 if err != nil {
302 pool.log.Debugf("failed to parse HelperOutput from helper output: %v", err)303 pool.log.Errorf("failed to parse HelperOutput from %v helper output: %v", args.AppId, err)
303 } else {304 } else {
304 pool.chOut <- res305 pool.chOut <- res
305 }306 }
306307
=== modified file 'launch_helper/legacy/legacy.go'
--- launch_helper/legacy/legacy.go 2014-08-21 18:03:49 +0000
+++ launch_helper/legacy/legacy.go 2014-11-25 18:40:27 +0000
@@ -55,7 +55,7 @@
55 err error55 err error
56}56}
5757
58func (lhl *legacyHelperLauncher) Launch(_, progname, f1, f2 string) (string, error) {58func (lhl *legacyHelperLauncher) Launch(appId, progname, f1, f2 string) (string, error) {
59 comm := make(chan msg)59 comm := make(chan msg)
6060
61 go func() {61 go func() {
@@ -78,9 +78,8 @@
78 p_err := cmd.Wait()78 p_err := cmd.Wait()
79 if p_err != nil {79 if p_err != nil {
80 // Helper failed or got killed, log output/errors80 // Helper failed or got killed, log output/errors
81 lhl.log.Errorf("Legacy helper failed: %v", p_err)81 lhl.log.Errorf("Legacy helper failed: appId: %v, helper: %v, pid: %v, error: %v, stdout: %#v, stderr: %#v.",
82 lhl.log.Errorf("Legacy helper failed. Stdout: %s", stdout)82 appId, progname, id, p_err, stdout.String(), stderr.String())
83 lhl.log.Errorf("Legacy helper failed. Stderr: %s", stderr)
84 }83 }
85 lhl.done(id)84 lhl.done(id)
86 }()85 }()
8786
=== modified file 'messaging/messaging_test.go'
--- messaging/messaging_test.go 2014-07-27 02:54:40 +0000
+++ messaging/messaging_test.go 2014-11-25 18:40:27 +0000
@@ -17,6 +17,7 @@
17package messaging17package messaging
1818
19import (19import (
20 "sort"
20 "time"21 "time"
2122
22 . "launchpad.net/gocheck"23 . "launchpad.net/gocheck"
@@ -121,6 +122,12 @@
121 c.Check(payload.Actions[1], Equals, "action-1")122 c.Check(payload.Actions[1], Equals, "action-1")
122}123}
123124
125func (msg *MessagingSuite) checkTags(c *C, got, expected []string) {
126 sort.Strings(got)
127 sort.Strings(expected)
128 c.Check(got, DeepEquals, expected)
129}
130
124func (ms *MessagingSuite) TestTagsListsTags(c *C) {131func (ms *MessagingSuite) TestTagsListsTags(c *C) {
125 mmu := New(ms.log)132 mmu := New(ms.log)
126 f := func(s string) *launch_helper.Notification {133 f := func(s string) *launch_helper.Notification {
@@ -130,15 +137,15 @@
130137
131 c.Check(mmu.Tags(ms.app), IsNil)138 c.Check(mmu.Tags(ms.app), IsNil)
132 c.Assert(mmu.Present(ms.app, "notif1", f("one")), Equals, true)139 c.Assert(mmu.Present(ms.app, "notif1", f("one")), Equals, true)
133 c.Check(mmu.Tags(ms.app), DeepEquals, []string{"one"})140 ms.checkTags(c, mmu.Tags(ms.app), []string{"one"})
134 c.Assert(mmu.Present(ms.app, "notif2", f("")), Equals, true)141 c.Assert(mmu.Present(ms.app, "notif2", f("")), Equals, true)
135 c.Check(mmu.Tags(ms.app), DeepEquals, []string{"one", ""})142 ms.checkTags(c, mmu.Tags(ms.app), []string{"one", ""})
136 // and an empty notification doesn't count143 // and an empty notification doesn't count
137 c.Assert(mmu.Present(ms.app, "notif3", &launch_helper.Notification{Tag: "X"}), Equals, false)144 c.Assert(mmu.Present(ms.app, "notif3", &launch_helper.Notification{Tag: "X"}), Equals, false)
138 c.Check(mmu.Tags(ms.app), DeepEquals, []string{"one", ""})145 ms.checkTags(c, mmu.Tags(ms.app), []string{"one", ""})
139 // and they go away if we remove one146 // and they go away if we remove one
140 mmu.RemoveNotification("notif1", false)147 mmu.RemoveNotification("notif1", false)
141 c.Check(mmu.Tags(ms.app), DeepEquals, []string{""})148 ms.checkTags(c, mmu.Tags(ms.app), []string{""})
142 mmu.RemoveNotification("notif2", false)149 mmu.RemoveNotification("notif2", false)
143 c.Check(mmu.Tags(ms.app), IsNil)150 c.Check(mmu.Tags(ms.app), IsNil)
144}151}
@@ -169,9 +176,9 @@
169 // app 1: "one", "two", "";176 // app 1: "one", "two", "";
170 // app 2: "one", "two";177 // app 2: "one", "two";
171 // app 3: "one", ""178 // app 3: "one", ""
172 c.Assert(mm.Tags(app1), DeepEquals, []string{"one", "two", ""})179 ms.checkTags(c, mm.Tags(app1), []string{"one", "two", ""})
173 c.Assert(mm.Tags(app2), DeepEquals, []string{"one", "two"})180 ms.checkTags(c, mm.Tags(app2), []string{"one", "two"})
174 c.Assert(mm.Tags(app3), DeepEquals, []string{"one", ""})181 ms.checkTags(c, mm.Tags(app3), []string{"one", ""})
175182
176 // clearing a non-existent tag does nothing183 // clearing a non-existent tag does nothing
177 c.Check(mm.Clear(app1, "foo"), Equals, 0)184 c.Check(mm.Clear(app1, "foo"), Equals, 0)
178185
=== modified file 'server/acceptance/suites/helpers.go'
--- server/acceptance/suites/helpers.go 2014-07-08 15:08:52 +0000
+++ server/acceptance/suites/helpers.go 2014-11-25 18:40:27 +0000
@@ -127,6 +127,11 @@
127 c.Log(info)127 c.Log(info)
128 continue128 continue
129 }129 }
130 if strings.HasPrefix(info, "DEBUG ") && !strings.HasPrefix(info, "DEBUG session(") {
131 // skip non session DEBUG logs
132 c.Log(info)
133 continue
134 }
130 logs <- info135 logs <- info
131 }136 }
132 }()137 }()
@@ -136,16 +141,12 @@
136const (141const (
137 DevListeningOnPat = "INFO listening for devices on "142 DevListeningOnPat = "INFO listening for devices on "
138 HTTPListeningOnPat = "INFO listening for http on "143 HTTPListeningOnPat = "INFO listening for http on "
139 debugPrefix = "DEBUG "
140)144)
141145
142// ExtractListeningAddr goes over logs ignoring DEBUG lines146// ExtractListeningAddr goes over logs until a line starting with pat
143// until a line starting with pat and returns the rest of that line.147// and returns the rest of that line.
144func ExtractListeningAddr(c *C, logs <-chan string, pat string) string {148func ExtractListeningAddr(c *C, logs <-chan string, pat string) string {
145 for line := range logs {149 for line := range logs {
146 if strings.HasPrefix(line, debugPrefix) {
147 continue
148 }
149 if !strings.HasPrefix(line, pat) {150 if !strings.HasPrefix(line, pat) {
150 c.Fatalf("matching %v: %v", pat, line)151 c.Fatalf("matching %v: %v", pat, line)
151 }152 }
152153
=== modified file 'server/api/handlers.go'
--- server/api/handlers.go 2014-07-14 15:23:17 +0000
+++ server/api/handlers.go 2014-11-25 18:40:27 +0000
@@ -23,6 +23,7 @@
23 "encoding/json"23 "encoding/json"
24 "fmt"24 "fmt"
25 "io"25 "io"
26 "mime"
26 "net/http"27 "net/http"
27 "time"28 "time"
2829
@@ -98,6 +99,12 @@
98 "Wrong request method, should be POST",99 "Wrong request method, should be POST",
99 nil,100 nil,
100 }101 }
102 ErrWrongRequestMethodGET = &APIError{
103 http.StatusMethodNotAllowed,
104 invalidRequest,
105 "Wrong request method, should be GET",
106 nil,
107 }
101 ErrMalformedJSONObject = &APIError{108 ErrMalformedJSONObject = &APIError{
102 http.StatusBadRequest,109 http.StatusBadRequest,
103 invalidRequest,110 invalidRequest,
@@ -268,7 +275,8 @@
268 if err := checkContentLength(request, maxBodySize); err != nil {275 if err := checkContentLength(request, maxBodySize); err != nil {
269 return err276 return err
270 }277 }
271 if request.Header.Get("Content-Type") != JSONMediaType {278 mediaType, _, err := mime.ParseMediaType(request.Header.Get("Content-Type"))
279 if err != nil || mediaType != JSONMediaType {
272 return ErrWrongContentType280 return ErrWrongContentType
273 }281 }
274 return nil282 return nil
@@ -452,14 +460,17 @@
452 if err != nil {460 if err != nil {
453 switch err {461 switch err {
454 case store.ErrUnknownToken:462 case store.ErrUnknownToken:
463 ctx.logger.Debugf("notify: %v %v unknown", ucast.AppId, ucast.Token)
455 return nil, ErrUnknownToken464 return nil, ErrUnknownToken
456 case store.ErrUnauthorized:465 case store.ErrUnauthorized:
466 ctx.logger.Debugf("notify: %v %v unauthorized", ucast.AppId, ucast.Token)
457 return nil, ErrUnauthorized467 return nil, ErrUnauthorized
458 default:468 default:
459 ctx.logger.Errorf("could not resolve token: %v", err)469 ctx.logger.Errorf("could not resolve token: %v", err)
460 return nil, ErrCouldNotResolveToken470 return nil, ErrCouldNotResolveToken
461 }471 }
462 }472 }
473 ctx.logger.Debugf("notify: %v %v -> %v", ucast.AppId, ucast.Token, chanId)
463474
464 _, notifs, meta, err := sto.GetChannelUnfiltered(chanId)475 _, notifs, meta, err := sto.GetChannelUnfiltered(chanId)
465 if err != nil {476 if err != nil {
@@ -491,6 +502,7 @@
491 if ucast.ClearPending {502 if ucast.ClearPending {
492 scrubCriteria = []string{ucast.AppId}503 scrubCriteria = []string{ucast.AppId}
493 } else if forApp >= ctx.storage.GetMaxNotificationsPerApplication() {504 } else if forApp >= ctx.storage.GetMaxNotificationsPerApplication() {
505 ctx.logger.Debugf("notify: %v %v too many pending", ucast.AppId, chanId)
494 return nil, apiErrorWithExtra(ErrTooManyPendingNotifications,506 return nil, apiErrorWithExtra(ErrTooManyPendingNotifications,
495 &last.Payload)507 &last.Payload)
496 } else if replaceable > 0 {508 } else if replaceable > 0 {
@@ -518,6 +530,8 @@
518 }530 }
519531
520 ctx.broker.Unicast(chanId)532 ctx.broker.Unicast(chanId)
533
534 ctx.logger.Debugf("notify: ok %v %v id:%v clear:%v replace:%v expired:%v", ucast.AppId, chanId, msgId, ucast.ClearPending, replaceable, expired)
521 return nil, nil535 return nil, nil
522}536}
523537
524538
=== modified file 'server/api/handlers_test.go'
--- server/api/handlers_test.go 2014-07-15 15:03:49 +0000
+++ server/api/handlers_test.go 2014-11-25 18:40:27 +0000
@@ -362,7 +362,7 @@
362 }362 }
363 sto := store.NewInMemoryPendingStore()363 sto := store.NewInMemoryPendingStore()
364 bsend := &checkBrokerSending{store: sto}364 bsend := &checkBrokerSending{store: sto}
365 ctx := &context{testStoreAccess(nil), bsend, nil}365 ctx := &context{testStoreAccess(nil), bsend, s.testlog}
366 payload := json.RawMessage(`{"a": 1}`)366 payload := json.RawMessage(`{"a": 1}`)
367 res, apiErr := doUnicast(ctx, sto, &Unicast{367 res, apiErr := doUnicast(ctx, sto, &Unicast{
368 UserId: "user1",368 UserId: "user1",
@@ -487,7 +487,7 @@
487 sto.AppendToUnicastChannel(chanId, "app1", n, "m4", expire)487 sto.AppendToUnicastChannel(chanId, "app1", n, "m4", expire)
488488
489 bsend := &checkBrokerSending{store: sto}489 bsend := &checkBrokerSending{store: sto}
490 ctx := &context{testStoreAccess(nil), bsend, nil}490 ctx := &context{testStoreAccess(nil), bsend, s.testlog}
491 payload := json.RawMessage(`{"a": 1}`)491 payload := json.RawMessage(`{"a": 1}`)
492 res, apiErr := doUnicast(ctx, sto, &Unicast{492 res, apiErr := doUnicast(ctx, sto, &Unicast{
493 UserId: "user1",493 UserId: "user1",
@@ -528,7 +528,7 @@
528 sto.AppendToUnicastChannel(chanId, "app1", n, "m1", expire)528 sto.AppendToUnicastChannel(chanId, "app1", n, "m1", expire)
529529
530 bsend := &checkBrokerSending{store: sto}530 bsend := &checkBrokerSending{store: sto}
531 ctx := &context{testStoreAccess(nil), bsend, nil}531 ctx := &context{testStoreAccess(nil), bsend, s.testlog}
532 payload := json.RawMessage(`{"a": 1}`)532 payload := json.RawMessage(`{"a": 1}`)
533 res, apiErr := doUnicast(ctx, sto, &Unicast{533 res, apiErr := doUnicast(ctx, sto, &Unicast{
534 UserId: "user1",534 UserId: "user1",
@@ -634,7 +634,7 @@
634 sto.AppendToUnicastChannel(chanId, "app1", n, "m4", expire)634 sto.AppendToUnicastChannel(chanId, "app1", n, "m4", expire)
635635
636 bsend := &checkBrokerSending{store: sto}636 bsend := &checkBrokerSending{store: sto}
637 ctx := &context{testStoreAccess(nil), bsend, nil}637 ctx := &context{testStoreAccess(nil), bsend, s.testlog}
638 payload := json.RawMessage(`{"a": 1}`)638 payload := json.RawMessage(`{"a": 1}`)
639 res, apiErr := doUnicast(ctx, sto, &Unicast{639 res, apiErr := doUnicast(ctx, sto, &Unicast{
640 UserId: "user1",640 UserId: "user1",
@@ -933,6 +933,22 @@
933 checkError(c, response, ErrWrongContentType)933 checkError(c, response, ErrWrongContentType)
934}934}
935935
936func (s *handlersSuite) TestContentTypeWithCharset(c *C) {
937 testServer := httptest.NewServer(&JSONPostHandler{})
938 defer testServer.Close()
939
940 dataString := `{"foo":"bar"}`
941
942 request := newPostRequest("/", &Broadcast{
943 Channel: "some-channel",
944 ExpireOn: future,
945 Data: json.RawMessage([]byte(dataString)),
946 }, testServer)
947 request.Header.Set("Content-Type", "application/json; charset=UTF-8")
948 result := checkRequestAsPost(request, 1024)
949 c.Assert(result, IsNil)
950}
951
936func (s *handlersSuite) TestCannotBroadcastNonPostMessages(c *C) {952func (s *handlersSuite) TestCannotBroadcastNonPostMessages(c *C) {
937 testServer := httptest.NewServer(&JSONPostHandler{})953 testServer := httptest.NewServer(&JSONPostHandler{})
938 defer testServer.Close()954 defer testServer.Close()
@@ -965,7 +981,7 @@
965 return sto, nil981 return sto, nil
966 })982 })
967 bsend := testBrokerSending{make(chan store.InternalChannelId, 1)}983 bsend := testBrokerSending{make(chan store.InternalChannelId, 1)}
968 testServer := httptest.NewServer(MakeHandlersMux(storage, bsend, nil))984 testServer := httptest.NewServer(MakeHandlersMux(storage, bsend, s.testlog))
969 defer testServer.Close()985 defer testServer.Close()
970986
971 payload := json.RawMessage(`{"foo":"bar"}`)987 payload := json.RawMessage(`{"foo":"bar"}`)
@@ -1049,7 +1065,7 @@
1049 return sto, nil1065 return sto, nil
1050 })1066 })
1051 bsend := testBrokerSending{make(chan store.InternalChannelId, 1)}1067 bsend := testBrokerSending{make(chan store.InternalChannelId, 1)}
1052 testServer := httptest.NewServer(MakeHandlersMux(storage, bsend, nil))1068 testServer := httptest.NewServer(MakeHandlersMux(storage, bsend, s.testlog))
1053 defer testServer.Close()1069 defer testServer.Close()
10541070
1055 request := newPostRequest("/register", &Registration{1071 request := newPostRequest("/register", &Registration{
10561072
=== modified file 'server/broker/testsuite/suite.go'
--- server/broker/testsuite/suite.go 2014-09-25 11:16:38 +0000
+++ server/broker/testsuite/suite.go 2014-11-25 18:40:27 +0000
@@ -66,12 +66,12 @@
6666
67func (s *CommonBrokerSuite) TestSanity(c *C) {67func (s *CommonBrokerSuite) TestSanity(c *C) {
68 sto := store.NewInMemoryPendingStore()68 sto := store.NewInMemoryPendingStore()
69 b := s.MakeBroker(sto, testBrokerConfig, nil)69 b := s.MakeBroker(sto, testBrokerConfig, s.testlog)
70 c.Check(s.RevealSession(b, "FOO"), IsNil)70 c.Check(s.RevealSession(b, "FOO"), IsNil)
71}71}
7272
73func (s *CommonBrokerSuite) TestStartStop(c *C) {73func (s *CommonBrokerSuite) TestStartStop(c *C) {
74 b := s.MakeBroker(nil, testBrokerConfig, nil)74 b := s.MakeBroker(nil, testBrokerConfig, s.testlog)
75 b.Start()75 b.Start()
76 c.Check(b.Running(), Equals, true)76 c.Check(b.Running(), Equals, true)
77 b.Start()77 b.Start()
@@ -82,7 +82,7 @@
8282
83func (s *CommonBrokerSuite) TestRegistration(c *C) {83func (s *CommonBrokerSuite) TestRegistration(c *C) {
84 sto := store.NewInMemoryPendingStore()84 sto := store.NewInMemoryPendingStore()
85 b := s.MakeBroker(sto, testBrokerConfig, nil)85 b := s.MakeBroker(sto, testBrokerConfig, s.testlog)
86 b.Start()86 b.Start()
87 defer b.Stop()87 defer b.Stop()
88 sess, err := b.Register(&protocol.ConnectMsg{88 sess, err := b.Register(&protocol.ConnectMsg{
@@ -112,7 +112,7 @@
112112
113func (s *CommonBrokerSuite) TestRegistrationBrokenLevels(c *C) {113func (s *CommonBrokerSuite) TestRegistrationBrokenLevels(c *C) {
114 sto := store.NewInMemoryPendingStore()114 sto := store.NewInMemoryPendingStore()
115 b := s.MakeBroker(sto, testBrokerConfig, nil)115 b := s.MakeBroker(sto, testBrokerConfig, s.testlog)
116 b.Start()116 b.Start()
117 defer b.Stop()117 defer b.Stop()
118 _, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1", Levels: map[string]int64{"z": 5}}, s.MakeTracker("s1"))118 _, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1", Levels: map[string]int64{"z": 5}}, s.MakeTracker("s1"))
@@ -121,7 +121,7 @@
121121
122func (s *CommonBrokerSuite) TestRegistrationInfoErrors(c *C) {122func (s *CommonBrokerSuite) TestRegistrationInfoErrors(c *C) {
123 sto := store.NewInMemoryPendingStore()123 sto := store.NewInMemoryPendingStore()
124 b := s.MakeBroker(sto, testBrokerConfig, nil)124 b := s.MakeBroker(sto, testBrokerConfig, s.testlog)
125 b.Start()125 b.Start()
126 defer b.Stop()126 defer b.Stop()
127 info := map[string]interface{}{127 info := map[string]interface{}{
@@ -140,7 +140,7 @@
140 notification1 := json.RawMessage(`{"m": "M"}`)140 notification1 := json.RawMessage(`{"m": "M"}`)
141 muchLater := time.Now().Add(10 * time.Minute)141 muchLater := time.Now().Add(10 * time.Minute)
142 sto.AppendToChannel(store.SystemInternalChannelId, notification1, muchLater)142 sto.AppendToChannel(store.SystemInternalChannelId, notification1, muchLater)
143 b := s.MakeBroker(sto, testBrokerConfig, nil)143 b := s.MakeBroker(sto, testBrokerConfig, s.testlog)
144 b.Start()144 b.Start()
145 defer b.Stop()145 defer b.Stop()
146 sess, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1"}, s.MakeTracker("s1"))146 sess, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1"}, s.MakeTracker("s1"))
@@ -166,7 +166,7 @@
166166
167func (s *CommonBrokerSuite) TestRegistrationLastWins(c *C) {167func (s *CommonBrokerSuite) TestRegistrationLastWins(c *C) {
168 sto := store.NewInMemoryPendingStore()168 sto := store.NewInMemoryPendingStore()
169 b := s.MakeBroker(sto, testBrokerConfig, nil)169 b := s.MakeBroker(sto, testBrokerConfig, s.testlog)
170 b.Start()170 b.Start()
171 defer b.Stop()171 defer b.Stop()
172 sess1, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1"}, s.MakeTracker("s1"))172 sess1, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1"}, s.MakeTracker("s1"))
@@ -197,7 +197,7 @@
197 sto := store.NewInMemoryPendingStore()197 sto := store.NewInMemoryPendingStore()
198 notification1 := json.RawMessage(`{"m": "M"}`)198 notification1 := json.RawMessage(`{"m": "M"}`)
199 decoded1 := map[string]interface{}{"m": "M"}199 decoded1 := map[string]interface{}{"m": "M"}
200 b := s.MakeBroker(sto, testBrokerConfig, nil)200 b := s.MakeBroker(sto, testBrokerConfig, s.testlog)
201 b.Start()201 b.Start()
202 defer b.Stop()202 defer b.Stop()
203 sess1, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1"}, s.MakeTracker("s1"))203 sess1, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1"}, s.MakeTracker("s1"))
@@ -278,7 +278,7 @@
278 notification2 := json.RawMessage(`{"m": "M2"}`)278 notification2 := json.RawMessage(`{"m": "M2"}`)
279 chanId1 := store.UnicastInternalChannelId("dev1", "dev1")279 chanId1 := store.UnicastInternalChannelId("dev1", "dev1")
280 chanId2 := store.UnicastInternalChannelId("dev2", "dev2")280 chanId2 := store.UnicastInternalChannelId("dev2", "dev2")
281 b := s.MakeBroker(sto, testBrokerConfig, nil)281 b := s.MakeBroker(sto, testBrokerConfig, s.testlog)
282 b.Start()282 b.Start()
283 defer b.Stop()283 defer b.Stop()
284 sess1, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev1"}, s.MakeTracker("s1"))284 sess1, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev1"}, s.MakeTracker("s1"))
@@ -312,7 +312,7 @@
312 sto := store.NewInMemoryPendingStore()312 sto := store.NewInMemoryPendingStore()
313 notification1 := json.RawMessage(`{"m": "M1"}`)313 notification1 := json.RawMessage(`{"m": "M1"}`)
314 chanId1 := store.UnicastInternalChannelId("dev3", "dev3")314 chanId1 := store.UnicastInternalChannelId("dev3", "dev3")
315 b := s.MakeBroker(sto, testBrokerConfig, nil)315 b := s.MakeBroker(sto, testBrokerConfig, s.testlog)
316 b.Start()316 b.Start()
317 defer b.Stop()317 defer b.Stop()
318 sess1, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev3"}, s.MakeTracker("s1"))318 sess1, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev3"}, s.MakeTracker("s1"))
@@ -354,7 +354,7 @@
354354
355func (s *CommonBrokerSuite) TestSessionFeed(c *C) {355func (s *CommonBrokerSuite) TestSessionFeed(c *C) {
356 sto := store.NewInMemoryPendingStore()356 sto := store.NewInMemoryPendingStore()
357 b := s.MakeBroker(sto, testBrokerConfig, nil)357 b := s.MakeBroker(sto, testBrokerConfig, s.testlog)
358 b.Start()358 b.Start()
359 defer b.Stop()359 defer b.Stop()
360 sess1, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev3"}, s.MakeTracker("s1"))360 sess1, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev3"}, s.MakeTracker("s1"))
361361
=== modified file 'server/listener/listener_test.go'
--- server/listener/listener_test.go 2014-09-25 11:20:00 +0000
+++ server/listener/listener_test.go 2014-11-25 18:40:27 +0000
@@ -18,6 +18,7 @@
1818
19import (19import (
20 "crypto/tls"20 "crypto/tls"
21 "io"
21 "net"22 "net"
22 "os/exec"23 "os/exec"
23 "regexp"24 "regexp"
@@ -112,7 +113,7 @@
112 conn.SetDeadline(time.Now().Add(10 * time.Second))113 conn.SetDeadline(time.Now().Add(10 * time.Second))
113 var buf [1]byte114 var buf [1]byte
114 for {115 for {
115 _, err := conn.Read(buf[:])116 _, err := io.ReadFull(conn, buf[:])
116 if err != nil {117 if err != nil {
117 return err118 return err
118 }119 }
@@ -137,7 +138,7 @@
137138
138func testReadByte(c *C, conn net.Conn, expected uint32) {139func testReadByte(c *C, conn net.Conn, expected uint32) {
139 var buf [1]byte140 var buf [1]byte
140 _, err := conn.Read(buf[:])141 _, err := io.ReadFull(conn, buf[:])
141 c.Check(err, IsNil)142 c.Check(err, IsNil)
142 c.Check(buf[0], Equals, byte(expected))143 c.Check(buf[0], Equals, byte(expected))
143}144}

Subscribers

People subscribed via source and target branches