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

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: 382
Merged at revision: 380
Proposed branch: lp:~chipaca/ubuntu-push/cmdch
Merge into: lp:ubuntu-push/automatic
Diff against target: 118 lines (+34/-7)
2 files modified
client/session/session.go (+29/-6)
client/session/session_test.go (+5/-1)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/cmdch
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+253497@code.launchpad.net

Commit message

First pass at a cmdCh in session.

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

looks good

review: Approve
lp:~chipaca/ubuntu-push/cmdch updated
382. By John Lenton

get rid of a corner case in an unrelated test

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'client/session/session.go'
2--- client/session/session.go 2015-03-18 17:41:59 +0000
3+++ client/session/session.go 2015-03-19 11:36:08 +0000
4@@ -39,6 +39,14 @@
5 "launchpad.net/ubuntu-push/util"
6 )
7
8+type sessCmd uint8
9+
10+const (
11+ cmdDisconnect sessCmd = iota
12+ cmdConnect
13+ cmdResetCookie
14+)
15+
16 var (
17 wireVersionBytes = []byte{protocol.ProtocolWireVersion}
18 )
19@@ -173,8 +181,8 @@
20 redialJitter func(time.Duration) time.Duration
21 redialDelays []time.Duration
22 redialDelaysIdx int
23- // connection events come in over here
24- connCh chan bool
25+ // connection events, and cookie reset requests, come in over here
26+ cmdCh chan sessCmd
27 // last seen connection event is here
28 lastConn bool
29 // connection events are handled by this
30@@ -242,7 +250,7 @@
31 }
32 sess.doneCh = make(chan uint32, 1)
33 sess.stopCh = make(chan struct{})
34- sess.connCh = make(chan bool, 1)
35+ sess.cmdCh = make(chan sessCmd)
36 sess.errCh = make(chan error, 1)
37
38 // to be overridden by tests
39@@ -302,6 +310,10 @@
40 }
41
42 func (sess *clientSession) ResetCookie() {
43+ sess.cmdCh <- cmdResetCookie
44+}
45+
46+func (sess *clientSession) resetCookie() {
47 sess.stopRedial()
48 sess.doClose(true)
49 }
50@@ -712,8 +724,15 @@
51 Loop:
52 for {
53 select {
54- case hasConn := <-sess.connCh:
55- sess.connHandler(hasConn)
56+ case cmd := <-sess.cmdCh:
57+ switch cmd {
58+ case cmdConnect:
59+ sess.connHandler(true)
60+ case cmdDisconnect:
61+ sess.connHandler(false)
62+ case cmdResetCookie:
63+ sess.resetCookie()
64+ }
65 case <-sess.stopCh:
66 sess.Log.Infof("session shutting down.")
67 sess.connLock.Lock()
68@@ -775,7 +794,11 @@
69 }
70
71 func (sess *clientSession) HasConnectivity(hasConn bool) {
72- sess.connCh <- hasConn
73+ if hasConn {
74+ sess.cmdCh <- cmdConnect
75+ } else {
76+ sess.cmdCh <- cmdDisconnect
77+ }
78 }
79
80 func init() {
81
82=== modified file 'client/session/session_test.go'
83--- client/session/session_test.go 2015-03-17 10:51:55 +0000
84+++ client/session/session_test.go 2015-03-19 11:36:08 +0000
85@@ -250,7 +250,7 @@
86 c.Check(sess.TLS.RootCAs, IsNil)
87 c.Check(sess.State(), Equals, Pristine)
88 c.Check(sess.stopCh, NotNil)
89- c.Check(sess.connCh, NotNil)
90+ c.Check(sess.cmdCh, NotNil)
91 }
92
93 func (cs *clientSessionSuite) TestNewSessionHostEndpointWorks(c *C) {
94@@ -1689,6 +1689,8 @@
95 func (cs *clientSessionSuite) TestResetCookie(c *C) {
96 sess, err := NewSession("foo:443", dummyConf(), "", cs.lvls, cs.log)
97 c.Assert(err, IsNil)
98+ c.Assert(sess.KeepConnection(), IsNil)
99+ defer sess.StopKeepConnection()
100 c.Check(sess.getCookie(), Equals, "")
101 sess.setCookie("COOKIE")
102 c.Check(sess.getCookie(), Equals, "COOKIE")
103@@ -1707,6 +1709,7 @@
104 c.Assert(sess, NotNil)
105 c.Assert(sess.State(), Equals, Pristine)
106 c.Assert(sess.KeepConnection(), IsNil)
107+ defer sess.StopKeepConnection()
108 // stopCh is meant to be used just for closing it, but abusing
109 // it for testing seems the right thing to do: this ensures
110 // the thing is ticking along before we check the state of
111@@ -1756,6 +1759,7 @@
112 defer sess.StopKeepConnection()
113
114 sess.doneCh <- 23
115+ sess.doneCh <- 24 // makes sure the first one has been processed before checking
116
117 c.Check(cs.log.Captured(),
118 Matches, `(?ms).* connected after 23 attempts\.`)

Subscribers

People subscribed via source and target branches