Merge lp:~chipaca/ubuntu-push/service into lp:ubuntu-push/automatic
- service
- Merge into automatic
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 |
Related bugs: |
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.
Samuele Pedroni (pedronis) wrote : | # |
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
Samuele Pedroni (pedronis) : | # |
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/
mkdir -p /mnt/tarmac/
mkdir -p /mnt/tarmac/
go get -u launchpad.
go get -d -u launchpad.
/mnt/tarmac/
"/mnt/tarmac/
go install launchpad.
go test launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
-------
FAIL: client_test.go:291: clientSuite.
client_test.go:297:
c.Check(
... 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...
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/
mkdir -p /mnt/tarmac/
mkdir -p /mnt/tarmac/
go get -u launchpad.
go get -d -u launchpad.
/mnt/tarmac/
"/mnt/tarmac/
go install launchpad.
env - PATH=/bin:
env: dbus-launch: No such file or directory
make: *** [check] Error 127
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/
mkdir -p /mnt/tarmac/
mkdir -p /mnt/tarmac/
go get -u launchpad.
go get -d -u launchpad.
/mnt/tarmac/
"/mnt/tarmac/
go install launchpad.
go test launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
2014/05/14 11:21:15.348747 INFO "com.ubuntu.
2014/05/14 11:21:15.350269 INFO Sending initial 'disconnected'.
2014/05/14 11:21:15.364743 INFO "org.freedeskto
2014/05/14 11:21:15.365179 INFO "com.canonical.
2014/05/14 11:21:15.365235 INFO "com.canonical.
2014/05/14 11:21:15.365264 INFO "org.freedeskto
2014/05/14 11:21:15.365344 DEBUG Invoking Info
2014/05/14 11:21:15.365719 ERROR Info failed: org.freedesktop
- 148. By John Lenton
-
[r=pedronis] First pass at client/service.
Preview Diff
1 | === modified file '.bzrignore' | |||
2 | --- .bzrignore 2014-04-11 15:14:18 +0000 | |||
3 | +++ .bzrignore 2014-05-14 12:29:13 +0000 | |||
4 | @@ -13,3 +13,10 @@ | |||
5 | 13 | debian/*.substvars | 13 | debian/*.substvars |
6 | 14 | ubuntu-push-client | 14 | ubuntu-push-client |
7 | 15 | push-server-dev | 15 | push-server-dev |
8 | 16 | signing-helper/CMakeCache.txt | ||
9 | 17 | signing-helper/CMakeFiles | ||
10 | 18 | signing-helper/Makefile | ||
11 | 19 | signing-helper/cmake_install.cmake | ||
12 | 20 | signing-helper/moc_signing.cpp | ||
13 | 21 | signing-helper/signing-helper | ||
14 | 22 | signing-helper/signing-helper_automoc.cpp | ||
15 | 16 | 23 | ||
16 | === modified file 'Makefile' | |||
17 | --- Makefile 2014-05-01 14:03:33 +0000 | |||
18 | +++ Makefile 2014-05-14 12:29:13 +0000 | |||
19 | @@ -33,9 +33,16 @@ | |||
20 | 33 | acceptance: | 33 | acceptance: |
21 | 34 | cd server/acceptance; ./acceptance.sh | 34 | cd server/acceptance; ./acceptance.sh |
22 | 35 | 35 | ||
26 | 36 | build-client: | 36 | build-client: ubuntu-push-client signing-helper/signing-helper |
27 | 37 | go build ubuntu-push-client.go | 37 | |
28 | 38 | (cd signing-helper && cmake . && make) | 38 | %: %.go |
29 | 39 | go build $< | ||
30 | 40 | |||
31 | 41 | signing-helper/Makefile: signing-helper/CMakeLists.txt signing-helper/signing-helper.cpp signing-helper/signing.h | ||
32 | 42 | cd signing-helper && (make clean || true) && cmake . | ||
33 | 43 | |||
34 | 44 | signing-helper/signing-helper: signing-helper/Makefile signing-helper/signing-helper.cpp signing-helper/signing.h | ||
35 | 45 | cd signing-helper && make | ||
36 | 39 | 46 | ||
37 | 40 | build-server-dev: | 47 | build-server-dev: |
38 | 41 | go build -o push-server-dev launchpad.net/ubuntu-push/server/dev | 48 | go build -o push-server-dev launchpad.net/ubuntu-push/server/dev |
39 | 42 | 49 | ||
40 | === modified file 'bus/testing/testing_endpoint.go' | |||
41 | --- bus/testing/testing_endpoint.go 2014-05-08 22:14:26 +0000 | |||
42 | +++ bus/testing/testing_endpoint.go 2014-05-14 12:29:13 +0000 | |||
43 | @@ -166,8 +166,15 @@ | |||
44 | 166 | endp.dialCond, endp.callCond, endp.retvals) | 166 | endp.dialCond, endp.callCond, endp.retvals) |
45 | 167 | } | 167 | } |
46 | 168 | 168 | ||
49 | 169 | // see Endpoint's Close. This one does nothing. | 169 | // see Endpoint's Close. This one does nothing beyond registering |
50 | 170 | func (tc *testingEndpoint) Close() {} | 170 | // being called. |
51 | 171 | func (tc *testingEndpoint) Close() { | ||
52 | 172 | tc.callArgsLck.Lock() | ||
53 | 173 | defer tc.callArgsLck.Unlock() | ||
54 | 174 | |||
55 | 175 | args := callArgs{Member: "::Close"} | ||
56 | 176 | tc.callArgs = append(tc.callArgs, args) | ||
57 | 177 | } | ||
58 | 171 | 178 | ||
59 | 172 | func (tc *testingEndpoint) GrabName(allowReplacement bool) <-chan error { | 179 | func (tc *testingEndpoint) GrabName(allowReplacement bool) <-chan error { |
60 | 173 | tc.callArgsLck.Lock() | 180 | tc.callArgsLck.Lock() |
61 | 174 | 181 | ||
62 | === modified file 'bus/testing/testing_endpoint_test.go' | |||
63 | --- bus/testing/testing_endpoint_test.go 2014-05-08 15:43:43 +0000 | |||
64 | +++ bus/testing/testing_endpoint_test.go 2014-05-14 12:29:13 +0000 | |||
65 | @@ -102,7 +102,11 @@ | |||
66 | 102 | func (s *TestingEndpointSuite) TestCloser(c *C) { | 102 | func (s *TestingEndpointSuite) TestCloser(c *C) { |
67 | 103 | endp := NewTestingEndpoint(nil, condition.Work(true)) | 103 | endp := NewTestingEndpoint(nil, condition.Work(true)) |
68 | 104 | endp.Close() | 104 | endp.Close() |
70 | 105 | // ... yay? | 105 | c.Check(GetCallArgs(endp), DeepEquals, []callArgs{ |
71 | 106 | { | ||
72 | 107 | Member: "::Close", | ||
73 | 108 | Args: nil, | ||
74 | 109 | }}) | ||
75 | 106 | } | 110 | } |
76 | 107 | 111 | ||
77 | 108 | // Test that WatchSignal() with a negative condition returns an error. | 112 | // Test that WatchSignal() with a negative condition returns an error. |
78 | 109 | 113 | ||
79 | === modified file 'client/client.go' | |||
80 | --- client/client.go 2014-05-02 10:42:16 +0000 | |||
81 | +++ client/client.go 2014-05-14 12:29:13 +0000 | |||
82 | @@ -34,6 +34,7 @@ | |||
83 | 34 | "launchpad.net/ubuntu-push/bus/notifications" | 34 | "launchpad.net/ubuntu-push/bus/notifications" |
84 | 35 | "launchpad.net/ubuntu-push/bus/systemimage" | 35 | "launchpad.net/ubuntu-push/bus/systemimage" |
85 | 36 | "launchpad.net/ubuntu-push/bus/urldispatcher" | 36 | "launchpad.net/ubuntu-push/bus/urldispatcher" |
86 | 37 | "launchpad.net/ubuntu-push/client/service" | ||
87 | 37 | "launchpad.net/ubuntu-push/client/session" | 38 | "launchpad.net/ubuntu-push/client/session" |
88 | 38 | "launchpad.net/ubuntu-push/client/session/levelmap" | 39 | "launchpad.net/ubuntu-push/client/session/levelmap" |
89 | 39 | "launchpad.net/ubuntu-push/config" | 40 | "launchpad.net/ubuntu-push/config" |
90 | @@ -79,6 +80,8 @@ | |||
91 | 79 | actionsCh <-chan notifications.RawActionReply | 80 | actionsCh <-chan notifications.RawActionReply |
92 | 80 | session *session.ClientSession | 81 | session *session.ClientSession |
93 | 81 | sessionConnectedCh chan uint32 | 82 | sessionConnectedCh chan uint32 |
94 | 83 | serviceEndpoint bus.Endpoint | ||
95 | 84 | service *service.Service | ||
96 | 82 | } | 85 | } |
97 | 83 | 86 | ||
98 | 84 | var ACTION_ID_SNOWFLAKE = "::ubuntu-push-client::" | 87 | var ACTION_ID_SNOWFLAKE = "::ubuntu-push-client::" |
99 | @@ -348,10 +351,20 @@ | |||
100 | 348 | client.handleNotification, client.handleErr) | 351 | client.handleNotification, client.handleErr) |
101 | 349 | } | 352 | } |
102 | 350 | 353 | ||
103 | 354 | func (client *PushClient) startService() error { | ||
104 | 355 | if client.serviceEndpoint == nil { | ||
105 | 356 | client.serviceEndpoint = bus.SessionBus.Endpoint(service.BusAddress, client.log) | ||
106 | 357 | } | ||
107 | 358 | |||
108 | 359 | client.service = service.NewService(client.serviceEndpoint, client.log) | ||
109 | 360 | return client.service.Start() | ||
110 | 361 | } | ||
111 | 362 | |||
112 | 351 | // Start calls doStart with the "real" starters | 363 | // Start calls doStart with the "real" starters |
113 | 352 | func (client *PushClient) Start() error { | 364 | func (client *PushClient) Start() error { |
114 | 353 | return client.doStart( | 365 | return client.doStart( |
115 | 354 | client.configure, | 366 | client.configure, |
116 | 367 | client.startService, | ||
117 | 355 | client.getDeviceId, | 368 | client.getDeviceId, |
118 | 356 | client.takeTheBus, | 369 | client.takeTheBus, |
119 | 357 | client.initSession, | 370 | client.initSession, |
120 | 358 | 371 | ||
121 | === modified file 'client/client_test.go' | |||
122 | --- client/client_test.go 2014-05-02 10:42:16 +0000 | |||
123 | +++ client/client_test.go 2014-05-14 12:29:13 +0000 | |||
124 | @@ -285,6 +285,34 @@ | |||
125 | 285 | } | 285 | } |
126 | 286 | 286 | ||
127 | 287 | /***************************************************************** | 287 | /***************************************************************** |
128 | 288 | startService tests | ||
129 | 289 | ******************************************************************/ | ||
130 | 290 | |||
131 | 291 | func (cs *clientSuite) TestStartServiceWorks(c *C) { | ||
132 | 292 | cli := NewPushClient(cs.configPath, cs.leveldbPath) | ||
133 | 293 | cli.log = cs.log | ||
134 | 294 | cli.serviceEndpoint = testibus.NewTestingEndpoint(condition.Work(true), nil) | ||
135 | 295 | c.Check(cli.service, IsNil) | ||
136 | 296 | c.Check(cli.startService(), IsNil) | ||
137 | 297 | c.Assert(cli.service, NotNil) | ||
138 | 298 | c.Check(cli.service.IsRunning(), Equals, true) | ||
139 | 299 | cli.service.Stop() | ||
140 | 300 | } | ||
141 | 301 | |||
142 | 302 | func (cs *clientSuite) TestStartServiceErrorsOnNilLog(c *C) { | ||
143 | 303 | cli := NewPushClient(cs.configPath, cs.leveldbPath) | ||
144 | 304 | c.Check(cli.log, IsNil) | ||
145 | 305 | c.Check(cli.startService(), NotNil) | ||
146 | 306 | } | ||
147 | 307 | |||
148 | 308 | func (cs *clientSuite) TestStartServiceErrorsOnBusDialFail(c *C) { | ||
149 | 309 | cli := NewPushClient(cs.configPath, cs.leveldbPath) | ||
150 | 310 | cli.log = cs.log | ||
151 | 311 | cli.serviceEndpoint = testibus.NewTestingEndpoint(condition.Work(false), nil) | ||
152 | 312 | c.Check(cli.startService(), NotNil) | ||
153 | 313 | } | ||
154 | 314 | |||
155 | 315 | /***************************************************************** | ||
156 | 288 | getDeviceId tests | 316 | getDeviceId tests |
157 | 289 | ******************************************************************/ | 317 | ******************************************************************/ |
158 | 290 | 318 | ||
159 | @@ -788,6 +816,8 @@ | |||
160 | 788 | 816 | ||
161 | 789 | cli := NewPushClient(cs.configPath, cs.leveldbPath) | 817 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
162 | 790 | // before start, everything sucks: | 818 | // before start, everything sucks: |
163 | 819 | // no service, | ||
164 | 820 | c.Check(cli.service, IsNil) | ||
165 | 791 | // no config, | 821 | // no config, |
166 | 792 | c.Check(string(cli.config.Addr), Equals, "") | 822 | c.Check(string(cli.config.Addr), Equals, "") |
167 | 793 | // no device id, | 823 | // no device id, |
168 | @@ -811,7 +841,10 @@ | |||
169 | 811 | c.Check(cli.session, NotNil) | 841 | c.Check(cli.session, NotNil) |
170 | 812 | // and a bus, | 842 | // and a bus, |
171 | 813 | c.Check(cli.notificationsEndp, NotNil) | 843 | c.Check(cli.notificationsEndp, NotNil) |
172 | 844 | // and a service, | ||
173 | 845 | c.Check(cli.service, NotNil) | ||
174 | 814 | // and everthying us just peachy! | 846 | // and everthying us just peachy! |
175 | 847 | cli.service.Stop() // cleanup | ||
176 | 815 | } | 848 | } |
177 | 816 | 849 | ||
178 | 817 | func (cs *clientSuite) TestStartCanFail(c *C) { | 850 | func (cs *clientSuite) TestStartCanFail(c *C) { |
179 | 818 | 851 | ||
180 | === added directory 'client/service' | |||
181 | === added file 'client/service/service.go' | |||
182 | --- client/service/service.go 1970-01-01 00:00:00 +0000 | |||
183 | +++ client/service/service.go 2014-05-14 12:29:13 +0000 | |||
184 | @@ -0,0 +1,82 @@ | |||
185 | 1 | package service | ||
186 | 2 | |||
187 | 3 | import ( | ||
188 | 4 | "errors" | ||
189 | 5 | "sync" | ||
190 | 6 | |||
191 | 7 | "launchpad.net/ubuntu-push/bus" | ||
192 | 8 | "launchpad.net/ubuntu-push/logger" | ||
193 | 9 | ) | ||
194 | 10 | |||
195 | 11 | type Service struct { | ||
196 | 12 | lock sync.RWMutex | ||
197 | 13 | state ServiceState | ||
198 | 14 | Log logger.Logger | ||
199 | 15 | Bus bus.Endpoint | ||
200 | 16 | } | ||
201 | 17 | |||
202 | 18 | type ServiceState uint8 | ||
203 | 19 | |||
204 | 20 | const ( | ||
205 | 21 | StateUnknown ServiceState = iota | ||
206 | 22 | StateRunning | ||
207 | 23 | StateFinished | ||
208 | 24 | ) | ||
209 | 25 | |||
210 | 26 | var ( | ||
211 | 27 | NotConfigured = errors.New("not configured") | ||
212 | 28 | AlreadyStarted = errors.New("already started") | ||
213 | 29 | BusAddress = bus.Address{ | ||
214 | 30 | Interface: "com.ubuntu.PushNotifications", | ||
215 | 31 | Path: "com/ubuntu/PushNotifications", | ||
216 | 32 | Name: "com.ubuntu.PushNotifications", | ||
217 | 33 | } | ||
218 | 34 | ) | ||
219 | 35 | |||
220 | 36 | func NewService(bus bus.Endpoint, log logger.Logger) *Service { | ||
221 | 37 | return &Service{Log: log, Bus: bus} | ||
222 | 38 | } | ||
223 | 39 | |||
224 | 40 | func (svc *Service) IsRunning() bool { | ||
225 | 41 | svc.lock.RLock() | ||
226 | 42 | defer svc.lock.RUnlock() | ||
227 | 43 | return svc.state == StateRunning | ||
228 | 44 | } | ||
229 | 45 | |||
230 | 46 | func (svc *Service) Start() error { | ||
231 | 47 | svc.lock.Lock() | ||
232 | 48 | defer svc.lock.Unlock() | ||
233 | 49 | if svc.state != StateUnknown { | ||
234 | 50 | return AlreadyStarted | ||
235 | 51 | } | ||
236 | 52 | if svc.Log == nil || svc.Bus == nil { | ||
237 | 53 | return NotConfigured | ||
238 | 54 | } | ||
239 | 55 | err := svc.Bus.Dial() | ||
240 | 56 | if err != nil { | ||
241 | 57 | return err | ||
242 | 58 | } | ||
243 | 59 | ch := svc.Bus.GrabName(true) | ||
244 | 60 | log := svc.Log | ||
245 | 61 | go func() { | ||
246 | 62 | for err := range ch { | ||
247 | 63 | if !svc.IsRunning() { | ||
248 | 64 | break | ||
249 | 65 | } | ||
250 | 66 | if err != nil { | ||
251 | 67 | log.Fatalf("name channel for %s got: %v", BusAddress.Name, err) | ||
252 | 68 | } | ||
253 | 69 | } | ||
254 | 70 | }() | ||
255 | 71 | svc.state = StateRunning | ||
256 | 72 | return nil | ||
257 | 73 | } | ||
258 | 74 | |||
259 | 75 | func (svc *Service) Stop() { | ||
260 | 76 | svc.lock.Lock() | ||
261 | 77 | defer svc.lock.Unlock() | ||
262 | 78 | if svc.Bus != nil { | ||
263 | 79 | svc.Bus.Close() | ||
264 | 80 | } | ||
265 | 81 | svc.state = StateFinished | ||
266 | 82 | } | ||
267 | 0 | 83 | ||
268 | === added file 'client/service/service_test.go' | |||
269 | --- client/service/service_test.go 1970-01-01 00:00:00 +0000 | |||
270 | +++ client/service/service_test.go 2014-05-14 12:29:13 +0000 | |||
271 | @@ -0,0 +1,93 @@ | |||
272 | 1 | /* | ||
273 | 2 | Copyright 2014 Canonical Ltd. | ||
274 | 3 | |||
275 | 4 | This program is free software: you can redistribute it and/or modify it | ||
276 | 5 | under the terms of the GNU General Public License version 3, as published | ||
277 | 6 | by the Free Software Foundation. | ||
278 | 7 | |||
279 | 8 | This program is distributed in the hope that it will be useful, but | ||
280 | 9 | WITHOUT ANY WARRANTY; without even the implied warranties of | ||
281 | 10 | MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
282 | 11 | PURPOSE. See the GNU General Public License for more details. | ||
283 | 12 | |||
284 | 13 | You should have received a copy of the GNU General Public License along | ||
285 | 14 | with this program. If not, see <http://www.gnu.org/licenses/>. | ||
286 | 15 | */ | ||
287 | 16 | |||
288 | 17 | package service | ||
289 | 18 | |||
290 | 19 | import ( | ||
291 | 20 | "testing" | ||
292 | 21 | |||
293 | 22 | . "launchpad.net/gocheck" | ||
294 | 23 | |||
295 | 24 | "launchpad.net/ubuntu-push/bus" | ||
296 | 25 | testibus "launchpad.net/ubuntu-push/bus/testing" | ||
297 | 26 | "launchpad.net/ubuntu-push/logger" | ||
298 | 27 | helpers "launchpad.net/ubuntu-push/testing" | ||
299 | 28 | "launchpad.net/ubuntu-push/testing/condition" | ||
300 | 29 | ) | ||
301 | 30 | |||
302 | 31 | func TestService(t *testing.T) { TestingT(t) } | ||
303 | 32 | |||
304 | 33 | type serviceSuite struct { | ||
305 | 34 | log logger.Logger | ||
306 | 35 | bus bus.Endpoint | ||
307 | 36 | } | ||
308 | 37 | |||
309 | 38 | var _ = Suite(&serviceSuite{}) | ||
310 | 39 | |||
311 | 40 | func (ss *serviceSuite) SetUpTest(c *C) { | ||
312 | 41 | ss.log = helpers.NewTestLogger(c, "debug") | ||
313 | 42 | ss.bus = testibus.NewTestingEndpoint(condition.Work(true), nil) | ||
314 | 43 | } | ||
315 | 44 | |||
316 | 45 | func (ss *serviceSuite) TestStart(c *C) { | ||
317 | 46 | svc := NewService(ss.bus, ss.log) | ||
318 | 47 | c.Check(svc.IsRunning(), Equals, false) | ||
319 | 48 | c.Check(svc.Start(), IsNil) | ||
320 | 49 | c.Check(svc.IsRunning(), Equals, true) | ||
321 | 50 | svc.Stop() | ||
322 | 51 | } | ||
323 | 52 | |||
324 | 53 | func (ss *serviceSuite) TestStartTwice(c *C) { | ||
325 | 54 | svc := NewService(ss.bus, ss.log) | ||
326 | 55 | c.Check(svc.Start(), IsNil) | ||
327 | 56 | c.Check(svc.Start(), Equals, AlreadyStarted) | ||
328 | 57 | svc.Stop() | ||
329 | 58 | } | ||
330 | 59 | |||
331 | 60 | func (ss *serviceSuite) TestStartNoLog(c *C) { | ||
332 | 61 | svc := NewService(ss.bus, nil) | ||
333 | 62 | c.Check(svc.Start(), Equals, NotConfigured) | ||
334 | 63 | } | ||
335 | 64 | |||
336 | 65 | func (ss *serviceSuite) TestStartNoBus(c *C) { | ||
337 | 66 | svc := NewService(nil, ss.log) | ||
338 | 67 | c.Check(svc.Start(), Equals, NotConfigured) | ||
339 | 68 | } | ||
340 | 69 | |||
341 | 70 | func (ss *serviceSuite) TestStartFailsOnBusDialFailure(c *C) { | ||
342 | 71 | bus := testibus.NewTestingEndpoint(condition.Work(false), nil) | ||
343 | 72 | svc := NewService(bus, ss.log) | ||
344 | 73 | c.Check(svc.Start(), ErrorMatches, `.*(?i)cond said no.*`) | ||
345 | 74 | svc.Stop() | ||
346 | 75 | } | ||
347 | 76 | |||
348 | 77 | func (ss *serviceSuite) TestStartGrabsName(c *C) { | ||
349 | 78 | svc := NewService(ss.bus, ss.log) | ||
350 | 79 | c.Assert(svc.Start(), IsNil) | ||
351 | 80 | callArgs := testibus.GetCallArgs(ss.bus) | ||
352 | 81 | defer svc.Stop() | ||
353 | 82 | c.Assert(callArgs, HasLen, 1) | ||
354 | 83 | c.Check(callArgs[0].Member, Equals, "::GrabName") | ||
355 | 84 | } | ||
356 | 85 | |||
357 | 86 | func (ss *serviceSuite) TestStopClosesBus(c *C) { | ||
358 | 87 | svc := NewService(ss.bus, ss.log) | ||
359 | 88 | c.Assert(svc.Start(), IsNil) | ||
360 | 89 | svc.Stop() | ||
361 | 90 | callArgs := testibus.GetCallArgs(ss.bus) | ||
362 | 91 | c.Assert(callArgs, HasLen, 2) | ||
363 | 92 | c.Check(callArgs[1].Member, Equals, "::Close") | ||
364 | 93 | } | ||
365 | 0 | 94 | ||
366 | === modified file 'ubuntu-push-client.go' | |||
367 | --- ubuntu-push-client.go 2014-04-30 16:44:16 +0000 | |||
368 | +++ ubuntu-push-client.go 2014-05-14 12:29:13 +0000 | |||
369 | @@ -19,37 +19,12 @@ | |||
370 | 19 | import ( | 19 | import ( |
371 | 20 | "log" | 20 | "log" |
372 | 21 | 21 | ||
373 | 22 | "launchpad.net/go-dbus/v1" | ||
374 | 23 | "launchpad.net/go-xdg/v0" | 22 | "launchpad.net/go-xdg/v0" |
375 | 24 | 23 | ||
376 | 25 | "launchpad.net/ubuntu-push/client" | 24 | "launchpad.net/ubuntu-push/client" |
377 | 26 | ) | 25 | ) |
378 | 27 | 26 | ||
379 | 28 | const NAME = "com.ubuntu.PushNotifications" | ||
380 | 29 | |||
381 | 30 | // grabName grabs ownership of the dbus name, and bails the client as | ||
382 | 31 | // soon as somebody else grabs it. | ||
383 | 32 | func grabName() { | ||
384 | 33 | conn, err := dbus.Connect(dbus.SessionBus) | ||
385 | 34 | if err != nil { | ||
386 | 35 | log.Fatalf("bus: %v", err) | ||
387 | 36 | } | ||
388 | 37 | |||
389 | 38 | flags := dbus.NameFlagAllowReplacement | dbus.NameFlagReplaceExisting | ||
390 | 39 | n := conn.RequestName(NAME, flags) | ||
391 | 40 | go func() { | ||
392 | 41 | for err := range n.C { | ||
393 | 42 | if err != nil { | ||
394 | 43 | log.Fatalf("FATAL: name channel got: %v", err) | ||
395 | 44 | } | ||
396 | 45 | } | ||
397 | 46 | }() | ||
398 | 47 | } | ||
399 | 48 | |||
400 | 49 | func main() { | 27 | func main() { |
401 | 50 | // XXX: this is a quick hack to ensure unicity | ||
402 | 51 | grabName() | ||
403 | 52 | |||
404 | 53 | cfgFname, err := xdg.Config.Find("ubuntu-push-client/config.json") | 28 | cfgFname, err := xdg.Config.Find("ubuntu-push-client/config.json") |
405 | 54 | if err != nil { | 29 | if err != nil { |
406 | 55 | log.Fatalf("unable to find a configuration file: %v", err) | 30 | log.Fatalf("unable to find a configuration file: %v", err) |
the README should mention the need to install cmake now.