Merge lp:~chipaca/ubuntu-push/persistence into lp:ubuntu-push

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: 67
Merged at revision: 79
Proposed branch: lp:~chipaca/ubuntu-push/persistence
Merge into: lp:ubuntu-push
Prerequisite: lp:~chipaca/ubuntu-push/sqlevelmap-in-session
Diff against target: 484 lines (+91/-51)
2 files modified
client/client.go (+28/-17)
client/client_test.go (+63/-34)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/persistence
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+205484@code.launchpad.net

Commit message

and this gives the client the ability to persist its session's levelmap

Description of the change

With this, NewPushClient takes a second argument that is the path to
the sqlite db in which to persist its level map. If the path is "",
use the good ol' mapLevelMap instead.

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

good time to do: pushClient => PushClient ?

c.Check(fmt.Sprintf("%T", ln), Equals, "*levelmap.sqliteLevelMap")

maybe giving LevelMap again a String() ?

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

The attempt to merge lp:~chipaca/ubuntu-push/persistence 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 code.google.com/p/gosqlite/sqlite3
/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 code.google.com/p/gosqlite/sqlite3
go test launchpad.net/ubuntu-push/...
ok launchpad.net/ubuntu-push/bus 0.009s
ok launchpad.net/ubuntu-push/bus/connectivity 0.148s
ok launchpad.net/ubuntu-push/bus/networkmanager 0.027s
ok launchpad.net/ubuntu-push/bus/notifications 0.017s
ok launchpad.net/ubuntu-push/bus/testing 0.025s
ok launchpad.net/ubuntu-push/bus/urldispatcher 0.005s
ok launchpad.net/ubuntu-push/client 0.098s
ok launchpad.net/ubuntu-push/client/session 0.086s
ok launchpad.net/ubuntu-push/client/session/levelmap 0.068s
ok launchpad.net/ubuntu-push/config 0.015s
ok launchpad.net/ubuntu-push/logger 0.006s
ok launchpad.net/ubuntu-push/protocol 0.010s
ok launchpad.net/ubuntu-push/server 0.027s
ok launchpad.net/ubuntu-push/server/acceptance 0.015s
? launchpad.net/ubuntu-push/server/acceptance/cmd [no test files]
? launchpad.net/ubuntu-push/server/acceptance/suites [no test files]
ok launchpad.net/ubuntu-push/server/api 0.017s
ok launchpad.net/ubuntu-push/server/broker 0.010s
ok launchpad.net/ubuntu-push/server/broker/simple 0.007s
? 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.384s
ok launchpad.net/ubuntu-push/server/session 0.162s
ok launchpad.net/ubuntu-push/server/store 0.210s
? launchpad.net/ubuntu-push/testing [no test files]
ok launchpad.net/ubuntu-push/testing/condition 0.004s
ok launchpad.net/ubuntu-push/util 0.006s
? launchpad.net/ubuntu-push/whoopsie [no test files]
ok launchpad.net/ubuntu-push/whoopsie/identifier 0.007s
ok launchpad.net/ubuntu-push/whoopsie/identifier/testing 0.011s
go test -race launchpad.net/ubuntu-push/...
ok launchpad.net/ubuntu-push/bus 1.018s
ok launchpad.net/ubuntu-push/bus/connectivity 1.190s
ok launchpad.net/ubuntu-push/bus/networkmanager 1.038s
ok launchpad.net/ubuntu-push/bus/notifications 1.026s
ok launchpad.net/ubuntu-push/bus/testing 1.035s
ok launchpad.net/ubuntu-push/bus/urldispatcher 1.015s
ok launchpad.net/ubuntu-push/client 1.270s
ok launchpad.net/ubuntu-push/client/session 1.462s
ok launchpad.net/ubuntu-push/client/session/levelmap 1.041s
ok launchpad.net/ubuntu-push/config 1.033s
ok launchpad.net/ubuntu-push/logger 1.049s
ok launchpad.net/ubuntu-push/protocol 1.051s
ok launchpad.net/ubuntu-push/server 1.119s
ok launchpad.net/ubuntu-push/server/acceptance 1.042s
? launchpad.net/ubuntu-push/server/acceptance/cmd [no tes...

Read more...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'client/client.go'
--- client/client.go 2014-02-21 16:17:28 +0000
+++ client/client.go 2014-03-12 11:09:23 +0000
@@ -50,8 +50,9 @@
50 LogLevel string `json:"log_level"`50 LogLevel string `json:"log_level"`
51}51}
5252
53// pushClient is the Ubuntu Push Notifications client-side daemon.53// PushClient is the Ubuntu Push Notifications client-side daemon.
54type pushClient struct {54type PushClient struct {
55 leveldbPath string
55 configPath string56 configPath string
56 config ClientConfig57 config ClientConfig
57 log logger.Logger58 log logger.Logger
@@ -70,15 +71,16 @@
7071
71// Creates a new Ubuntu Push Notifications client-side daemon that will use72// Creates a new Ubuntu Push Notifications client-side daemon that will use
72// the given configuration file.73// the given configuration file.
73func NewPushClient(configPath string) *pushClient {74func NewPushClient(configPath string, leveldbPath string) *PushClient {
74 client := new(pushClient)75 client := new(PushClient)
75 client.configPath = configPath76 client.configPath = configPath
77 client.leveldbPath = leveldbPath
7678
77 return client79 return client
78}80}
7981
80// configure loads its configuration, and sets it up.82// configure loads its configuration, and sets it up.
81func (client *pushClient) configure() error {83func (client *PushClient) configure() error {
82 f, err := os.Open(client.configPath)84 f, err := os.Open(client.configPath)
83 if err != nil {85 if err != nil {
84 return fmt.Errorf("opening config: %v", err)86 return fmt.Errorf("opening config: %v", err)
@@ -115,7 +117,7 @@
115}117}
116118
117// getDeviceId gets the whoopsie identifier for the device119// getDeviceId gets the whoopsie identifier for the device
118func (client *pushClient) getDeviceId() error {120func (client *PushClient) getDeviceId() error {
119 err := client.idder.Generate()121 err := client.idder.Generate()
120 if err != nil {122 if err != nil {
121 return err123 return err
@@ -125,7 +127,7 @@
125}127}
126128
127// takeTheBus starts the connection(s) to D-Bus and sets up associated event channels129// takeTheBus starts the connection(s) to D-Bus and sets up associated event channels
128func (client *pushClient) takeTheBus() error {130func (client *PushClient) takeTheBus() error {
129 go connectivity.ConnectedState(client.connectivityEndp,131 go connectivity.ConnectedState(client.connectivityEndp,
130 client.config.ConnectivityConfig, client.log, client.connCh)132 client.config.ConnectivityConfig, client.log, client.connCh)
131 iniCh := make(chan uint32)133 iniCh := make(chan uint32)
@@ -140,10 +142,10 @@
140}142}
141143
142// initSession creates the session object144// initSession creates the session object
143func (client *pushClient) initSession() error {145func (client *PushClient) initSession() error {
144 sess, err := session.NewSession(string(client.config.Addr), client.pem,146 sess, err := session.NewSession(string(client.config.Addr), client.pem,
145 client.config.ExchangeTimeout.Duration, client.deviceId,147 client.config.ExchangeTimeout.Duration, client.deviceId,
146 levelmap.NewLevelMap, client.log)148 client.levelMapFactory, client.log)
147 if err != nil {149 if err != nil {
148 return err150 return err
149 }151 }
@@ -151,8 +153,17 @@
151 return nil153 return nil
152}154}
153155
156// levelmapFactory returns a levelMap for the session
157func (client *PushClient) levelMapFactory() (levelmap.LevelMap, error) {
158 if client.leveldbPath == "" {
159 return levelmap.NewLevelMap()
160 } else {
161 return levelmap.NewSqliteLevelMap(client.leveldbPath)
162 }
163}
164
154// handleConnState deals with connectivity events165// handleConnState deals with connectivity events
155func (client *pushClient) handleConnState(hasConnectivity bool) {166func (client *PushClient) handleConnState(hasConnectivity bool) {
156 if client.hasConnectivity == hasConnectivity {167 if client.hasConnectivity == hasConnectivity {
157 // nothing to do!168 // nothing to do!
158 return169 return
@@ -166,7 +177,7 @@
166}177}
167178
168// handleErr deals with the session erroring out of its loop179// handleErr deals with the session erroring out of its loop
169func (client *pushClient) handleErr(err error) {180func (client *PushClient) handleErr(err error) {
170 // if we're not connected, we don't really care181 // if we're not connected, we don't really care
171 client.log.Errorf("session exited: %s", err)182 client.log.Errorf("session exited: %s", err)
172 if client.hasConnectivity {183 if client.hasConnectivity {
@@ -175,7 +186,7 @@
175}186}
176187
177// handleNotification deals with receiving a notification188// handleNotification deals with receiving a notification
178func (client *pushClient) handleNotification() error {189func (client *PushClient) handleNotification() error {
179 action_id := "dummy_id"190 action_id := "dummy_id"
180 a := []string{action_id, "Go get it!"} // action value not visible on the phone191 a := []string{action_id, "Go get it!"} // action value not visible on the phone
181 h := map[string]*dbus.Variant{"x-canonical-switch-to-application": &dbus.Variant{true}}192 h := map[string]*dbus.Variant{"x-canonical-switch-to-application": &dbus.Variant{true}}
@@ -199,14 +210,14 @@
199}210}
200211
201// handleClick deals with the user clicking a notification212// handleClick deals with the user clicking a notification
202func (client *pushClient) handleClick() error {213func (client *PushClient) handleClick() error {
203 // it doesn't get much simpler...214 // it doesn't get much simpler...
204 urld := urldispatcher.New(client.urlDispatcherEndp, client.log)215 urld := urldispatcher.New(client.urlDispatcherEndp, client.log)
205 return urld.DispatchURL("settings:///system/system-update")216 return urld.DispatchURL("settings:///system/system-update")
206}217}
207218
208// doLoop connects events with their handlers219// doLoop connects events with their handlers
209func (client *pushClient) doLoop(connhandler func(bool), clickhandler, notifhandler func() error, errhandler func(error)) {220func (client *PushClient) doLoop(connhandler func(bool), clickhandler, notifhandler func() error, errhandler func(error)) {
210 for {221 for {
211 select {222 select {
212 case state := <-client.connCh:223 case state := <-client.connCh:
@@ -225,7 +236,7 @@
225236
226// doStart calls each of its arguments in order, returning the first non-nil237// doStart calls each of its arguments in order, returning the first non-nil
227// error (or nil at the end)238// error (or nil at the end)
228func (client *pushClient) doStart(fs ...func() error) error {239func (client *PushClient) doStart(fs ...func() error) error {
229 for _, f := range fs {240 for _, f := range fs {
230 if err := f(); err != nil {241 if err := f(); err != nil {
231 return err242 return err
@@ -235,13 +246,13 @@
235}246}
236247
237// Loop calls doLoop with the "real" handlers248// Loop calls doLoop with the "real" handlers
238func (client *pushClient) Loop() {249func (client *PushClient) Loop() {
239 client.doLoop(client.handleConnState, client.handleClick,250 client.doLoop(client.handleConnState, client.handleClick,
240 client.handleNotification, client.handleErr)251 client.handleNotification, client.handleErr)
241}252}
242253
243// Start calls doStart with the "real" starters254// Start calls doStart with the "real" starters
244func (client *pushClient) Start() error {255func (client *PushClient) Start() error {
245 return client.doStart(256 return client.doStart(
246 client.configure,257 client.configure,
247 client.getDeviceId,258 client.getDeviceId,
248259
=== modified file 'client/client_test.go'
--- client/client_test.go 2014-02-08 18:26:49 +0000
+++ client/client_test.go 2014-03-12 11:09:23 +0000
@@ -52,9 +52,10 @@
52}52}
5353
54type clientSuite struct {54type clientSuite struct {
55 timeouts []time.Duration55 timeouts []time.Duration
56 configPath string56 configPath string
57 log *helpers.TestLogger57 leveldbPath string
58 log *helpers.TestLogger
58}59}
5960
60var _ = Suite(&clientSuite{})61var _ = Suite(&clientSuite{})
@@ -74,6 +75,7 @@
7475
75func (cs *clientSuite) SetUpSuite(c *C) {76func (cs *clientSuite) SetUpSuite(c *C) {
76 cs.timeouts = util.SwapTimeouts([]time.Duration{0})77 cs.timeouts = util.SwapTimeouts([]time.Duration{0})
78 cs.leveldbPath = ""
77}79}
7880
79func (cs *clientSuite) TearDownSuite(c *C) {81func (cs *clientSuite) TearDownSuite(c *C) {
@@ -99,12 +101,21 @@
99 ioutil.WriteFile(cs.configPath, []byte(cfg), 0600)101 ioutil.WriteFile(cs.configPath, []byte(cfg), 0600)
100}102}
101103
104type sqlientSuite struct{ clientSuite }
105
106func (s *sqlientSuite) SetUpSuite(c *C) {
107 s.clientSuite.SetUpSuite(c)
108 s.leveldbPath = ":memory:"
109}
110
111var _ = Suite(&sqlientSuite{})
112
102/*****************************************************************113/*****************************************************************
103 configure tests114 configure tests
104******************************************************************/115******************************************************************/
105116
106func (cs *clientSuite) TestConfigureWorks(c *C) {117func (cs *clientSuite) TestConfigureWorks(c *C) {
107 cli := NewPushClient(cs.configPath)118 cli := NewPushClient(cs.configPath, cs.leveldbPath)
108 err := cli.configure()119 err := cli.configure()
109 c.Assert(err, IsNil)120 c.Assert(err, IsNil)
110 c.Assert(cli.config, NotNil)121 c.Assert(cli.config, NotNil)
@@ -112,7 +123,7 @@
112}123}
113124
114func (cs *clientSuite) TestConfigureSetsUpLog(c *C) {125func (cs *clientSuite) TestConfigureSetsUpLog(c *C) {
115 cli := NewPushClient(cs.configPath)126 cli := NewPushClient(cs.configPath, cs.leveldbPath)
116 c.Check(cli.log, IsNil)127 c.Check(cli.log, IsNil)
117 err := cli.configure()128 err := cli.configure()
118 c.Assert(err, IsNil)129 c.Assert(err, IsNil)
@@ -120,7 +131,7 @@
120}131}
121132
122func (cs *clientSuite) TestConfigureSetsUpPEM(c *C) {133func (cs *clientSuite) TestConfigureSetsUpPEM(c *C) {
123 cli := NewPushClient(cs.configPath)134 cli := NewPushClient(cs.configPath, cs.leveldbPath)
124 c.Check(cli.pem, IsNil)135 c.Check(cli.pem, IsNil)
125 err := cli.configure()136 err := cli.configure()
126 c.Assert(err, IsNil)137 c.Assert(err, IsNil)
@@ -128,7 +139,7 @@
128}139}
129140
130func (cs *clientSuite) TestConfigureSetsUpIdder(c *C) {141func (cs *clientSuite) TestConfigureSetsUpIdder(c *C) {
131 cli := NewPushClient(cs.configPath)142 cli := NewPushClient(cs.configPath, cs.leveldbPath)
132 c.Check(cli.idder, IsNil)143 c.Check(cli.idder, IsNil)
133 err := cli.configure()144 err := cli.configure()
134 c.Assert(err, IsNil)145 c.Assert(err, IsNil)
@@ -136,7 +147,7 @@
136}147}
137148
138func (cs *clientSuite) TestConfigureSetsUpEndpoints(c *C) {149func (cs *clientSuite) TestConfigureSetsUpEndpoints(c *C) {
139 cli := NewPushClient(cs.configPath)150 cli := NewPushClient(cs.configPath, cs.leveldbPath)
140 c.Check(cli.notificationsEndp, IsNil)151 c.Check(cli.notificationsEndp, IsNil)
141 c.Check(cli.urlDispatcherEndp, IsNil)152 c.Check(cli.urlDispatcherEndp, IsNil)
142 c.Check(cli.connectivityEndp, IsNil)153 c.Check(cli.connectivityEndp, IsNil)
@@ -148,7 +159,7 @@
148}159}
149160
150func (cs *clientSuite) TestConfigureSetsUpConnCh(c *C) {161func (cs *clientSuite) TestConfigureSetsUpConnCh(c *C) {
151 cli := NewPushClient(cs.configPath)162 cli := NewPushClient(cs.configPath, cs.leveldbPath)
152 c.Check(cli.connCh, IsNil)163 c.Check(cli.connCh, IsNil)
153 err := cli.configure()164 err := cli.configure()
154 c.Assert(err, IsNil)165 c.Assert(err, IsNil)
@@ -156,13 +167,13 @@
156}167}
157168
158func (cs *clientSuite) TestConfigureBailsOnBadFilename(c *C) {169func (cs *clientSuite) TestConfigureBailsOnBadFilename(c *C) {
159 cli := NewPushClient("/does/not/exist")170 cli := NewPushClient("/does/not/exist", cs.leveldbPath)
160 err := cli.configure()171 err := cli.configure()
161 c.Assert(err, NotNil)172 c.Assert(err, NotNil)
162}173}
163174
164func (cs *clientSuite) TestConfigureBailsOnBadConfig(c *C) {175func (cs *clientSuite) TestConfigureBailsOnBadConfig(c *C) {
165 cli := NewPushClient("/etc/passwd")176 cli := NewPushClient("/etc/passwd", cs.leveldbPath)
166 err := cli.configure()177 err := cli.configure()
167 c.Assert(err, NotNil)178 c.Assert(err, NotNil)
168}179}
@@ -180,7 +191,7 @@
180 "recheck_timeout": "3h"191 "recheck_timeout": "3h"
181}`), 0600)192}`), 0600)
182193
183 cli := NewPushClient(cs.configPath)194 cli := NewPushClient(cs.configPath, cs.leveldbPath)
184 err := cli.configure()195 err := cli.configure()
185 c.Assert(err, ErrorMatches, "reading PEM file: .*")196 c.Assert(err, ErrorMatches, "reading PEM file: .*")
186}197}
@@ -198,7 +209,7 @@
198 "recheck_timeout": "3h"209 "recheck_timeout": "3h"
199}`), 0600)210}`), 0600)
200211
201 cli := NewPushClient(cs.configPath)212 cli := NewPushClient(cs.configPath, cs.leveldbPath)
202 err := cli.configure()213 err := cli.configure()
203 c.Assert(err, ErrorMatches, "no PEM found.*")214 c.Assert(err, ErrorMatches, "no PEM found.*")
204}215}
@@ -208,7 +219,7 @@
208******************************************************************/219******************************************************************/
209220
210func (cs *clientSuite) TestGetDeviceIdWorks(c *C) {221func (cs *clientSuite) TestGetDeviceIdWorks(c *C) {
211 cli := NewPushClient(cs.configPath)222 cli := NewPushClient(cs.configPath, cs.leveldbPath)
212 cli.log = cs.log223 cli.log = cs.log
213 cli.idder = identifier.New()224 cli.idder = identifier.New()
214 c.Check(cli.deviceId, Equals, "")225 c.Check(cli.deviceId, Equals, "")
@@ -217,7 +228,7 @@
217}228}
218229
219func (cs *clientSuite) TestGetDeviceIdCanFail(c *C) {230func (cs *clientSuite) TestGetDeviceIdCanFail(c *C) {
220 cli := NewPushClient(cs.configPath)231 cli := NewPushClient(cs.configPath, cs.leveldbPath)
221 cli.log = cs.log232 cli.log = cs.log
222 cli.idder = idtesting.Failing()233 cli.idder = idtesting.Failing()
223 c.Check(cli.deviceId, Equals, "")234 c.Check(cli.deviceId, Equals, "")
@@ -245,7 +256,7 @@
245 )256 )
246 testibus.SetWatchTicker(cEndp, make(chan bool))257 testibus.SetWatchTicker(cEndp, make(chan bool))
247 // ok, create the thing258 // ok, create the thing
248 cli := NewPushClient(cs.configPath)259 cli := NewPushClient(cs.configPath, cs.leveldbPath)
249 cli.log = cs.log260 cli.log = cs.log
250 err := cli.configure()261 err := cli.configure()
251 c.Assert(err, IsNil)262 c.Assert(err, IsNil)
@@ -273,7 +284,7 @@
273284
274// takeTheBus can, in fact, fail285// takeTheBus can, in fact, fail
275func (cs *clientSuite) TestTakeTheBusCanFail(c *C) {286func (cs *clientSuite) TestTakeTheBusCanFail(c *C) {
276 cli := NewPushClient(cs.configPath)287 cli := NewPushClient(cs.configPath, cs.leveldbPath)
277 err := cli.configure()288 err := cli.configure()
278 cli.log = cs.log289 cli.log = cs.log
279 c.Assert(err, IsNil)290 c.Assert(err, IsNil)
@@ -294,7 +305,7 @@
294******************************************************************/305******************************************************************/
295306
296func (cs *clientSuite) TestHandleErr(c *C) {307func (cs *clientSuite) TestHandleErr(c *C) {
297 cli := NewPushClient(cs.configPath)308 cli := NewPushClient(cs.configPath, cs.leveldbPath)
298 cli.log = cs.log309 cli.log = cs.log
299 c.Assert(cli.initSession(), IsNil)310 c.Assert(cli.initSession(), IsNil)
300 cli.hasConnectivity = true311 cli.hasConnectivity = true
@@ -303,11 +314,29 @@
303}314}
304315
305/*****************************************************************316/*****************************************************************
317 levelmapFactory tests
318******************************************************************/
319
320func (cs *clientSuite) TestLevelMapFactoryNoDbPath(c *C) {
321 cli := NewPushClient(cs.configPath, "")
322 ln, err := cli.levelMapFactory()
323 c.Assert(err, IsNil)
324 c.Check(fmt.Sprintf("%T", ln), Equals, "*levelmap.mapLevelMap")
325}
326
327func (cs *clientSuite) TestLevelMapFactoryWithDbPath(c *C) {
328 cli := NewPushClient(cs.configPath, ":memory:")
329 ln, err := cli.levelMapFactory()
330 c.Assert(err, IsNil)
331 c.Check(fmt.Sprintf("%T", ln), Equals, "*levelmap.sqliteLevelMap")
332}
333
334/*****************************************************************
306 handleConnState tests335 handleConnState tests
307******************************************************************/336******************************************************************/
308337
309func (cs *clientSuite) TestHandleConnStateD2C(c *C) {338func (cs *clientSuite) TestHandleConnStateD2C(c *C) {
310 cli := NewPushClient(cs.configPath)339 cli := NewPushClient(cs.configPath, cs.leveldbPath)
311 cli.log = cs.log340 cli.log = cs.log
312 c.Assert(cli.initSession(), IsNil)341 c.Assert(cli.initSession(), IsNil)
313342
@@ -318,7 +347,7 @@
318}347}
319348
320func (cs *clientSuite) TestHandleConnStateSame(c *C) {349func (cs *clientSuite) TestHandleConnStateSame(c *C) {
321 cli := NewPushClient(cs.configPath)350 cli := NewPushClient(cs.configPath, cs.leveldbPath)
322 cli.log = cs.log351 cli.log = cs.log
323 // here we want to check that we don't do anything352 // here we want to check that we don't do anything
324 c.Assert(cli.session, IsNil)353 c.Assert(cli.session, IsNil)
@@ -332,7 +361,7 @@
332}361}
333362
334func (cs *clientSuite) TestHandleConnStateC2D(c *C) {363func (cs *clientSuite) TestHandleConnStateC2D(c *C) {
335 cli := NewPushClient(cs.configPath)364 cli := NewPushClient(cs.configPath, cs.leveldbPath)
336 cli.log = cs.log365 cli.log = cs.log
337 cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, levelmap.NewLevelMap, cs.log)366 cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, levelmap.NewLevelMap, cs.log)
338 cli.session.Dial()367 cli.session.Dial()
@@ -345,7 +374,7 @@
345}374}
346375
347func (cs *clientSuite) TestHandleConnStateC2DPending(c *C) {376func (cs *clientSuite) TestHandleConnStateC2DPending(c *C) {
348 cli := NewPushClient(cs.configPath)377 cli := NewPushClient(cs.configPath, cs.leveldbPath)
349 cli.log = cs.log378 cli.log = cs.log
350 cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, levelmap.NewLevelMap, cs.log)379 cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, levelmap.NewLevelMap, cs.log)
351 cli.hasConnectivity = true380 cli.hasConnectivity = true
@@ -359,7 +388,7 @@
359******************************************************************/388******************************************************************/
360389
361func (cs *clientSuite) TestHandleNotification(c *C) {390func (cs *clientSuite) TestHandleNotification(c *C) {
362 cli := NewPushClient(cs.configPath)391 cli := NewPushClient(cs.configPath, cs.leveldbPath)
363 endp := testibus.NewTestingEndpoint(nil, condition.Work(true), uint32(1))392 endp := testibus.NewTestingEndpoint(nil, condition.Work(true), uint32(1))
364 cli.notificationsEndp = endp393 cli.notificationsEndp = endp
365 cli.log = cs.log394 cli.log = cs.log
@@ -372,7 +401,7 @@
372}401}
373402
374func (cs *clientSuite) TestHandleNotificationFail(c *C) {403func (cs *clientSuite) TestHandleNotificationFail(c *C) {
375 cli := NewPushClient(cs.configPath)404 cli := NewPushClient(cs.configPath, cs.leveldbPath)
376 cli.log = cs.log405 cli.log = cs.log
377 endp := testibus.NewTestingEndpoint(nil, condition.Work(false))406 endp := testibus.NewTestingEndpoint(nil, condition.Work(false))
378 cli.notificationsEndp = endp407 cli.notificationsEndp = endp
@@ -384,7 +413,7 @@
384******************************************************************/413******************************************************************/
385414
386func (cs *clientSuite) TestHandleClick(c *C) {415func (cs *clientSuite) TestHandleClick(c *C) {
387 cli := NewPushClient(cs.configPath)416 cli := NewPushClient(cs.configPath, cs.leveldbPath)
388 cli.log = cs.log417 cli.log = cs.log
389 endp := testibus.NewTestingEndpoint(nil, condition.Work(true), nil)418 endp := testibus.NewTestingEndpoint(nil, condition.Work(true), nil)
390 cli.urlDispatcherEndp = endp419 cli.urlDispatcherEndp = endp
@@ -401,7 +430,7 @@
401******************************************************************/430******************************************************************/
402431
403func (cs *clientSuite) TestDoLoopConn(c *C) {432func (cs *clientSuite) TestDoLoopConn(c *C) {
404 cli := NewPushClient(cs.configPath)433 cli := NewPushClient(cs.configPath, cs.leveldbPath)
405 cli.log = cs.log434 cli.log = cs.log
406 cli.connCh = make(chan bool, 1)435 cli.connCh = make(chan bool, 1)
407 cli.connCh <- true436 cli.connCh <- true
@@ -413,7 +442,7 @@
413}442}
414443
415func (cs *clientSuite) TestDoLoopClick(c *C) {444func (cs *clientSuite) TestDoLoopClick(c *C) {
416 cli := NewPushClient(cs.configPath)445 cli := NewPushClient(cs.configPath, cs.leveldbPath)
417 cli.log = cs.log446 cli.log = cs.log
418 c.Assert(cli.initSession(), IsNil)447 c.Assert(cli.initSession(), IsNil)
419 aCh := make(chan notifications.RawActionReply, 1)448 aCh := make(chan notifications.RawActionReply, 1)
@@ -426,7 +455,7 @@
426}455}
427456
428func (cs *clientSuite) TestDoLoopNotif(c *C) {457func (cs *clientSuite) TestDoLoopNotif(c *C) {
429 cli := NewPushClient(cs.configPath)458 cli := NewPushClient(cs.configPath, cs.leveldbPath)
430 cli.log = cs.log459 cli.log = cs.log
431 c.Assert(cli.initSession(), IsNil)460 c.Assert(cli.initSession(), IsNil)
432 cli.session.MsgCh = make(chan *session.Notification, 1)461 cli.session.MsgCh = make(chan *session.Notification, 1)
@@ -438,7 +467,7 @@
438}467}
439468
440func (cs *clientSuite) TestDoLoopErr(c *C) {469func (cs *clientSuite) TestDoLoopErr(c *C) {
441 cli := NewPushClient(cs.configPath)470 cli := NewPushClient(cs.configPath, cs.leveldbPath)
442 cli.log = cs.log471 cli.log = cs.log
443 c.Assert(cli.initSession(), IsNil)472 c.Assert(cli.initSession(), IsNil)
444 cli.session.ErrCh = make(chan error, 1)473 cli.session.ErrCh = make(chan error, 1)
@@ -454,7 +483,7 @@
454******************************************************************/483******************************************************************/
455484
456func (cs *clientSuite) TestDoStartWorks(c *C) {485func (cs *clientSuite) TestDoStartWorks(c *C) {
457 cli := NewPushClient(cs.configPath)486 cli := NewPushClient(cs.configPath, cs.leveldbPath)
458 one_called := false487 one_called := false
459 two_called := false488 two_called := false
460 one := func() error { one_called = true; return nil }489 one := func() error { one_called = true; return nil }
@@ -465,7 +494,7 @@
465}494}
466495
467func (cs *clientSuite) TestDoStartFailsAsExpected(c *C) {496func (cs *clientSuite) TestDoStartFailsAsExpected(c *C) {
468 cli := NewPushClient(cs.configPath)497 cli := NewPushClient(cs.configPath, cs.leveldbPath)
469 one_called := false498 one_called := false
470 two_called := false499 two_called := false
471 failure := errors.New("Failure")500 failure := errors.New("Failure")
@@ -481,7 +510,7 @@
481******************************************************************/510******************************************************************/
482511
483func (cs *clientSuite) TestLoop(c *C) {512func (cs *clientSuite) TestLoop(c *C) {
484 cli := NewPushClient(cs.configPath)513 cli := NewPushClient(cs.configPath, cs.leveldbPath)
485 cli.connCh = make(chan bool)514 cli.connCh = make(chan bool)
486 cli.sessionConnectedCh = make(chan uint32)515 cli.sessionConnectedCh = make(chan uint32)
487 aCh := make(chan notifications.RawActionReply, 1)516 aCh := make(chan notifications.RawActionReply, 1)
@@ -559,7 +588,7 @@
559 c.Skip("no dbus")588 c.Skip("no dbus")
560 }589 }
561590
562 cli := NewPushClient(cs.configPath)591 cli := NewPushClient(cs.configPath, cs.leveldbPath)
563 // before start, everything sucks:592 // before start, everything sucks:
564 // no config,593 // no config,
565 c.Check(string(cli.config.Addr), Equals, "")594 c.Check(string(cli.config.Addr), Equals, "")
@@ -588,7 +617,7 @@
588}617}
589618
590func (cs *clientSuite) TestStartCanFail(c *C) {619func (cs *clientSuite) TestStartCanFail(c *C) {
591 cli := NewPushClient("/does/not/exist")620 cli := NewPushClient("/does/not/exist", cs.leveldbPath)
592 // easiest way for it to fail is to feed it a bad config621 // easiest way for it to fail is to feed it a bad config
593 err := cli.Start()622 err := cli.Start()
594 // and it works. Err. Doesn't.623 // and it works. Err. Doesn't.

Subscribers

People subscribed via source and target branches