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