Merge lp:~chipaca/ubuntu-push/sqlevelmap-in-session into lp:ubuntu-push

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: 66
Merged at revision: 68
Proposed branch: lp:~chipaca/ubuntu-push/sqlevelmap-in-session
Merge into: lp:ubuntu-push
Prerequisite: lp:~chipaca/ubuntu-push/introducing-sqlevelmap
Diff against target: 371 lines (+61/-38)
4 files modified
client/client.go (+3/-1)
client/client_test.go (+3/-2)
client/session/session.go (+3/-2)
client/session/session_test.go (+52/-33)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/sqlevelmap-in-session
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+205483@code.launchpad.net

Commit message

bring sqlevelmap into session

Description of the change

This updates client/session to work with the sqlite levelmap.

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

98 +type clientSessionSuite struct {
99 + log logger.Logger
100 + lvls func() (levelmap.LevelMap, error)
101 +}
102 +
103 +type clientSqlevelsSessionSuite struct{ clientSessionSuite }
104 +
105 +var _ = Suite(&clientSessionSuite{})
106 +var _ = Suite(&clientSqlevelsSessionSuite{})
107 +
108 +func (cs *clientSessionSuite) SetUpSuite(c *C) {
109 + cs.lvls = levelmap.NewLevelMap
110 +}
111 +
112 +func (cs *clientSqlevelsSessionSuite) SetUpSuite(c *C) {
113 + cs.lvls = func() (levelmap.LevelMap, error) { return levelmap.NewSqliteLevelMap(":memory:") }
114 +}
115 +
116 func (cs *clientSessionSuite) SetUpTest(c *C) {
117 cs.log = helpers.NewTestLogger(c, "debug")
118 }

