Merge lp:~pedronis/ubuntu-push/broker-testing into lp:ubuntu-push

Proposed by Samuele Pedroni
Status: Merged
Approved by: Samuele Pedroni
Approved revision: 27
Merged at revision: 22
Proposed branch: lp:~pedronis/ubuntu-push/broker-testing
Merge into: lp:ubuntu-push
Prerequisite: lp:~pedronis/ubuntu-push/broker-testsuite
Diff against target: 634 lines (+166/-132)
11 files modified
server/broker/broker.go (+2/-2)
server/broker/broker_test.go (+0/-3)
server/broker/exchanges_test.go (+18/-56)
server/broker/exchg_impl_test.go (+47/-0)
server/broker/simple/simple.go (+1/-1)
server/broker/simple/simple_test.go (+7/-14)
server/broker/testing/impls.go (+60/-0)
server/broker/testsuite/suite.go (+13/-19)
server/session/session_test.go (+15/-35)
server/session/tracker.go (+1/-1)
server/session/tracker_test.go (+2/-1)
To merge this branch: bzr merge lp:~pedronis/ubuntu-push/broker-testing
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Review via email: mp+203003@code.launchpad.net

Commit message

introduce reusable TestBrokerConfig and TestBrokerSession

Description of the change

introduce reusable TestBrokerConfig and TestBrokerSession

To post a comment you must log in.
Revision history for this message
John Lenton (chipaca) wrote :

