Merge lp:~chipaca/ubuntu-push/service into lp:ubuntu-push/automatic

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: no longer in the source branch.
Merged at revision: 148
Proposed branch: lp:~chipaca/ubuntu-push/service
Merge into: lp:ubuntu-push/automatic
Prerequisite: lp:~chipaca/ubuntu-push/endpoint-names
Diff against target: 406 lines (+252/-31)
9 files modified
.bzrignore (+7/-0)
Makefile (+10/-3)
bus/testing/testing_endpoint.go (+9/-2)
bus/testing/testing_endpoint_test.go (+5/-1)
client/client.go (+13/-0)
client/client_test.go (+33/-0)
client/service/service.go (+82/-0)
client/service/service_test.go (+93/-0)
ubuntu-push-client.go (+0/-25)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/service
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+219205@code.launchpad.net

This proposal supersedes a proposal from 2014-05-12.

Commit message

First pass at client/service.

Description of the change

First pass at client/service.

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

the README should mention the need to install cmake now.

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

any particular reason for this check/style:

222 + }
223 + if svc.Log == nil {
224 + return NotConfigured
225 + }

instead of having a NewService?

not against, mostly wondering about consistency

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

The attempt to merge lp:~chipaca/ubuntu-push/service into lp:ubuntu-push/automatic failed. Below is the output from the failed tests.

rm -f -r /mnt/tarmac/cache/ubuntu-push-automatic/go-ws/pkg
mkdir -p /mnt/tarmac/cache/ubuntu-push-automatic/go-ws/bin
mkdir -p /mnt/tarmac/cache/ubuntu-push-automatic/go-ws/pkg
go get -u launchpad.net/godeps
go get -d -u launchpad.net/gocheck launchpad.net/go-dbus/v1 launchpad.net/go-xdg/v0 code.google.com/p/gosqlite/sqlite3 launchpad.net/~ubuntu-push-hackers/ubuntu-push/go-uuid/uuid
/mnt/tarmac/cache/ubuntu-push-automatic/go-ws/bin/godeps -u dependencies.tsv
"/mnt/tarmac/cache/ubuntu-push-automatic/go-ws/src/launchpad.net/gocheck" now at <email address hidden>
go install launchpad.net/gocheck launchpad.net/go-dbus/v1 launchpad.net/go-xdg/v0 code.google.com/p/gosqlite/sqlite3 launchpad.net/~ubuntu-push-hackers/ubuntu-push/go-uuid/uuid
go test launchpad.net/ubuntu-push launchpad.net/ubuntu-push/bus launchpad.net/ubuntu-push/bus/connectivity launchpad.net/ubuntu-push/bus/networkmanager launchpad.net/ubuntu-push/bus/notifications launchpad.net/ubuntu-push/bus/systemimage launchpad.net/ubuntu-push/bus/testing launchpad.net/ubuntu-push/bus/urldispatcher launchpad.net/ubuntu-push/client launchpad.net/ubuntu-push/client/gethosts launchpad.net/ubuntu-push/client/service launchpad.net/ubuntu-push/client/session launchpad.net/ubuntu-push/client/session/levelmap launchpad.net/ubuntu-push/config launchpad.net/ubuntu-push/external/murmur3 launchpad.net/ubuntu-push/logger launchpad.net/ubuntu-push/protocol launchpad.net/ubuntu-push/server launchpad.net/ubuntu-push/server/api launchpad.net/ubuntu-push/server/broker launchpad.net/ubuntu-push/server/broker/simple launchpad.net/ubuntu-push/server/broker/testing launchpad.net/ubuntu-push/server/broker/testsuite launchpad.net/ubuntu-push/server/dev launchpad.net/ubuntu-push/server/listener launchpad.net/ubuntu-push/server/session launchpad.net/ubuntu-push/server/store launchpad.net/ubuntu-push/testing launchpad.net/ubuntu-push/testing/condition launchpad.net/ubuntu-push/util launchpad.net/ubuntu-push/whoopsie launchpad.net/ubuntu-push/whoopsie/identifier launchpad.net/ubuntu-push/whoopsie/identifier/testing
? launchpad.net/ubuntu-push [no test files]
ok launchpad.net/ubuntu-push/bus 0.008s
ok launchpad.net/ubuntu-push/bus/connectivity 1.161s
ok launchpad.net/ubuntu-push/bus/networkmanager 0.097s
ok launchpad.net/ubuntu-push/bus/notifications 0.017s
ok launchpad.net/ubuntu-push/bus/systemimage 0.006s
ok launchpad.net/ubuntu-push/bus/testing 0.030s
ok launchpad.net/ubuntu-push/bus/urldispatcher 0.008s