I find the order in which things occur here a bit strange (though go doesn't care), my impulse would be to put them at the end, but maybe this is better, I'm also unsure about putting the hooks into &clientSessionSuite{...} vs setting them in SetUpSuite

Revision history for this message
Samuele Pedroni (pedronis) :
review: Approve
64. By John Lenton

Merged introducing-sqlevelmap into sqlevelmap-in-session.

65. By John Lenton

improved legibility of test setup, via pedronis

66. By John Lenton

merged trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'client/client.go'
2--- client/client.go 2014-02-08 11:30:13 +0000
3+++ client/client.go 2014-02-12 16:56:28 +0000
4@@ -29,6 +29,7 @@
5 "launchpad.net/ubuntu-push/bus/notifications"
6 "launchpad.net/ubuntu-push/bus/urldispatcher"
7 "launchpad.net/ubuntu-push/client/session"
8+ "launchpad.net/ubuntu-push/client/session/levelmap"
9 "launchpad.net/ubuntu-push/config"
10 "launchpad.net/ubuntu-push/logger"
11 "launchpad.net/ubuntu-push/util"
12@@ -141,7 +142,8 @@
13 // initSession creates the session object
14 func (client *pushClient) initSession() error {
15 sess, err := session.NewSession(string(client.config.Addr), client.pem,
16- client.config.ExchangeTimeout.Duration, client.deviceId, client.log)
17+ client.config.ExchangeTimeout.Duration, client.deviceId,
18+ levelmap.NewLevelMap, client.log)
19 if err != nil {
20 return err
21 }
22
23=== modified file 'client/client_test.go'
24--- client/client_test.go 2014-02-08 18:19:05 +0000
25+++ client/client_test.go 2014-02-12 16:56:28 +0000
26@@ -26,6 +26,7 @@
27 "launchpad.net/ubuntu-push/bus/notifications"
28 testibus "launchpad.net/ubuntu-push/bus/testing"
29 "launchpad.net/ubuntu-push/client/session"
30+ "launchpad.net/ubuntu-push/client/session/levelmap"
31 helpers "launchpad.net/ubuntu-push/testing"
32 "launchpad.net/ubuntu-push/testing/condition"
33 "launchpad.net/ubuntu-push/util"
34@@ -333,7 +334,7 @@
35 func (cs *clientSuite) TestHandleConnStateC2D(c *C) {
36 cli := NewPushClient(cs.configPath)
37 cli.log = cs.log
38- cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, cs.log)
39+ cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, levelmap.NewLevelMap, cs.log)
40 cli.session.Dial()
41 cli.hasConnectivity = true
42
43@@ -346,7 +347,7 @@
44 func (cs *clientSuite) TestHandleConnStateC2DPending(c *C) {
45 cli := NewPushClient(cs.configPath)
46 cli.log = cs.log
47- cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, cs.log)
48+ cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, levelmap.NewLevelMap, cs.log)
49 cli.hasConnectivity = true
50
51 cli.handleConnState(false)
52
53=== modified file 'client/session/session.go'
54--- client/session/session.go 2014-02-12 13:24:23 +0000
55+++ client/session/session.go 2014-02-12 16:56:28 +0000
56@@ -78,9 +78,10 @@
57 }
58
59 func NewSession(serverAddr string, pem []byte, exchangeTimeout time.Duration,
60- deviceId string, log logger.Logger) (*ClientSession, error) {
61+ deviceId string, levelmapFactory func() (levelmap.LevelMap, error),
62+ log logger.Logger) (*ClientSession, error) {
63 state := uint32(Disconnected)
64- levels, err := levelmap.NewLevelMap()
65+ levels, err := levelmapFactory()
66 if err != nil {
67 return nil, err
68 }
69
70=== modified file 'client/session/session_test.go'
71--- client/session/session_test.go 2014-02-12 13:24:23 +0000
72+++ client/session/session_test.go 2014-02-12 16:56:28 +0000
73@@ -24,6 +24,7 @@
74 "io"
75 "io/ioutil"
76 . "launchpad.net/gocheck"
77+ "launchpad.net/ubuntu-push/client/session/levelmap"
78 "launchpad.net/ubuntu-push/logger"
79 "launchpad.net/ubuntu-push/protocol"
80 helpers "launchpad.net/ubuntu-push/testing"
81@@ -36,12 +37,6 @@
82
83 func TestSession(t *testing.T) { TestingT(t) }
84
85-type clientSessionSuite struct {
86- log logger.Logger
87-}
88-
89-var _ = Suite(&clientSessionSuite{})
90-
91 //
92 // helpers! candidates to live in their own ../testing/ package.
93 //
94@@ -164,16 +159,33 @@
95
96 /////
97
98+type clientSessionSuite struct {
99+ log logger.Logger
100+ lvls func() (levelmap.LevelMap, error)
101+}
102+
103 func (cs *clientSessionSuite) SetUpTest(c *C) {
104 cs.log = helpers.NewTestLogger(c, "debug")
105 }
106
107+// in-memory level map testing
108+var _ = Suite(&clientSessionSuite{lvls: levelmap.NewLevelMap})
109+
110+// sqlite level map testing
111+type clientSqlevelsSessionSuite struct{ clientSessionSuite }
112+
113+var _ = Suite(&clientSqlevelsSessionSuite{})
114+
115+func (cs *clientSqlevelsSessionSuite) SetUpSuite(c *C) {
116+ cs.lvls = func() (levelmap.LevelMap, error) { return levelmap.NewSqliteLevelMap(":memory:") }
117+}
118+
119 /****************************************************************
120 NewSession() tests
121 ****************************************************************/
122
123 func (cs *clientSessionSuite) TestNewSessionPlainWorks(c *C) {
124- sess, err := NewSession("", nil, 0, "", cs.log)
125+ sess, err := NewSession("", nil, 0, "", cs.lvls, cs.log)
126 c.Check(sess, NotNil)
127 c.Check(err, IsNil)
128 // but no root CAs set
129@@ -185,7 +197,7 @@
130 var pem, _ = ioutil.ReadFile(certfile)
131
132 func (cs *clientSessionSuite) TestNewSessionPEMWorks(c *C) {
133- sess, err := NewSession("", pem, 0, "wah", cs.log)
134+ sess, err := NewSession("", pem, 0, "wah", cs.lvls, cs.log)
135 c.Check(sess, NotNil)
136 c.Assert(err, IsNil)
137 c.Check(sess.TLS.RootCAs, NotNil)
138@@ -193,17 +205,24 @@
139
140 func (cs *clientSessionSuite) TestNewSessionBadPEMFileContentFails(c *C) {
141 badpem := []byte("This is not the PEM you're looking for.")
142- sess, err := NewSession("", badpem, 0, "wah", cs.log)
143+ sess, err := NewSession("", badpem, 0, "wah", cs.lvls, cs.log)
144 c.Check(sess, IsNil)
145 c.Check(err, NotNil)
146 }
147
148+func (cs *clientSessionSuite) TestNewSessionBadLevelMapFails(c *C) {
149+ ferr := func() (levelmap.LevelMap, error) { return nil, errors.New("Busted.") }
150+ sess, err := NewSession("", nil, 0, "wah", ferr, cs.log)
151+ c.Check(sess, IsNil)
152+ c.Assert(err, NotNil)
153+}
154+
155 /****************************************************************
156 connect() tests
157 ****************************************************************/
158
159 func (cs *clientSessionSuite) TestConnectFailsWithNoAddress(c *C) {
160- sess, err := NewSession("", nil, 0, "wah", cs.log)
161+ sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log)
162 c.Assert(err, IsNil)
163 err = sess.connect()
164 c.Check(err, ErrorMatches, ".*connect.*address.*")
165@@ -214,7 +233,7 @@
166 srv, err := net.Listen("tcp", "localhost:0")
167 c.Assert(err, IsNil)
168 defer srv.Close()
169- sess, err := NewSession(srv.Addr().String(), nil, 0, "wah", cs.log)
170+ sess, err := NewSession(srv.Addr().String(), nil, 0, "wah", cs.lvls, cs.log)
171 c.Assert(err, IsNil)
172 err = sess.connect()
173 c.Check(err, IsNil)
174@@ -225,7 +244,7 @@
175 func (cs *clientSessionSuite) TestConnectConnectFail(c *C) {
176 srv, err := net.Listen("tcp", "localhost:0")
177 c.Assert(err, IsNil)
178- sess, err := NewSession(srv.Addr().String(), nil, 0, "wah", cs.log)
179+ sess, err := NewSession(srv.Addr().String(), nil, 0, "wah", cs.lvls, cs.log)
180 srv.Close()
181 c.Assert(err, IsNil)
182 err = sess.connect()
183@@ -238,7 +257,7 @@
184 ****************************************************************/
185
186 func (cs *clientSessionSuite) TestClose(c *C) {
187- sess, err := NewSession("", nil, 0, "wah", cs.log)
188+ sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log)
189 c.Assert(err, IsNil)
190 sess.Connection = &testConn{Name: "TestClose"}
191 sess.Close()
192@@ -247,7 +266,7 @@
193 }
194
195 func (cs *clientSessionSuite) TestCloseTwice(c *C) {
196- sess, err := NewSession("", nil, 0, "wah", cs.log)
197+ sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log)
198 c.Assert(err, IsNil)
199 sess.Connection = &testConn{Name: "TestCloseTwice"}
200 sess.Close()
201@@ -258,7 +277,7 @@
202 }
203
204 func (cs *clientSessionSuite) TestCloseFails(c *C) {
205- sess, err := NewSession("", nil, 0, "wah", cs.log)
206+ sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log)
207 c.Assert(err, IsNil)
208 sess.Connection = &testConn{Name: "TestCloseFails", CloseCondition: condition.Work(false)}
209 sess.Close()
210@@ -272,7 +291,7 @@
211 func (d *derp) Stop() { d.stopped = true }
212
213 func (cs *clientSessionSuite) TestCloseStopsRetrier(c *C) {
214- sess, err := NewSession("", nil, 0, "wah", cs.log)
215+ sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log)
216 c.Assert(err, IsNil)
217 ar := new(derp)
218 sess.retrier = ar
219@@ -289,7 +308,7 @@
220
221 func (cs *clientSessionSuite) TestAutoRedialWorks(c *C) {
222 // checks that AutoRedial sets up a retrier and tries redialing it
223- sess, err := NewSession("", nil, 0, "wah", cs.log)
224+ sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log)
225 c.Assert(err, IsNil)
226 ar := new(derp)
227 sess.retrier = ar
228@@ -300,7 +319,7 @@
229
230 func (cs *clientSessionSuite) TestAutoRedialStopsRetrier(c *C) {
231 // checks that AutoRedial stops the previous retrier
232- sess, err := NewSession("", nil, 0, "wah", cs.log)
233+ sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log)
234 c.Assert(err, IsNil)
235 ch := make(chan uint32)
236 c.Check(sess.retrier, IsNil)
237@@ -325,7 +344,7 @@
238
239 func (s *msgSuite) SetUpTest(c *C) {
240 var err error
241- s.sess, err = NewSession("", nil, time.Millisecond, "wah", helpers.NewTestLogger(c, "debug"))
242+ s.sess, err = NewSession("", nil, time.Millisecond, "wah", levelmap.NewLevelMap, helpers.NewTestLogger(c, "debug"))
243 c.Assert(err, IsNil)
244 s.sess.Connection = &testConn{Name: "TestHandle*"}
245 s.errCh = make(chan error, 1)
246@@ -500,7 +519,7 @@
247 start() tests
248 ****************************************************************/
249 func (cs *clientSessionSuite) TestStartFailsIfSetDeadlineFails(c *C) {
250- sess, err := NewSession("", nil, 0, "wah", cs.log)
251+ sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log)
252 c.Assert(err, IsNil)
253 sess.Connection = &testConn{Name: "TestStartFailsIfSetDeadlineFails",
254 DeadlineCondition: condition.Work(false)} // setdeadline will fail
255@@ -510,7 +529,7 @@
256 }
257
258 func (cs *clientSessionSuite) TestStartFailsIfWriteFails(c *C) {
259- sess, err := NewSession("", nil, 0, "wah", cs.log)
260+ sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log)
261 c.Assert(err, IsNil)
262 sess.Connection = &testConn{Name: "TestStartFailsIfWriteFails",
263 WriteCondition: condition.Work(false)} // write will fail
264@@ -520,7 +539,7 @@
265 }
266
267 func (cs *clientSessionSuite) TestStartFailsIfGetLevelsFails(c *C) {
268- sess, err := NewSession("", nil, 0, "wah", cs.log)
269+ sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log)
270 c.Assert(err, IsNil)
271 sess.Levels = &brokenLevelMap{}
272 sess.Connection = &testConn{Name: "TestStartConnectMessageFails"}
273@@ -540,7 +559,7 @@
274 }
275
276 func (cs *clientSessionSuite) TestStartConnectMessageFails(c *C) {
277- sess, err := NewSession("", nil, 0, "wah", cs.log)
278+ sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log)
279 c.Assert(err, IsNil)
280 sess.Connection = &testConn{Name: "TestStartConnectMessageFails"}
281 errCh := make(chan error, 1)
282@@ -566,7 +585,7 @@
283 }
284
285 func (cs *clientSessionSuite) TestStartConnackReadError(c *C) {
286- sess, err := NewSession("", nil, 0, "wah", cs.log)
287+ sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log)
288 c.Assert(err, IsNil)
289 sess.Connection = &testConn{Name: "TestStartConnackReadError"}
290 errCh := make(chan error, 1)
291@@ -590,7 +609,7 @@
292 }
293
294 func (cs *clientSessionSuite) TestStartBadConnack(c *C) {
295- sess, err := NewSession("", nil, 0, "wah", cs.log)
296+ sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log)
297 c.Assert(err, IsNil)
298 sess.Connection = &testConn{Name: "TestStartBadConnack"}
299 errCh := make(chan error, 1)
300@@ -614,7 +633,7 @@
301 }
302
303 func (cs *clientSessionSuite) TestStartNotConnack(c *C) {
304- sess, err := NewSession("", nil, 0, "wah", cs.log)
305+ sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log)
306 c.Assert(err, IsNil)
307 sess.Connection = &testConn{Name: "TestStartBadConnack"}
308 errCh := make(chan error, 1)
309@@ -638,7 +657,7 @@
310 }
311
312 func (cs *clientSessionSuite) TestStartWorks(c *C) {
313- sess, err := NewSession("", nil, 0, "wah", cs.log)
314+ sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log)
315 c.Assert(err, IsNil)
316 sess.Connection = &testConn{Name: "TestStartWorks"}
317 errCh := make(chan error, 1)
318@@ -670,7 +689,7 @@
319 ****************************************************************/
320
321 func (cs *clientSessionSuite) TestRunBailsIfConnectFails(c *C) {
322- sess, err := NewSession("", nil, 0, "wah", cs.log)
323+ sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log)
324 c.Assert(err, IsNil)
325 failure := errors.New("TestRunBailsIfConnectFails")
326 has_closed := false
327@@ -684,7 +703,7 @@
328 }
329
330 func (cs *clientSessionSuite) TestRunBailsIfStartFails(c *C) {
331- sess, err := NewSession("", nil, 0, "wah", cs.log)
332+ sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log)
333 c.Assert(err, IsNil)
334 failure := errors.New("TestRunBailsIfStartFails")
335 err = sess.run(
336@@ -696,7 +715,7 @@
337 }
338
339 func (cs *clientSessionSuite) TestRunRunsEvenIfLoopFails(c *C) {
340- sess, err := NewSession("", nil, 0, "wah", cs.log)
341+ sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log)
342 c.Assert(err, IsNil)
343 // just to make a point: until here we haven't set ErrCh & MsgCh (no
344 // biggie if this stops being true)
345@@ -725,7 +744,7 @@
346 ****************************************************************/
347
348 func (cs *clientSessionSuite) TestJitter(c *C) {
349- sess, err := NewSession("", nil, 0, "wah", cs.log)
350+ sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log)
351 c.Assert(err, IsNil)
352 num_tries := 20 // should do the math
353 spread := time.Second //
354@@ -757,7 +776,7 @@
355
356 func (cs *clientSessionSuite) TestDialPanics(c *C) {
357 // one last unhappy test
358- sess, err := NewSession("", nil, 0, "wah", cs.log)
359+ sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log)
360 c.Assert(err, IsNil)
361 sess.Protocolator = nil
362 c.Check(sess.Dial, PanicMatches, ".*protocol constructor.")
363@@ -775,7 +794,7 @@
364 timeout := 100 * time.Millisecond
365 lst, err := tls.Listen("tcp", "localhost:0", tlsCfg)
366 c.Assert(err, IsNil)
367- sess, err := NewSession(lst.Addr().String(), nil, timeout, "wah", cs.log)
368+ sess, err := NewSession(lst.Addr().String(), nil, timeout, "wah", cs.lvls, cs.log)
369 c.Assert(err, IsNil)
370 tconn := &testConn{CloseCondition: condition.Fail2Work(10)}
371 sess.Connection = tconn

Subscribers

People subscribed via source and target branches