You know me, I like this kind of branch.
Only thing that would've made it sweeter would've been a testing/impls_test.go

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'server/broker/broker.go'
--- server/broker/broker.go 2014-01-24 08:01:44 +0000
+++ server/broker/broker.go 2014-01-24 08:01:44 +0000
@@ -52,8 +52,8 @@
52 // SessionChannel returns the session control channel52 // SessionChannel returns the session control channel
53 // on which the session gets exchanges to perform.53 // on which the session gets exchanges to perform.
54 SessionChannel() <-chan Exchange54 SessionChannel() <-chan Exchange
55 // DeviceId returns the device id string.55 // DeviceIdentifier returns the device id string.
56 DeviceId() string56 DeviceIdentifier() string
57 // Levels returns the current channel levels for the session57 // Levels returns the current channel levels for the session
58 Levels() LevelsMap58 Levels() LevelsMap
59 // ExchangeScratchArea returns the scratch area for exchanges.59 // ExchangeScratchArea returns the scratch area for exchanges.
6060
=== modified file 'server/broker/broker_test.go'
--- server/broker/broker_test.go 2014-01-15 08:39:04 +0000
+++ server/broker/broker_test.go 2014-01-24 08:01:44 +0000
@@ -19,11 +19,8 @@
19import (19import (
20 "fmt"20 "fmt"
21 . "launchpad.net/gocheck"21 . "launchpad.net/gocheck"
22 "testing"
23)22)
2423
25func TestBroker(t *testing.T) { TestingT(t) }
26
27type brokerSuite struct{}24type brokerSuite struct{}
2825
29var _ = Suite(&brokerSuite{})26var _ = Suite(&brokerSuite{})
3027
=== modified file 'server/broker/exchanges_test.go'
--- server/broker/exchanges_test.go 2014-01-24 08:01:44 +0000
+++ server/broker/exchanges_test.go 2014-01-24 08:01:44 +0000
@@ -14,47 +14,29 @@
14 with this program. If not, see <http://www.gnu.org/licenses/>.14 with this program. If not, see <http://www.gnu.org/licenses/>.
15*/15*/
1616
17package broker17package broker_test // use a package test to avoid cyclic imports
1818
19import (19import (
20 "encoding/json"20 "encoding/json"
21 . "launchpad.net/gocheck"21 . "launchpad.net/gocheck"
22 "launchpad.net/ubuntu-push/server/broker"
23 "launchpad.net/ubuntu-push/server/broker/testing"
22 "launchpad.net/ubuntu-push/server/store"24 "launchpad.net/ubuntu-push/server/store"
23 // "log"25 // "log"
26 gotesting "testing"
24)27)
2528
29func TestBroker(t *gotesting.T) { TestingT(t) }
30
26type exchangesSuite struct{}31type exchangesSuite struct{}
2732
28var _ = Suite(&exchangesSuite{})33var _ = Suite(&exchangesSuite{})
2934
30type testBrokerSession struct {
31 deviceId string
32 exchanges chan Exchange
33 levels LevelsMap
34 exchgScratch ExchangesScratchArea
35}
36
37func (tbs *testBrokerSession) SessionChannel() <-chan Exchange {
38 return nil
39}
40
41func (tbs *testBrokerSession) DeviceId() string {
42 return ""
43}
44
45func (tbs *testBrokerSession) Levels() LevelsMap {
46 return tbs.levels
47}
48
49func (tbs *testBrokerSession) ExchangeScratchArea() *ExchangesScratchArea {
50 return &tbs.exchgScratch
51}
52
53func (s *exchangesSuite) TestBroadcastExchange(c *C) {35func (s *exchangesSuite) TestBroadcastExchange(c *C) {
54 sess := &testBrokerSession{36 sess := &testing.TestBrokerSession{
55 levels: map[store.InternalChannelId]int64{},37 LevelsMap: broker.LevelsMap(map[store.InternalChannelId]int64{}),
56 }38 }
57 exchg := &BroadcastExchange{39 exchg := &broker.BroadcastExchange{
58 ChanId: store.SystemInternalChannelId,40 ChanId: store.SystemInternalChannelId,
59 TopLevel: 3,41 TopLevel: 3,
60 NotificationPayloads: []json.RawMessage{42 NotificationPayloads: []json.RawMessage{
@@ -72,14 +54,14 @@
72 c.Assert(err, IsNil)54 c.Assert(err, IsNil)
73 err = exchg.Acked(sess)55 err = exchg.Acked(sess)
74 c.Assert(err, IsNil)56 c.Assert(err, IsNil)
75 c.Check(sess.levels[store.SystemInternalChannelId], Equals, int64(3))57 c.Check(sess.LevelsMap[store.SystemInternalChannelId], Equals, int64(3))
76}58}
7759
78func (s *exchangesSuite) TestBroadcastExchangeAckMismatch(c *C) {60func (s *exchangesSuite) TestBroadcastExchangeAckMismatch(c *C) {
79 sess := &testBrokerSession{61 sess := &testing.TestBrokerSession{
80 levels: map[store.InternalChannelId]int64{},62 LevelsMap: broker.LevelsMap(map[store.InternalChannelId]int64{}),
81 }63 }
82 exchg := &BroadcastExchange{64 exchg := &broker.BroadcastExchange{
83 ChanId: store.SystemInternalChannelId,65 ChanId: store.SystemInternalChannelId,
84 TopLevel: 3,66 TopLevel: 3,
85 NotificationPayloads: []json.RawMessage{67 NotificationPayloads: []json.RawMessage{
@@ -96,36 +78,16 @@
96 c.Assert(err, IsNil)78 c.Assert(err, IsNil)
97 err = exchg.Acked(sess)79 err = exchg.Acked(sess)
98 c.Assert(err, Not(IsNil))80 c.Assert(err, Not(IsNil))
99 c.Check(sess.levels[store.SystemInternalChannelId], Equals, int64(0))81 c.Check(sess.LevelsMap[store.SystemInternalChannelId], Equals, int64(0))
100}
101
102func (s *exchangesSuite) TestFilterByLevel(c *C) {
103 payloads := []json.RawMessage{
104 json.RawMessage(`{"a": 3}`),
105 json.RawMessage(`{"a": 4}`),
106 json.RawMessage(`{"a": 5}`),
107 }
108 res := filterByLevel(5, 5, payloads)
109 c.Check(len(res), Equals, 0)
110 res = filterByLevel(4, 5, payloads)
111 c.Check(len(res), Equals, 1)
112 c.Check(res[0], DeepEquals, json.RawMessage(`{"a": 5}`))
113 res = filterByLevel(3, 5, payloads)
114 c.Check(len(res), Equals, 2)
115 c.Check(res[0], DeepEquals, json.RawMessage(`{"a": 4}`))
116 res = filterByLevel(2, 5, payloads)
117 c.Check(len(res), Equals, 3)
118 res = filterByLevel(1, 5, payloads)
119 c.Check(len(res), Equals, 3)
120}82}
12183
122func (s *exchangesSuite) TestBroadcastExchangeFilterByLevel(c *C) {84func (s *exchangesSuite) TestBroadcastExchangeFilterByLevel(c *C) {
123 sess := &testBrokerSession{85 sess := &testing.TestBrokerSession{
124 levels: map[store.InternalChannelId]int64{86 LevelsMap: broker.LevelsMap(map[store.InternalChannelId]int64{
125 store.SystemInternalChannelId: 2,87 store.SystemInternalChannelId: 2,
126 },88 }),
127 }89 }
128 exchg := &BroadcastExchange{90 exchg := &broker.BroadcastExchange{
129 ChanId: store.SystemInternalChannelId,91 ChanId: store.SystemInternalChannelId,
130 TopLevel: 3,92 TopLevel: 3,
131 NotificationPayloads: []json.RawMessage{93 NotificationPayloads: []json.RawMessage{
13294
=== added file 'server/broker/exchg_impl_test.go'
--- server/broker/exchg_impl_test.go 1970-01-01 00:00:00 +0000
+++ server/broker/exchg_impl_test.go 2014-01-24 08:01:44 +0000
@@ -0,0 +1,47 @@
1/*
2 Copyright 2013-2014 Canonical Ltd.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License version 3, as published
6 by the Free Software Foundation.
7
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranties of
10 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along
14 with this program. If not, see <http://www.gnu.org/licenses/>.
15*/
16
17package broker
18
19import (
20 "encoding/json"
21 . "launchpad.net/gocheck"
22 // "log"
23)
24
25type exchangesImplSuite struct{}
26
27var _ = Suite(&exchangesImplSuite{})
28
29func (s *exchangesImplSuite) TestFilterByLevel(c *C) {
30 payloads := []json.RawMessage{
31 json.RawMessage(`{"a": 3}`),
32 json.RawMessage(`{"a": 4}`),
33 json.RawMessage(`{"a": 5}`),
34 }
35 res := filterByLevel(5, 5, payloads)
36 c.Check(len(res), Equals, 0)
37 res = filterByLevel(4, 5, payloads)
38 c.Check(len(res), Equals, 1)
39 c.Check(res[0], DeepEquals, json.RawMessage(`{"a": 5}`))
40 res = filterByLevel(3, 5, payloads)
41 c.Check(len(res), Equals, 2)
42 c.Check(res[0], DeepEquals, json.RawMessage(`{"a": 4}`))
43 res = filterByLevel(2, 5, payloads)
44 c.Check(len(res), Equals, 3)
45 res = filterByLevel(1, 5, payloads)
46 c.Check(len(res), Equals, 3)
47}
048
=== modified file 'server/broker/simple/simple.go'
--- server/broker/simple/simple.go 2014-01-24 08:01:44 +0000
+++ server/broker/simple/simple.go 2014-01-24 08:01:44 +0000
@@ -70,7 +70,7 @@
70 return sess.exchanges70 return sess.exchanges
71}71}
7272
73func (sess *simpleBrokerSession) DeviceId() string {73func (sess *simpleBrokerSession) DeviceIdentifier() string {
74 return sess.deviceId74 return sess.deviceId
75}75}
7676
7777
=== modified file 'server/broker/simple/simple_test.go'
--- server/broker/simple/simple_test.go 2014-01-24 08:01:44 +0000
+++ server/broker/simple/simple_test.go 2014-01-24 08:01:44 +0000
@@ -20,30 +20,23 @@
20 "encoding/json"20 "encoding/json"
21 . "launchpad.net/gocheck"21 . "launchpad.net/gocheck"
22 "launchpad.net/ubuntu-push/server/broker"22 "launchpad.net/ubuntu-push/server/broker"
23 "launchpad.net/ubuntu-push/server/broker/testing"
23 "launchpad.net/ubuntu-push/server/store"24 "launchpad.net/ubuntu-push/server/store"
24 // "log"25 // "log"
25 "testing"26 gotesting "testing"
26)27)
2728
28func TestSimple(t *testing.T) { TestingT(t) }29func TestSimple(t *gotesting.T) { TestingT(t) }
2930
30type simpleSuite struct{}31type simpleSuite struct{}
3132
32var _ = Suite(&simpleSuite{})33var _ = Suite(&simpleSuite{})
3334
34type testBrokerConfig struct{}35var testBrokerConfig = &testing.TestBrokerConfig{10, 5}
35
36func (tbc *testBrokerConfig) SessionQueueSize() uint {
37 return 10
38}
39
40func (tbc *testBrokerConfig) BrokerQueueSize() uint {
41 return 5
42}
4336
44func (s *simpleSuite) TestNew(c *C) {37func (s *simpleSuite) TestNew(c *C) {
45 sto := store.NewInMemoryPendingStore()38 sto := store.NewInMemoryPendingStore()
46 b := NewSimpleBroker(sto, &testBrokerConfig{}, nil)39 b := NewSimpleBroker(sto, testBrokerConfig, nil)
47 c.Check(cap(b.sessionCh), Equals, 5)40 c.Check(cap(b.sessionCh), Equals, 5)
48 c.Check(len(b.registry), Equals, 0)41 c.Check(len(b.registry), Equals, 0)
49 c.Check(b.sto, Equals, sto)42 c.Check(b.sto, Equals, sto)
@@ -53,7 +46,7 @@
53 sto := store.NewInMemoryPendingStore()46 sto := store.NewInMemoryPendingStore()
54 notification1 := json.RawMessage(`{"m": "M"}`)47 notification1 := json.RawMessage(`{"m": "M"}`)
55 sto.AppendToChannel(store.SystemInternalChannelId, notification1)48 sto.AppendToChannel(store.SystemInternalChannelId, notification1)
56 b := NewSimpleBroker(sto, &testBrokerConfig{}, nil)49 b := NewSimpleBroker(sto, testBrokerConfig, nil)
57 sess := &simpleBrokerSession{50 sess := &simpleBrokerSession{
58 exchanges: make(chan broker.Exchange, 1),51 exchanges: make(chan broker.Exchange, 1),
59 }52 }
@@ -71,7 +64,7 @@
71 sto := store.NewInMemoryPendingStore()64 sto := store.NewInMemoryPendingStore()
72 notification1 := json.RawMessage(`{"m": "M"}`)65 notification1 := json.RawMessage(`{"m": "M"}`)
73 sto.AppendToChannel(store.SystemInternalChannelId, notification1)66 sto.AppendToChannel(store.SystemInternalChannelId, notification1)
74 b := NewSimpleBroker(sto, &testBrokerConfig{}, nil)67 b := NewSimpleBroker(sto, testBrokerConfig, nil)
75 sess := &simpleBrokerSession{68 sess := &simpleBrokerSession{
76 exchanges: make(chan broker.Exchange, 1),69 exchanges: make(chan broker.Exchange, 1),
77 levels: map[store.InternalChannelId]int64{70 levels: map[store.InternalChannelId]int64{
7871
=== added directory 'server/broker/testing'
=== added file 'server/broker/testing/impls.go'
--- server/broker/testing/impls.go 1970-01-01 00:00:00 +0000
+++ server/broker/testing/impls.go 2014-01-24 08:01:44 +0000
@@ -0,0 +1,60 @@
1/*
2 Copyright 2013-2014 Canonical Ltd.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License version 3, as published
6 by the Free Software Foundation.
7
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranties of
10 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along
14 with this program. If not, see <http://www.gnu.org/licenses/>.
15*/
16
17// Package testing contains simple test implementations of some broker interfaces.
18package testing
19
20import (
21 "launchpad.net/ubuntu-push/server/broker"
22)
23
24// Test implementation of BrokerSession.
25type TestBrokerSession struct {
26 DeviceId string
27 Exchanges chan broker.Exchange
28 LevelsMap broker.LevelsMap
29 exchgScratch broker.ExchangesScratchArea
30}
31
32func (tbs *TestBrokerSession) DeviceIdentifier() string {
33 return tbs.DeviceId
34}
35
36func (tbs *TestBrokerSession) SessionChannel() <-chan broker.Exchange {
37 return tbs.Exchanges
38}
39
40func (tbs *TestBrokerSession) Levels() broker.LevelsMap {
41 return tbs.LevelsMap
42}
43
44func (tbs *TestBrokerSession) ExchangeScratchArea() *broker.ExchangesScratchArea {
45 return &tbs.exchgScratch
46}
47
48// Test implementation of BrokerConfig.
49type TestBrokerConfig struct {
50 ConfigSessionQueueSize uint
51 ConfigBrokerQueueSize uint
52}
53
54func (tbc *TestBrokerConfig) SessionQueueSize() uint {
55 return tbc.ConfigSessionQueueSize
56}
57
58func (tbc *TestBrokerConfig) BrokerQueueSize() uint {
59 return tbc.ConfigBrokerQueueSize
60}
061
=== modified file 'server/broker/testsuite/suite.go'
--- server/broker/testsuite/suite.go 2014-01-24 08:01:44 +0000
+++ server/broker/testsuite/suite.go 2014-01-24 08:01:44 +0000
@@ -24,6 +24,7 @@
24 "launchpad.net/ubuntu-push/logger"24 "launchpad.net/ubuntu-push/logger"
25 "launchpad.net/ubuntu-push/protocol"25 "launchpad.net/ubuntu-push/protocol"
26 "launchpad.net/ubuntu-push/server/broker"26 "launchpad.net/ubuntu-push/server/broker"
27 "launchpad.net/ubuntu-push/server/broker/testing"
27 "launchpad.net/ubuntu-push/server/store"28 "launchpad.net/ubuntu-push/server/store"
28 helpers "launchpad.net/ubuntu-push/testing"29 helpers "launchpad.net/ubuntu-push/testing"
29 // "log"30 // "log"
@@ -47,24 +48,16 @@
47 RevealSession func(broker.Broker, string) broker.BrokerSession48 RevealSession func(broker.Broker, string) broker.BrokerSession
48}49}
4950
50type testBrokerConfig struct{}51var testBrokerConfig = &testing.TestBrokerConfig{10, 5}
51
52func (tbc *testBrokerConfig) SessionQueueSize() uint {
53 return 10
54}
55
56func (tbc *testBrokerConfig) BrokerQueueSize() uint {
57 return 5
58}
5952
60func (s *CommonBrokerSuite) TestSanity(c *C) {53func (s *CommonBrokerSuite) TestSanity(c *C) {
61 sto := store.NewInMemoryPendingStore()54 sto := store.NewInMemoryPendingStore()
62 b := s.MakeBroker(sto, &testBrokerConfig{}, nil)55 b := s.MakeBroker(sto, testBrokerConfig, nil)
63 c.Check(s.RevealSession(b, "FOO"), IsNil)56 c.Check(s.RevealSession(b, "FOO"), IsNil)
64}57}
6558
66func (s *CommonBrokerSuite) TestStartStop(c *C) {59func (s *CommonBrokerSuite) TestStartStop(c *C) {
67 b := s.MakeBroker(nil, &testBrokerConfig{}, nil)60 b := s.MakeBroker(nil, testBrokerConfig, nil)
68 b.Start()61 b.Start()
69 c.Check(b.Running(), Equals, true)62 c.Check(b.Running(), Equals, true)
70 b.Start()63 b.Start()
@@ -75,13 +68,14 @@
7568
76func (s *CommonBrokerSuite) TestRegistration(c *C) {69func (s *CommonBrokerSuite) TestRegistration(c *C) {
77 sto := store.NewInMemoryPendingStore()70 sto := store.NewInMemoryPendingStore()
78 b := s.MakeBroker(sto, &testBrokerConfig{}, nil)71 b := s.MakeBroker(sto, testBrokerConfig, nil)
79 b.Start()72 b.Start()
80 defer b.Stop()73 defer b.Stop()
81 sess, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1", Levels: map[string]int64{"0": 5}})74 sess, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1", Levels: map[string]int64{"0": 5}})
82 c.Assert(err, IsNil)75 c.Assert(err, IsNil)
83 c.Assert(s.RevealSession(b, "dev-1"), Equals, sess)76 c.Assert(s.RevealSession(b, "dev-1"), Equals, sess)
84 c.Assert(sess.DeviceId(), Equals, "dev-1")77 c.Assert(sess.DeviceIdentifier(), Equals, "dev-1")
78 c.Assert(sess.ExchangeScratchArea(), Not(IsNil))
85 c.Check(sess.Levels(), DeepEquals, broker.LevelsMap(map[store.InternalChannelId]int64{79 c.Check(sess.Levels(), DeepEquals, broker.LevelsMap(map[store.InternalChannelId]int64{
86 store.SystemInternalChannelId: 5,80 store.SystemInternalChannelId: 5,
87 }))81 }))
@@ -94,7 +88,7 @@
9488
95func (s *CommonBrokerSuite) TestRegistrationBrokenLevels(c *C) {89func (s *CommonBrokerSuite) TestRegistrationBrokenLevels(c *C) {
96 sto := store.NewInMemoryPendingStore()90 sto := store.NewInMemoryPendingStore()
97 b := s.MakeBroker(sto, &testBrokerConfig{}, nil)91 b := s.MakeBroker(sto, testBrokerConfig, nil)
98 b.Start()92 b.Start()
99 defer b.Stop()93 defer b.Stop()
100 _, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1", Levels: map[string]int64{"z": 5}})94 _, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1", Levels: map[string]int64{"z": 5}})
@@ -105,7 +99,7 @@
105 sto := store.NewInMemoryPendingStore()99 sto := store.NewInMemoryPendingStore()
106 notification1 := json.RawMessage(`{"m": "M"}`)100 notification1 := json.RawMessage(`{"m": "M"}`)
107 sto.AppendToChannel(store.SystemInternalChannelId, notification1)101 sto.AppendToChannel(store.SystemInternalChannelId, notification1)
108 b := s.MakeBroker(sto, &testBrokerConfig{}, nil)102 b := s.MakeBroker(sto, testBrokerConfig, nil)
109 b.Start()103 b.Start()
110 defer b.Stop()104 defer b.Stop()
111 sess, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1"})105 sess, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1"})
@@ -117,7 +111,7 @@
117 buf := &helpers.SyncedLogBuffer{}111 buf := &helpers.SyncedLogBuffer{}
118 logger := logger.NewSimpleLogger(buf, "error")112 logger := logger.NewSimpleLogger(buf, "error")
119 sto := &testFailingStore{}113 sto := &testFailingStore{}
120 b := s.MakeBroker(sto, &testBrokerConfig{}, logger)114 b := s.MakeBroker(sto, testBrokerConfig, logger)
121 b.Start()115 b.Start()
122 defer b.Stop()116 defer b.Stop()
123 _, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1"})117 _, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1"})
@@ -128,7 +122,7 @@
128122
129func (s *CommonBrokerSuite) TestRegistrationLastWins(c *C) {123func (s *CommonBrokerSuite) TestRegistrationLastWins(c *C) {
130 sto := store.NewInMemoryPendingStore()124 sto := store.NewInMemoryPendingStore()
131 b := s.MakeBroker(sto, &testBrokerConfig{}, nil)125 b := s.MakeBroker(sto, testBrokerConfig, nil)
132 b.Start()126 b.Start()
133 defer b.Stop()127 defer b.Stop()
134 sess1, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1"})128 sess1, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1"})
@@ -146,7 +140,7 @@
146func (s *CommonBrokerSuite) TestBroadcast(c *C) {140func (s *CommonBrokerSuite) TestBroadcast(c *C) {
147 sto := store.NewInMemoryPendingStore()141 sto := store.NewInMemoryPendingStore()
148 notification1 := json.RawMessage(`{"m": "M"}`)142 notification1 := json.RawMessage(`{"m": "M"}`)
149 b := s.MakeBroker(sto, &testBrokerConfig{}, nil)143 b := s.MakeBroker(sto, testBrokerConfig, nil)
150 b.Start()144 b.Start()
151 defer b.Stop()145 defer b.Stop()
152 sess1, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1"})146 sess1, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1"})
@@ -195,7 +189,7 @@
195 buf := &helpers.SyncedLogBuffer{Written: make(chan bool, 1)}189 buf := &helpers.SyncedLogBuffer{Written: make(chan bool, 1)}
196 logger := logger.NewSimpleLogger(buf, "error")190 logger := logger.NewSimpleLogger(buf, "error")
197 sto := &testFailingStore{countdownToFail: 1}191 sto := &testFailingStore{countdownToFail: 1}
198 b := s.MakeBroker(sto, &testBrokerConfig{}, logger)192 b := s.MakeBroker(sto, testBrokerConfig, logger)
199 b.Start()193 b.Start()
200 defer b.Stop()194 defer b.Stop()
201 _, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1"})195 _, err := b.Register(&protocol.ConnectMsg{Type: "connect", DeviceId: "dev-1"})
202196
=== modified file 'server/session/session_test.go'
--- server/session/session_test.go 2014-01-24 08:01:44 +0000
+++ server/session/session_test.go 2014-01-24 08:01:44 +0000
@@ -28,13 +28,14 @@
28 "launchpad.net/ubuntu-push/logger"28 "launchpad.net/ubuntu-push/logger"
29 "launchpad.net/ubuntu-push/protocol"29 "launchpad.net/ubuntu-push/protocol"
30 "launchpad.net/ubuntu-push/server/broker"30 "launchpad.net/ubuntu-push/server/broker"
31 "launchpad.net/ubuntu-push/server/broker/testing"
31 "net"32 "net"
32 "reflect"33 "reflect"
33 "testing"34 gotesting "testing"
34 "time"35 "time"
35)36)
3637
37func TestSession(t *testing.T) { TestingT(t) }38func TestSession(t *gotesting.T) { TestingT(t) }
3839
39type sessionSuite struct{}40type sessionSuite struct{}
4041
@@ -123,34 +124,13 @@
123 return &testBroker{registration: make(chan interface{}, 2)}124 return &testBroker{registration: make(chan interface{}, 2)}
124}125}
125126
126type testBrokerSession struct {
127 deviceId string
128 exchanges chan broker.Exchange
129}
130
131func (tbs *testBrokerSession) SessionChannel() <-chan broker.Exchange {
132 return tbs.exchanges
133}
134
135func (tbs *testBrokerSession) DeviceId() string {
136 return tbs.deviceId
137}
138
139func (tbs *testBrokerSession) Levels() broker.LevelsMap {
140 return nil
141}
142
143func (tbs *testBrokerSession) ExchangeScratchArea() *broker.ExchangesScratchArea {
144 return nil
145}
146
147func (tb *testBroker) Register(connect *protocol.ConnectMsg) (broker.BrokerSession, error) {127func (tb *testBroker) Register(connect *protocol.ConnectMsg) (broker.BrokerSession, error) {
148 tb.registration <- "register " + connect.DeviceId128 tb.registration <- "register " + connect.DeviceId
149 return &testBrokerSession{connect.DeviceId, nil}, tb.err129 return &testing.TestBrokerSession{DeviceId: connect.DeviceId}, tb.err
150}130}
151131
152func (tb *testBroker) Unregister(sess broker.BrokerSession) {132func (tb *testBroker) Unregister(sess broker.BrokerSession) {
153 tb.registration <- "unregister " + sess.(*testBrokerSession).deviceId133 tb.registration <- "unregister " + sess.DeviceIdentifier()
154}134}
155135
156func (s *sessionSuite) TestSessionStart(c *C) {136func (s *sessionSuite) TestSessionStart(c *C) {
@@ -176,7 +156,7 @@
176 err := <-errCh156 err := <-errCh
177 c.Check(err, IsNil)157 c.Check(err, IsNil)
178 c.Check(takeNext(brkr.registration), Equals, "register dev-1")158 c.Check(takeNext(brkr.registration), Equals, "register dev-1")
179 c.Check(sess.(*testBrokerSession).deviceId, Equals, "dev-1")159 c.Check(sess.DeviceIdentifier(), Equals, "dev-1")
180}160}
181161
182func (s *sessionSuite) TestSessionRegisterError(c *C) {162func (s *sessionSuite) TestSessionRegisterError(c *C) {
@@ -242,7 +222,7 @@
242 up := make(chan interface{}, 5)222 up := make(chan interface{}, 5)
243 down := make(chan interface{}, 5)223 down := make(chan interface{}, 5)
244 tp := &testProtocol{up, down}224 tp := &testProtocol{up, down}
245 sess := &testBrokerSession{}225 sess := &testing.TestBrokerSession{}
246 go func() {226 go func() {
247 errCh <- sessionLoop(tp, sess, cfg5msPingInterval2msExchangeTout)227 errCh <- sessionLoop(tp, sess, cfg5msPingInterval2msExchangeTout)
248 }()228 }()
@@ -263,7 +243,7 @@
263 up := make(chan interface{}, 5)243 up := make(chan interface{}, 5)
264 down := make(chan interface{}, 5)244 down := make(chan interface{}, 5)
265 tp := &testProtocol{up, down}245 tp := &testProtocol{up, down}
266 sess := &testBrokerSession{}246 sess := &testing.TestBrokerSession{}
267 go func() {247 go func() {
268 errCh <- sessionLoop(tp, sess, cfg5msPingInterval2msExchangeTout)248 errCh <- sessionLoop(tp, sess, cfg5msPingInterval2msExchangeTout)
269 }()249 }()
@@ -279,7 +259,7 @@
279 up := make(chan interface{}, 5)259 up := make(chan interface{}, 5)
280 down := make(chan interface{}, 5)260 down := make(chan interface{}, 5)
281 tp := &testProtocol{up, down}261 tp := &testProtocol{up, down}
282 sess := &testBrokerSession{}262 sess := &testing.TestBrokerSession{}
283 go func() {263 go func() {
284 errCh <- sessionLoop(tp, sess, cfg5msPingInterval2msExchangeTout)264 errCh <- sessionLoop(tp, sess, cfg5msPingInterval2msExchangeTout)
285 }()265 }()
@@ -332,7 +312,7 @@
332 tp := &testProtocol{up, down}312 tp := &testProtocol{up, down}
333 exchanges := make(chan broker.Exchange, 1)313 exchanges := make(chan broker.Exchange, 1)
334 exchanges <- &testExchange{}314 exchanges <- &testExchange{}
335 sess := &testBrokerSession{exchanges: exchanges}315 sess := &testing.TestBrokerSession{Exchanges: exchanges}
336 go func() {316 go func() {
337 errCh <- sessionLoop(tp, sess, cfg5msPingInterval2msExchangeTout)317 errCh <- sessionLoop(tp, sess, cfg5msPingInterval2msExchangeTout)
338 }()318 }()
@@ -355,7 +335,7 @@
355 tp := &testProtocol{up, down}335 tp := &testProtocol{up, down}
356 exchanges := make(chan broker.Exchange, 1)336 exchanges := make(chan broker.Exchange, 1)
357 exchanges <- &testExchange{nParts: 2}337 exchanges <- &testExchange{nParts: 2}
358 sess := &testBrokerSession{exchanges: exchanges}338 sess := &testing.TestBrokerSession{Exchanges: exchanges}
359 go func() {339 go func() {
360 errCh <- sessionLoop(tp, sess, cfg5msPingInterval2msExchangeTout)340 errCh <- sessionLoop(tp, sess, cfg5msPingInterval2msExchangeTout)
361 }()341 }()
@@ -383,7 +363,7 @@
383 exchanges := make(chan broker.Exchange, 1)363 exchanges := make(chan broker.Exchange, 1)
384 prepErr := errors.New("prepare failure")364 prepErr := errors.New("prepare failure")
385 exchanges <- &testExchange{prepErr: prepErr}365 exchanges <- &testExchange{prepErr: prepErr}
386 sess := &testBrokerSession{exchanges: exchanges}366 sess := &testing.TestBrokerSession{Exchanges: exchanges}
387 go func() {367 go func() {
388 errCh <- sessionLoop(tp, sess, cfg5msPingInterval2msExchangeTout)368 errCh <- sessionLoop(tp, sess, cfg5msPingInterval2msExchangeTout)
389 }()369 }()
@@ -399,7 +379,7 @@
399 exchanges := make(chan broker.Exchange, 1)379 exchanges := make(chan broker.Exchange, 1)
400 finErr := errors.New("finish error")380 finErr := errors.New("finish error")
401 exchanges <- &testExchange{finErr: finErr}381 exchanges <- &testExchange{finErr: finErr}
402 sess := &testBrokerSession{exchanges: exchanges}382 sess := &testing.TestBrokerSession{Exchanges: exchanges}
403 go func() {383 go func() {
404 errCh <- sessionLoop(tp, sess, cfg5msPingInterval2msExchangeTout)384 errCh <- sessionLoop(tp, sess, cfg5msPingInterval2msExchangeTout)
405 }()385 }()
@@ -418,7 +398,7 @@
418 tp := &testProtocol{up, down}398 tp := &testProtocol{up, down}
419 exchanges := make(chan broker.Exchange, 1)399 exchanges := make(chan broker.Exchange, 1)
420 exchanges <- &testExchange{}400 exchanges <- &testExchange{}
421 sess := &testBrokerSession{exchanges: exchanges}401 sess := &testing.TestBrokerSession{Exchanges: exchanges}
422 go func() {402 go func() {
423 errCh <- sessionLoop(tp, sess, cfg5msPingInterval2msExchangeTout)403 errCh <- sessionLoop(tp, sess, cfg5msPingInterval2msExchangeTout)
424 }()404 }()
@@ -436,7 +416,7 @@
436 tp := &testProtocol{up, down}416 tp := &testProtocol{up, down}
437 exchanges := make(chan broker.Exchange, 1)417 exchanges := make(chan broker.Exchange, 1)
438 exchanges <- &testExchange{finSleep: 3 * time.Millisecond}418 exchanges <- &testExchange{finSleep: 3 * time.Millisecond}
439 sess := &testBrokerSession{exchanges: exchanges}419 sess := &testing.TestBrokerSession{Exchanges: exchanges}
440 go func() {420 go func() {
441 errCh <- sessionLoop(tp, sess, cfg5msPingInterval2msExchangeTout)421 errCh <- sessionLoop(tp, sess, cfg5msPingInterval2msExchangeTout)
442 }()422 }()
443423
=== modified file 'server/session/tracker.go'
--- server/session/tracker.go 2014-01-15 08:55:54 +0000
+++ server/session/tracker.go 2014-01-24 08:01:44 +0000
@@ -57,7 +57,7 @@
57}57}
5858
59func (trk *tracker) Registered(sess broker.BrokerSession) {59func (trk *tracker) Registered(sess broker.BrokerSession) {
60 trk.Infof("session(%x) registered %v", trk.sessionId, sess.DeviceId())60 trk.Infof("session(%x) registered %v", trk.sessionId, sess.DeviceIdentifier())
61}61}
6262
63func (trk *tracker) End(err error) error {63func (trk *tracker) End(err error) error {
6464
=== modified file 'server/session/tracker_test.go'
--- server/session/tracker_test.go 2014-01-15 08:55:54 +0000
+++ server/session/tracker_test.go 2014-01-24 08:01:44 +0000
@@ -22,6 +22,7 @@
22 . "launchpad.net/gocheck"22 . "launchpad.net/gocheck"
23 "launchpad.net/ubuntu-push/logger"23 "launchpad.net/ubuntu-push/logger"
24 "launchpad.net/ubuntu-push/server/broker"24 "launchpad.net/ubuntu-push/server/broker"
25 "launchpad.net/ubuntu-push/server/broker/testing"
25 "net"26 "net"
26)27)
2728
@@ -50,7 +51,7 @@
50 logger := logger.NewSimpleLogger(buf, "debug")51 logger := logger.NewSimpleLogger(buf, "debug")
51 track := NewTracker(logger)52 track := NewTracker(logger)
52 track.Start(&testRemoteAddrable{})53 track.Start(&testRemoteAddrable{})
53 track.Registered(&testBrokerSession{deviceId: "DEV-ID"})54 track.Registered(&testing.TestBrokerSession{DeviceId: "DEV-ID"})
54 regExpected := fmt.Sprintf(`.*connected.*\n.* INFO session\(%x\) registered DEV-ID\n`, track.(*tracker).sessionId)55 regExpected := fmt.Sprintf(`.*connected.*\n.* INFO session\(%x\) registered DEV-ID\n`, track.(*tracker).sessionId)
55 c.Check(buf.String(), Matches, regExpected)56 c.Check(buf.String(), Matches, regExpected)
56}57}

Subscribers

People subscribed via source and target branches