Merge lp:~chipaca/ubuntu-push/small-reorg into lp:ubuntu-push

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: 41
Merged at revision: 41
Proposed branch: lp:~chipaca/ubuntu-push/small-reorg
Merge into: lp:ubuntu-push
Diff against target: 198 lines (+27/-67)
2 files modified
client/session/session.go (+7/-18)
client/session/session_test.go (+20/-49)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/small-reorg
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+204355@code.launchpad.net

Commit message

Killed checkRunnable; renamed: Dial -> connect, run -> loop.

Description of the change

Killed checkRunnable; renamed: Dial -> connect, run -> loop.

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

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 2014-01-31 19:42:28 +0000
3+++ client/session/session.go 2014-01-31 21:54:22 +0000
4@@ -83,12 +83,12 @@
5 return sess, nil
6 }
7
8-// Dial connects to a server using the configuration in the ClientSession
9-// and sets up the connection.
10-func (sess *ClientSession) Dial() error {
11+// connect to a server using the configuration in the ClientSession
12+// and set up the connection.
13+func (sess *ClientSession) connect() error {
14 conn, err := net.DialTimeout("tcp", sess.ServerAddr, sess.ExchangeTimeout)
15 if err != nil {
16- return err
17+ return fmt.Errorf("connect: %s", err)
18 }
19 sess.Connection = tls.Client(conn, sess.TLS)
20 return nil
21@@ -104,17 +104,6 @@
22 }
23 }
24
25-// call this to ensure the session is sane to run
26-func (sess *ClientSession) checkRunnable() error {
27- if sess.Connection == nil {
28- return errors.New("can't run disconnected.")
29- }
30- if sess.Protocolator == nil {
31- return errors.New("can't run without a protocol constructor.")
32- }
33- return nil
34-}
35-
36 // handle "ping" messages
37 func (sess *ClientSession) handlePing() error {
38 err := sess.proto.WriteMessage(protocol.PingPongMsg{Type: "pong"})
39@@ -144,8 +133,8 @@
40 return nil
41 }
42
43-// Run the session with the server, emits a stream of events.
44-func (sess *ClientSession) run() error {
45+// loop runs the session with the server, emits a stream of events.
46+func (sess *ClientSession) loop() error {
47 var err error
48 var recv serverMsg
49 for {
50@@ -167,7 +156,7 @@
51 }
52 }
53
54-// Call this when you've connected and are ready to start running.
55+// Call this when you've connected and want to start looping.
56 func (sess *ClientSession) start() error {
57 conn := sess.Connection
58 err := conn.SetDeadline(time.Now().Add(sess.ExchangeTimeout))
59
60=== modified file 'client/session/session_test.go'
61--- client/session/session_test.go 2014-01-31 19:56:16 +0000
62+++ client/session/session_test.go 2014-01-31 21:54:22 +0000
63@@ -186,34 +186,34 @@
64 }
65
66 /****************************************************************
67- Dial() tests
68+ connect() tests
69 ****************************************************************/
70
71-func (cs *clientSessionSuite) TestDialFailsWithNoAddress(c *C) {
72+func (cs *clientSessionSuite) TestConnectFailsWithNoAddress(c *C) {
73 sess, err := NewSession("", nil, 0, "wah", debuglog)
74 c.Assert(err, IsNil)
75- err = sess.Dial()
76- c.Check(err, ErrorMatches, ".*dial.*address.*")
77+ err = sess.connect()
78+ c.Check(err, ErrorMatches, ".*connect.*address.*")
79 }
80
81-func (cs *clientSessionSuite) TestDialConnects(c *C) {
82+func (cs *clientSessionSuite) TestConnectConnects(c *C) {
83 srv, err := net.Listen("tcp", "localhost:0")
84 c.Assert(err, IsNil)
85 defer srv.Close()
86 sess, err := NewSession(srv.Addr().String(), nil, 0, "wah", debuglog)
87 c.Assert(err, IsNil)
88- err = sess.Dial()
89+ err = sess.connect()
90 c.Check(err, IsNil)
91 c.Check(sess.Connection, NotNil)
92 }
93
94-func (cs *clientSessionSuite) TestDialConnectFail(c *C) {
95+func (cs *clientSessionSuite) TestConnectConnectFail(c *C) {
96 srv, err := net.Listen("tcp", "localhost:0")
97 c.Assert(err, IsNil)
98 sess, err := NewSession(srv.Addr().String(), nil, 0, "wah", debuglog)
99 srv.Close()
100 c.Assert(err, IsNil)
101- err = sess.Dial()
102+ err = sess.connect()
103 c.Check(err, ErrorMatches, ".*connection refused")
104 }
105
106@@ -248,35 +248,6 @@
107 }
108
109 /****************************************************************
110- checkRunnable() tests
111-****************************************************************/
112-
113-func (cs *clientSessionSuite) TestCheckRunnableFailsIfNoConnection(c *C) {
114- sess, err := NewSession("", nil, 0, "wah", debuglog)
115- c.Assert(err, IsNil)
116- // no connection!
117- c.Check(sess.checkRunnable(), NotNil)
118-}
119-
120-func (cs *clientSessionSuite) TestCheckRunnableFailsIfNoProtocolator(c *C) {
121- sess, err := NewSession("", nil, 0, "wah", debuglog)
122- c.Assert(err, IsNil)
123- // set up the connection
124- sess.Connection = &testConn{}
125- // And stomp on the protocolator
126- sess.Protocolator = nil
127- c.Check(sess.checkRunnable(), NotNil)
128-}
129-
130-func (cs *clientSessionSuite) TestCheckRunnable(c *C) {
131- sess, err := NewSession("", nil, 0, "wah", debuglog)
132- c.Assert(err, IsNil)
133- // set up the connection
134- sess.Connection = &testConn{}
135- c.Check(sess.checkRunnable(), IsNil)
136-}
137-
138-/****************************************************************
139 handlePing() tests
140 ****************************************************************/
141
142@@ -374,28 +345,28 @@
143 }
144
145 /****************************************************************
146- run() tests
147+ loop() tests
148 ****************************************************************/
149
150-type runSuite msgSuite
151-
152-var _ = Suite(&runSuite{})
153-
154-func (s *runSuite) SetUpTest(c *C) {
155+type loopSuite msgSuite
156+
157+var _ = Suite(&loopSuite{})
158+
159+func (s *loopSuite) SetUpTest(c *C) {
160 (*msgSuite)(s).SetUpTest(c)
161- s.sess.Connection.(*testConn).Name = "TestRun* (small r)"
162+ s.sess.Connection.(*testConn).Name = "TestLoop*"
163 go func() {
164- s.errCh <- s.sess.run()
165+ s.errCh <- s.sess.loop()
166 }()
167 }
168
169-func (s *runSuite) TestRunReadError(c *C) {
170+func (s *loopSuite) TestLoopReadError(c *C) {
171 s.upCh <- errors.New("Read")
172 err := <-s.errCh
173 c.Check(err, ErrorMatches, "Read")
174 }
175
176-func (s *runSuite) TestRunPing(c *C) {
177+func (s *loopSuite) TestLoopPing(c *C) {
178 c.Check(takeNext(s.downCh), Equals, "deadline 1ms")
179 s.upCh <- protocol.PingPongMsg{Type: "ping"}
180 c.Check(takeNext(s.downCh), Equals, protocol.PingPongMsg{Type: "pong"})
181@@ -404,7 +375,7 @@
182 c.Check(<-s.errCh, Equals, failure)
183 }
184
185-func (s *runSuite) TestRunLoopsDaLoop(c *C) {
186+func (s *loopSuite) TestLoopLoopsDaLoop(c *C) {
187 for i := 1; i < 10; i++ {
188 c.Check(takeNext(s.downCh), Equals, "deadline 1ms")
189 s.upCh <- protocol.PingPongMsg{Type: "ping"}
190@@ -416,7 +387,7 @@
191 c.Check(<-s.errCh, Equals, failure)
192 }
193
194-func (s *runSuite) TestRunBroadcast(c *C) {
195+func (s *loopSuite) TestLoopBroadcast(c *C) {
196 b := &protocol.BroadcastMsg{
197 Type: "broadcast",
198 AppId: "--ignored--",

Subscribers

People subscribed via source and target branches