Merge lp:~chipaca/ubuntu-push/home-cooking-client-session-style into lp:ubuntu-push

Proposed by John Lenton
Status: Superseded
Proposed branch: lp:~chipaca/ubuntu-push/home-cooking-client-session-style
Merge into: lp:ubuntu-push
Prerequisite: lp:~chipaca/ubuntu-push/elements-of-client-session-toponomy
Diff against target: 117 lines (+102/-0)
2 files modified
client/session/session.go (+31/-0)
client/session/session_test.go (+71/-0)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/home-cooking-client-session-style
Reviewer Review Type Date Requested Status
Ubuntu Push Hackers Pending
Review via email: mp+204131@code.launchpad.net

This proposal has been superseded by a proposal from 2014-02-01.

Commit message

That's all, folks.

Description of the change

Client session, volume 6: Home cooking, client-session-style.

To post a comment you must log in.
42. By John Lenton

Merged elements-of-client-session-toponomy into home-cooking-client-session-style.

43. By John Lenton

renamed the fake server in TestResets to "srv" (from "lp")

44. By John Lenton

Merged elements-of-client-session-toponomy into home-cooking-client-session-style.

45. By John Lenton

Fixed a test binding all ifaces

46. By John Lenton

Merged elements-of-client-session-toponomy into home-cooking-client-session-style.

47. By John Lenton

Merged elements-of-client-session-toponomy into home-cooking-client-session-style.

48. By John Lenton

Merged elements-of-client-session-toponomy into home-cooking-client-session-style.

49. By John Lenton

Merged elements-of-client-session-toponomy into home-cooking-client-session-style.

50. By John Lenton

Merged elements-of-client-session-toponomy into home-cooking-client-session-style.

51. By John Lenton

Merged elements-of-client-session-toponomy into home-cooking-client-session-style.

52. By John Lenton

Merged elements-of-client-session-toponomy into home-cooking-client-session-style.

53. By John Lenton

Merged elements-of-client-session-toponomy into home-cooking-client-session-style.

Revision history for this message
Samuele Pedroni (pedronis) wrote :

31 + sess.Log.Errorf("%s", err)

seems that error needs a prefix of sort

Revision history for this message
Samuele Pedroni (pedronis) wrote :