----------------------------------------------------------------------
FAIL: client_test.go:291: clientSuite.TestStartServiceWorks

client_test.go:297:
    c.Check(cli.service.IsRunning(), Equals, true)
... obtained bool = false
... expected bool = true

2014/05/14 10:28:26.701116 INFO Sending initial 'disconnected'.
2014/05/14 10:28:26.701507 DEBUG Invoking Info
2014/05/14 10:28:26.701693 DEBUG got initial state of Connected Global
2014/05/14 10:28:26.701718 ERROR got weird PrimaryConnection: 0x46
2014/05/14 10:28:26.701725 DEBUG prima...

Read more...

Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :

The attempt to merge lp:~chipaca/ubuntu-push/service into lp:ubuntu-push/automatic failed. Below is the output from the failed tests.

rm -f -r /mnt/tarmac/cache/ubuntu-push-automatic/go-ws/pkg
mkdir -p /mnt/tarmac/cache/ubuntu-push-automatic/go-ws/bin
mkdir -p /mnt/tarmac/cache/ubuntu-push-automatic/go-ws/pkg
go get -u launchpad.net/godeps
go get -d -u launchpad.net/gocheck launchpad.net/go-dbus/v1 launchpad.net/go-xdg/v0 code.google.com/p/gosqlite/sqlite3 launchpad.net/~ubuntu-push-hackers/ubuntu-push/go-uuid/uuid
/mnt/tarmac/cache/ubuntu-push-automatic/go-ws/bin/godeps -u dependencies.tsv
"/mnt/tarmac/cache/ubuntu-push-automatic/go-ws/src/launchpad.net/gocheck" now at <email address hidden>
go install launchpad.net/gocheck launchpad.net/go-dbus/v1 launchpad.net/go-xdg/v0 code.google.com/p/gosqlite/sqlite3 launchpad.net/~ubuntu-push-hackers/ubuntu-push/go-uuid/uuid
env - PATH=/bin:/usr/bin:/sbin:/usr/sbin GOROOT= GOPATH=/mnt/tarmac/cache/ubuntu-push-automatic/go-ws dbus-launch --exit-with-session go test launchpad.net/ubuntu-push launchpad.net/ubuntu-push/bus launchpad.net/ubuntu-push/bus/connectivity launchpad.net/ubuntu-push/bus/networkmanager launchpad.net/ubuntu-push/bus/notifications launchpad.net/ubuntu-push/bus/systemimage launchpad.net/ubuntu-push/bus/testing launchpad.net/ubuntu-push/bus/urldispatcher launchpad.net/ubuntu-push/client launchpad.net/ubuntu-push/client/gethosts launchpad.net/ubuntu-push/client/service launchpad.net/ubuntu-push/client/session launchpad.net/ubuntu-push/client/session/levelmap launchpad.net/ubuntu-push/config launchpad.net/ubuntu-push/external/murmur3 launchpad.net/ubuntu-push/logger launchpad.net/ubuntu-push/protocol launchpad.net/ubuntu-push/server launchpad.net/ubuntu-push/server/api launchpad.net/ubuntu-push/server/broker launchpad.net/ubuntu-push/server/broker/simple launchpad.net/ubuntu-push/server/broker/testing launchpad.net/ubuntu-push/server/broker/testsuite launchpad.net/ubuntu-push/server/dev launchpad.net/ubuntu-push/server/listener launchpad.net/ubuntu-push/server/session launchpad.net/ubuntu-push/server/store launchpad.net/ubuntu-push/testing launchpad.net/ubuntu-push/testing/condition launchpad.net/ubuntu-push/util launchpad.net/ubuntu-push/whoopsie launchpad.net/ubuntu-push/whoopsie/identifier launchpad.net/ubuntu-push/whoopsie/identifier/testing

env: dbus-launch: No such file or directory
make: *** [check] Error 127

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

The attempt to merge lp:~chipaca/ubuntu-push/service into lp:ubuntu-push/automatic failed. Below is the output from the failed tests.

rm -f -r /mnt/tarmac/cache/ubuntu-push-automatic/go-ws/pkg
mkdir -p /mnt/tarmac/cache/ubuntu-push-automatic/go-ws/bin
mkdir -p /mnt/tarmac/cache/ubuntu-push-automatic/go-ws/pkg
go get -u launchpad.net/godeps
go get -d -u launchpad.net/gocheck launchpad.net/go-dbus/v1 launchpad.net/go-xdg/v0 code.google.com/p/gosqlite/sqlite3 launchpad.net/~ubuntu-push-hackers/ubuntu-push/go-uuid/uuid
/mnt/tarmac/cache/ubuntu-push-automatic/go-ws/bin/godeps -u dependencies.tsv
"/mnt/tarmac/cache/ubuntu-push-automatic/go-ws/src/launchpad.net/gocheck" now at <email address hidden>
go install launchpad.net/gocheck launchpad.net/go-dbus/v1 launchpad.net/go-xdg/v0 code.google.com/p/gosqlite/sqlite3 launchpad.net/~ubuntu-push-hackers/ubuntu-push/go-uuid/uuid
go test launchpad.net/ubuntu-push launchpad.net/ubuntu-push/bus launchpad.net/ubuntu-push/bus/connectivity launchpad.net/ubuntu-push/bus/networkmanager launchpad.net/ubuntu-push/bus/notifications launchpad.net/ubuntu-push/bus/systemimage launchpad.net/ubuntu-push/bus/testing launchpad.net/ubuntu-push/bus/urldispatcher launchpad.net/ubuntu-push/client launchpad.net/ubuntu-push/client/gethosts launchpad.net/ubuntu-push/client/service launchpad.net/ubuntu-push/client/session launchpad.net/ubuntu-push/client/session/levelmap launchpad.net/ubuntu-push/config launchpad.net/ubuntu-push/external/murmur3 launchpad.net/ubuntu-push/logger launchpad.net/ubuntu-push/protocol launchpad.net/ubuntu-push/server launchpad.net/ubuntu-push/server/api launchpad.net/ubuntu-push/server/broker launchpad.net/ubuntu-push/server/broker/simple launchpad.net/ubuntu-push/server/broker/testing launchpad.net/ubuntu-push/server/broker/testsuite launchpad.net/ubuntu-push/server/dev launchpad.net/ubuntu-push/server/listener launchpad.net/ubuntu-push/server/session launchpad.net/ubuntu-push/server/store launchpad.net/ubuntu-push/testing launchpad.net/ubuntu-push/testing/condition launchpad.net/ubuntu-push/util launchpad.net/ubuntu-push/whoopsie launchpad.net/ubuntu-push/whoopsie/identifier launchpad.net/ubuntu-push/whoopsie/identifier/testing
? launchpad.net/ubuntu-push [no test files]
ok launchpad.net/ubuntu-push/bus 0.009s
ok launchpad.net/ubuntu-push/bus/connectivity 1.174s
ok launchpad.net/ubuntu-push/bus/networkmanager 0.101s
ok launchpad.net/ubuntu-push/bus/notifications 0.016s
ok launchpad.net/ubuntu-push/bus/systemimage 0.006s
ok launchpad.net/ubuntu-push/bus/testing 0.017s
ok launchpad.net/ubuntu-push/bus/urldispatcher 0.006s
2014/05/14 11:21:15.348747 INFO "com.ubuntu.PushNotifications" dialed in.
2014/05/14 11:21:15.350269 INFO Sending initial 'disconnected'.
2014/05/14 11:21:15.364743 INFO "org.freedesktop.NetworkManager" dialed in.
2014/05/14 11:21:15.365179 INFO "com.canonical.URLDispatcher" dialed in.
2014/05/14 11:21:15.365235 INFO "com.canonical.SystemImage" dialed in.
2014/05/14 11:21:15.365264 INFO "org.freedesktop.Notifications" dialed in.
2014/05/14 11:21:15.365344 DEBUG Invoking Info
2014/05/14 11:21:15.365719 ERROR Info failed: org.freedesktop.D...