98 +func (cs *clientSessionSuite) TestResets(c *C) {

it's hard to tell what this is testing concretely? it's not cliear it's checking the various bits of channel resetting for example

maybe run/Run should set a flag on the session or something to use here?

Revision history for this message
Samuele Pedroni (pedronis) wrote :

Run and Reset need descriptions

Revision history for this message
Samuele Pedroni (pedronis) wrote :

vaguer comments:

bit unsure about the assymmetry that the happy start path has you call Dial and Run,

and Reset does both for you,

also not sure about Run doing "go ..." for you

Unmerged revisions

53. By John Lenton

Merged elements-of-client-session-toponomy into home-cooking-client-session-style.

52. By John Lenton

Merged elements-of-client-session-toponomy into home-cooking-client-session-style.

51. By John Lenton

Merged elements-of-client-session-toponomy into home-cooking-client-session-style.

50. By John Lenton

Merged elements-of-client-session-toponomy into home-cooking-client-session-style.

49. By John Lenton

Merged elements-of-client-session-toponomy into home-cooking-client-session-style.

48. By John Lenton

Merged elements-of-client-session-toponomy into home-cooking-client-session-style.

47. By John Lenton

Merged elements-of-client-session-toponomy into home-cooking-client-session-style.

46. By John Lenton

Merged elements-of-client-session-toponomy into home-cooking-client-session-style.

45. By John Lenton

Fixed a test binding all ifaces

44. By John Lenton

Merged elements-of-client-session-toponomy into home-cooking-client-session-style.

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 17:52:59 +0000
3+++ client/session/session.go 2014-01-31 17:52:59 +0000
4@@ -203,3 +203,34 @@
5 sess.Log.Debugf("Connected %v.", conn.LocalAddr())
6 return nil
7 }
8+
9+func (sess *ClientSession) Run() {
10+ go func() {
11+ err := sess.checkRunnable()
12+ if err == nil {
13+ err = sess.start()
14+ if err == nil {
15+ err = sess.run()
16+ }
17+ }
18+ sess.ErrCh <- err
19+ }()
20+}
21+
22+func (sess *ClientSession) Reset() error {
23+ if sess.Protocolator == nil {
24+ return errors.New("Can't Reset() without a protocol constructor.")
25+ }
26+ if sess.Connection != nil {
27+ sess.Close() // just in case
28+ }
29+ err := sess.Dial()
30+ if err != nil {
31+ sess.Log.Errorf("%s", err)
32+ return err
33+ }
34+ sess.ErrCh = make(chan error, 1)
35+ sess.MsgCh = make(chan *Notification)
36+ sess.Run()
37+ return nil
38+}
39
40=== modified file 'client/session/session_test.go'
41--- client/session/session_test.go 2014-01-31 17:52:59 +0000
42+++ client/session/session_test.go 2014-01-31 17:52:59 +0000
43@@ -559,3 +559,74 @@
44 err = <-errCh
45 c.Assert(err, IsNil)
46 }
47+
48+/****************************************************************
49+ Run() tests
50+****************************************************************/
51+
52+func (cs *clientSessionSuite) TestRunRuns(c *C) {
53+ sess, err := NewSession("", nil, 0, "wah", debuglog)
54+ c.Assert(err, IsNil)
55+ sess.Connection = &testConn{Name: "TestRunRuns"}
56+ upCh := make(chan interface{}, 5)
57+ downCh := make(chan interface{}, 5)
58+ proto := &testProtocol{up: upCh, down: downCh}
59+ sess.Protocolator = func(_ net.Conn) protocol.Protocol { return proto }
60+ sess.ErrCh = make(chan error, 1)
61+
62+ sess.Run()
63+
64+ // now walk it through start()
65+ takeNext(downCh) // connectMsg
66+ upCh <- nil // no error
67+ upCh <- protocol.ConnAckMsg{
68+ Type: "connack",
69+ Params: protocol.ConnAckParams{(10 * time.Millisecond).String()},
70+ }
71+ // in the mainloop!
72+ upCh <- io.EOF
73+ err = <-sess.ErrCh
74+ c.Check(err, Equals, io.EOF)
75+}
76+
77+/****************************************************************
78+ Reset() tests
79+****************************************************************/
80+
81+func (cs *clientSessionSuite) TestResetFailsWithoutProtocolator(c *C) {
82+ sess, err := NewSession("", nil, 0, "wah", debuglog)
83+ c.Assert(err, IsNil)
84+ sess.Protocolator = nil
85+ err = sess.Reset()
86+ c.Assert(err, NotNil)
87+ c.Check(err.Error(), Matches, ".*protocol constructor\\.")
88+}
89+
90+func (cs *clientSessionSuite) TestResetFailsWithNoAddress(c *C) {
91+ sess, err := NewSession("", nil, 0, "wah", debuglog)
92+ c.Assert(err, IsNil)
93+ err = sess.Reset()
94+ c.Assert(err, NotNil)
95+ c.Check(err.Error(), Matches, ".*dial.*address.*")
96+}
97+
98+func (cs *clientSessionSuite) TestResets(c *C) {
99+ upCh := make(chan interface{}, 5)
100+ downCh := make(chan interface{}, 5)
101+ srv, err := net.Listen("tcp", "localhost:0")
102+ c.Assert(err, IsNil)
103+ defer srv.Close()
104+
105+ sess, err := NewSession(srv.Addr().String(), nil, 0, "wah", debuglog)
106+ c.Assert(err, IsNil)
107+ proto := &testProtocol{up: upCh, down: downCh}
108+ sess.Connection = &testConn{Name: "TestResets"}
109+ sess.Protocolator = func(_ net.Conn) protocol.Protocol { return proto }
110+
111+ sess.Reset()
112+
113+ // wheee
114+ err = <-sess.ErrCh
115+ c.Assert(err, NotNil) // some random tcp error because
116+ // there's nobody talking to the port
117+}

Subscribers

People subscribed via source and target branches