lp:~chipaca/ubuntu-push/service updated
148. By John Lenton

[r=pedronis] First pass at client/service.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2014-04-11 15:14:18 +0000
+++ .bzrignore 2014-05-14 12:29:13 +0000
@@ -13,3 +13,10 @@
13debian/*.substvars13debian/*.substvars
14ubuntu-push-client14ubuntu-push-client
15push-server-dev15push-server-dev
16signing-helper/CMakeCache.txt
17signing-helper/CMakeFiles
18signing-helper/Makefile
19signing-helper/cmake_install.cmake
20signing-helper/moc_signing.cpp
21signing-helper/signing-helper
22signing-helper/signing-helper_automoc.cpp
1623
=== modified file 'Makefile'
--- Makefile 2014-05-01 14:03:33 +0000
+++ Makefile 2014-05-14 12:29:13 +0000
@@ -33,9 +33,16 @@
33acceptance:33acceptance:
34 cd server/acceptance; ./acceptance.sh34 cd server/acceptance; ./acceptance.sh
3535
36build-client:36build-client: ubuntu-push-client signing-helper/signing-helper
37 go build ubuntu-push-client.go37
38 (cd signing-helper && cmake . && make)38%: %.go
39 go build $<
40
41signing-helper/Makefile: signing-helper/CMakeLists.txt signing-helper/signing-helper.cpp signing-helper/signing.h
42 cd signing-helper && (make clean || true) && cmake .
43
44signing-helper/signing-helper: signing-helper/Makefile signing-helper/signing-helper.cpp signing-helper/signing.h
45 cd signing-helper && make
3946
40build-server-dev:47build-server-dev:
41 go build -o push-server-dev launchpad.net/ubuntu-push/server/dev48 go build -o push-server-dev launchpad.net/ubuntu-push/server/dev
4249
=== modified file 'bus/testing/testing_endpoint.go'
--- bus/testing/testing_endpoint.go 2014-05-08 22:14:26 +0000
+++ bus/testing/testing_endpoint.go 2014-05-14 12:29:13 +0000
@@ -166,8 +166,15 @@
166 endp.dialCond, endp.callCond, endp.retvals)166 endp.dialCond, endp.callCond, endp.retvals)
167}167}
168168
169// see Endpoint's Close. This one does nothing.169// see Endpoint's Close. This one does nothing beyond registering
170func (tc *testingEndpoint) Close() {}170// being called.
171func (tc *testingEndpoint) Close() {
172 tc.callArgsLck.Lock()
173 defer tc.callArgsLck.Unlock()
174
175 args := callArgs{Member: "::Close"}
176 tc.callArgs = append(tc.callArgs, args)
177}
171178
172func (tc *testingEndpoint) GrabName(allowReplacement bool) <-chan error {179func (tc *testingEndpoint) GrabName(allowReplacement bool) <-chan error {
173 tc.callArgsLck.Lock()180 tc.callArgsLck.Lock()
174181
=== modified file 'bus/testing/testing_endpoint_test.go'
--- bus/testing/testing_endpoint_test.go 2014-05-08 15:43:43 +0000
+++ bus/testing/testing_endpoint_test.go 2014-05-14 12:29:13 +0000
@@ -102,7 +102,11 @@
102func (s *TestingEndpointSuite) TestCloser(c *C) {102func (s *TestingEndpointSuite) TestCloser(c *C) {
103 endp := NewTestingEndpoint(nil, condition.Work(true))103 endp := NewTestingEndpoint(nil, condition.Work(true))
104 endp.Close()104 endp.Close()
105 // ... yay?105 c.Check(GetCallArgs(endp), DeepEquals, []callArgs{
106 {
107 Member: "::Close",
108 Args: nil,
109 }})
106}110}
107111
108// Test that WatchSignal() with a negative condition returns an error.112// Test that WatchSignal() with a negative condition returns an error.
109113
=== modified file 'client/client.go'
--- client/client.go 2014-05-02 10:42:16 +0000
+++ client/client.go 2014-05-14 12:29:13 +0000
@@ -34,6 +34,7 @@
34 "launchpad.net/ubuntu-push/bus/notifications"34 "launchpad.net/ubuntu-push/bus/notifications"
35 "launchpad.net/ubuntu-push/bus/systemimage"35 "launchpad.net/ubuntu-push/bus/systemimage"
36 "launchpad.net/ubuntu-push/bus/urldispatcher"36 "launchpad.net/ubuntu-push/bus/urldispatcher"
37 "launchpad.net/ubuntu-push/client/service"
37 "launchpad.net/ubuntu-push/client/session"38 "launchpad.net/ubuntu-push/client/session"
38 "launchpad.net/ubuntu-push/client/session/levelmap"39 "launchpad.net/ubuntu-push/client/session/levelmap"
39 "launchpad.net/ubuntu-push/config"40 "launchpad.net/ubuntu-push/config"
@@ -79,6 +80,8 @@
79 actionsCh <-chan notifications.RawActionReply80 actionsCh <-chan notifications.RawActionReply
80 session *session.ClientSession81 session *session.ClientSession
81 sessionConnectedCh chan uint3282 sessionConnectedCh chan uint32
83 serviceEndpoint bus.Endpoint
84 service *service.Service
82}85}
8386
84var ACTION_ID_SNOWFLAKE = "::ubuntu-push-client::"87var ACTION_ID_SNOWFLAKE = "::ubuntu-push-client::"
@@ -348,10 +351,20 @@
348 client.handleNotification, client.handleErr)351 client.handleNotification, client.handleErr)
349}352}
350353
354func (client *PushClient) startService() error {
355 if client.serviceEndpoint == nil {
356 client.serviceEndpoint = bus.SessionBus.Endpoint(service.BusAddress, client.log)
357 }
358
359 client.service = service.NewService(client.serviceEndpoint, client.log)
360 return client.service.Start()
361}
362
351// Start calls doStart with the "real" starters363// Start calls doStart with the "real" starters
352func (client *PushClient) Start() error {364func (client *PushClient) Start() error {
353 return client.doStart(365 return client.doStart(
354 client.configure,366 client.configure,
367 client.startService,
355 client.getDeviceId,368 client.getDeviceId,
356 client.takeTheBus,369 client.takeTheBus,
357 client.initSession,370 client.initSession,
358371
=== modified file 'client/client_test.go'
--- client/client_test.go 2014-05-02 10:42:16 +0000
+++ client/client_test.go 2014-05-14 12:29:13 +0000
@@ -285,6 +285,34 @@
285}285}
286286
287/*****************************************************************287/*****************************************************************
288 startService tests
289******************************************************************/
290
291func (cs *clientSuite) TestStartServiceWorks(c *C) {
292 cli := NewPushClient(cs.configPath, cs.leveldbPath)
293 cli.log = cs.log
294 cli.serviceEndpoint = testibus.NewTestingEndpoint(condition.Work(true), nil)
295 c.Check(cli.service, IsNil)
296 c.Check(cli.startService(), IsNil)
297 c.Assert(cli.service, NotNil)
298 c.Check(cli.service.IsRunning(), Equals, true)
299 cli.service.Stop()
300}
301
302func (cs *clientSuite) TestStartServiceErrorsOnNilLog(c *C) {
303 cli := NewPushClient(cs.configPath, cs.leveldbPath)
304 c.Check(cli.log, IsNil)
305 c.Check(cli.startService(), NotNil)
306}
307
308func (cs *clientSuite) TestStartServiceErrorsOnBusDialFail(c *C) {
309 cli := NewPushClient(cs.configPath, cs.leveldbPath)
310 cli.log = cs.log
311 cli.serviceEndpoint = testibus.NewTestingEndpoint(condition.Work(false), nil)
312 c.Check(cli.startService(), NotNil)
313}
314
315/*****************************************************************
288 getDeviceId tests316 getDeviceId tests
289******************************************************************/317******************************************************************/
290318
@@ -788,6 +816,8 @@
788816
789 cli := NewPushClient(cs.configPath, cs.leveldbPath)817 cli := NewPushClient(cs.configPath, cs.leveldbPath)
790 // before start, everything sucks:818 // before start, everything sucks:
819 // no service,
820 c.Check(cli.service, IsNil)
791 // no config,821 // no config,
792 c.Check(string(cli.config.Addr), Equals, "")822 c.Check(string(cli.config.Addr), Equals, "")
793 // no device id,823 // no device id,
@@ -811,7 +841,10 @@
811 c.Check(cli.session, NotNil)841 c.Check(cli.session, NotNil)
812 // and a bus,842 // and a bus,
813 c.Check(cli.notificationsEndp, NotNil)843 c.Check(cli.notificationsEndp, NotNil)
844 // and a service,
845 c.Check(cli.service, NotNil)
814 // and everthying us just peachy!846 // and everthying us just peachy!
847 cli.service.Stop() // cleanup
815}848}
816849
817func (cs *clientSuite) TestStartCanFail(c *C) {850func (cs *clientSuite) TestStartCanFail(c *C) {
818851
=== added directory 'client/service'
=== added file 'client/service/service.go'
--- client/service/service.go 1970-01-01 00:00:00 +0000
+++ client/service/service.go 2014-05-14 12:29:13 +0000
@@ -0,0 +1,82 @@
1package service
2
3import (
4 "errors"
5 "sync"
6
7 "launchpad.net/ubuntu-push/bus"
8 "launchpad.net/ubuntu-push/logger"
9)
10
11type Service struct {
12 lock sync.RWMutex
13 state ServiceState
14 Log logger.Logger
15 Bus bus.Endpoint
16}
17
18type ServiceState uint8
19
20const (
21 StateUnknown ServiceState = iota
22 StateRunning
23 StateFinished
24)
25
26var (
27 NotConfigured = errors.New("not configured")
28 AlreadyStarted = errors.New("already started")
29 BusAddress = bus.Address{
30 Interface: "com.ubuntu.PushNotifications",
31 Path: "com/ubuntu/PushNotifications",
32 Name: "com.ubuntu.PushNotifications",
33 }
34)
35
36func NewService(bus bus.Endpoint, log logger.Logger) *Service {
37 return &Service{Log: log, Bus: bus}
38}
39
40func (svc *Service) IsRunning() bool {
41 svc.lock.RLock()
42 defer svc.lock.RUnlock()
43 return svc.state == StateRunning
44}
45
46func (svc *Service) Start() error {
47 svc.lock.Lock()
48 defer svc.lock.Unlock()
49 if svc.state != StateUnknown {
50 return AlreadyStarted
51 }
52 if svc.Log == nil || svc.Bus == nil {
53 return NotConfigured
54 }
55 err := svc.Bus.Dial()
56 if err != nil {
57 return err
58 }
59 ch := svc.Bus.GrabName(true)
60 log := svc.Log
61 go func() {
62 for err := range ch {
63 if !svc.IsRunning() {
64 break
65 }
66 if err != nil {
67 log.Fatalf("name channel for %s got: %v", BusAddress.Name, err)
68 }
69 }
70 }()
71 svc.state = StateRunning
72 return nil
73}
74
75func (svc *Service) Stop() {
76 svc.lock.Lock()
77 defer svc.lock.Unlock()
78 if svc.Bus != nil {
79 svc.Bus.Close()
80 }
81 svc.state = StateFinished
82}
083
=== added file 'client/service/service_test.go'
--- client/service/service_test.go 1970-01-01 00:00:00 +0000
+++ client/service/service_test.go 2014-05-14 12:29:13 +0000
@@ -0,0 +1,93 @@
1/*
2 Copyright 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 service
18
19import (
20 "testing"
21
22 . "launchpad.net/gocheck"
23
24 "launchpad.net/ubuntu-push/bus"
25 testibus "launchpad.net/ubuntu-push/bus/testing"
26 "launchpad.net/ubuntu-push/logger"
27 helpers "launchpad.net/ubuntu-push/testing"
28 "launchpad.net/ubuntu-push/testing/condition"
29)
30
31func TestService(t *testing.T) { TestingT(t) }
32
33type serviceSuite struct {
34 log logger.Logger
35 bus bus.Endpoint
36}
37
38var _ = Suite(&serviceSuite{})
39
40func (ss *serviceSuite) SetUpTest(c *C) {
41 ss.log = helpers.NewTestLogger(c, "debug")
42 ss.bus = testibus.NewTestingEndpoint(condition.Work(true), nil)
43}
44
45func (ss *serviceSuite) TestStart(c *C) {
46 svc := NewService(ss.bus, ss.log)
47 c.Check(svc.IsRunning(), Equals, false)
48 c.Check(svc.Start(), IsNil)
49 c.Check(svc.IsRunning(), Equals, true)
50 svc.Stop()
51}
52
53func (ss *serviceSuite) TestStartTwice(c *C) {
54 svc := NewService(ss.bus, ss.log)
55 c.Check(svc.Start(), IsNil)
56 c.Check(svc.Start(), Equals, AlreadyStarted)
57 svc.Stop()
58}
59
60func (ss *serviceSuite) TestStartNoLog(c *C) {
61 svc := NewService(ss.bus, nil)
62 c.Check(svc.Start(), Equals, NotConfigured)
63}
64
65func (ss *serviceSuite) TestStartNoBus(c *C) {
66 svc := NewService(nil, ss.log)
67 c.Check(svc.Start(), Equals, NotConfigured)
68}
69
70func (ss *serviceSuite) TestStartFailsOnBusDialFailure(c *C) {
71 bus := testibus.NewTestingEndpoint(condition.Work(false), nil)
72 svc := NewService(bus, ss.log)
73 c.Check(svc.Start(), ErrorMatches, `.*(?i)cond said no.*`)
74 svc.Stop()
75}
76
77func (ss *serviceSuite) TestStartGrabsName(c *C) {
78 svc := NewService(ss.bus, ss.log)
79 c.Assert(svc.Start(), IsNil)
80 callArgs := testibus.GetCallArgs(ss.bus)
81 defer svc.Stop()
82 c.Assert(callArgs, HasLen, 1)
83 c.Check(callArgs[0].Member, Equals, "::GrabName")
84}
85
86func (ss *serviceSuite) TestStopClosesBus(c *C) {
87 svc := NewService(ss.bus, ss.log)
88 c.Assert(svc.Start(), IsNil)
89 svc.Stop()
90 callArgs := testibus.GetCallArgs(ss.bus)
91 c.Assert(callArgs, HasLen, 2)
92 c.Check(callArgs[1].Member, Equals, "::Close")
93}
094
=== modified file 'ubuntu-push-client.go'
--- ubuntu-push-client.go 2014-04-30 16:44:16 +0000
+++ ubuntu-push-client.go 2014-05-14 12:29:13 +0000
@@ -19,37 +19,12 @@
19import (19import (
20 "log"20 "log"
2121
22 "launchpad.net/go-dbus/v1"
23 "launchpad.net/go-xdg/v0"22 "launchpad.net/go-xdg/v0"
2423
25 "launchpad.net/ubuntu-push/client"24 "launchpad.net/ubuntu-push/client"
26)25)
2726
28const NAME = "com.ubuntu.PushNotifications"
29
30// grabName grabs ownership of the dbus name, and bails the client as
31// soon as somebody else grabs it.
32func grabName() {
33 conn, err := dbus.Connect(dbus.SessionBus)
34 if err != nil {
35 log.Fatalf("bus: %v", err)
36 }
37
38 flags := dbus.NameFlagAllowReplacement | dbus.NameFlagReplaceExisting
39 n := conn.RequestName(NAME, flags)
40 go func() {
41 for err := range n.C {
42 if err != nil {
43 log.Fatalf("FATAL: name channel got: %v", err)
44 }
45 }
46 }()
47}
48
49func main() {27func main() {
50 // XXX: this is a quick hack to ensure unicity
51 grabName()
52
53 cfgFname, err := xdg.Config.Find("ubuntu-push-client/config.json")28 cfgFname, err := xdg.Config.Find("ubuntu-push-client/config.json")
54 if err != nil {29 if err != nil {
55 log.Fatalf("unable to find a configuration file: %v", err)30 log.Fatalf("unable to find a configuration file: %v", err)

Subscribers

People subscribed via source and target branches