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
=== modified file 'client/session/session.go'
--- client/session/session.go 2014-01-31 17:52:59 +0000
+++ client/session/session.go 2014-01-31 17:52:59 +0000
@@ -203,3 +203,34 @@
203 sess.Log.Debugf("Connected %v.", conn.LocalAddr())203 sess.Log.Debugf("Connected %v.", conn.LocalAddr())
204 return nil204 return nil
205}205}
206
207func (sess *ClientSession) Run() {
208 go func() {
209 err := sess.checkRunnable()
210 if err == nil {
211 err = sess.start()
212 if err == nil {
213 err = sess.run()
214 }
215 }
216 sess.ErrCh <- err
217 }()
218}
219
220func (sess *ClientSession) Reset() error {
221 if sess.Protocolator == nil {
222 return errors.New("Can't Reset() without a protocol constructor.")
223 }
224 if sess.Connection != nil {
225 sess.Close() // just in case
226 }
227 err := sess.Dial()
228 if err != nil {
229 sess.Log.Errorf("%s", err)
230 return err
231 }
232 sess.ErrCh = make(chan error, 1)
233 sess.MsgCh = make(chan *Notification)
234 sess.Run()
235 return nil
236}
206237
=== modified file 'client/session/session_test.go'
--- client/session/session_test.go 2014-01-31 17:52:59 +0000
+++ client/session/session_test.go 2014-01-31 17:52:59 +0000
@@ -559,3 +559,74 @@
559 err = <-errCh559 err = <-errCh
560 c.Assert(err, IsNil)560 c.Assert(err, IsNil)
561}561}
562
563/****************************************************************
564 Run() tests
565****************************************************************/
566
567func (cs *clientSessionSuite) TestRunRuns(c *C) {
568 sess, err := NewSession("", nil, 0, "wah", debuglog)
569 c.Assert(err, IsNil)
570 sess.Connection = &testConn{Name: "TestRunRuns"}
571 upCh := make(chan interface{}, 5)
572 downCh := make(chan interface{}, 5)
573 proto := &testProtocol{up: upCh, down: downCh}
574 sess.Protocolator = func(_ net.Conn) protocol.Protocol { return proto }
575 sess.ErrCh = make(chan error, 1)
576
577 sess.Run()
578
579 // now walk it through start()
580 takeNext(downCh) // connectMsg
581 upCh <- nil // no error
582 upCh <- protocol.ConnAckMsg{
583 Type: "connack",
584 Params: protocol.ConnAckParams{(10 * time.Millisecond).String()},
585 }
586 // in the mainloop!
587 upCh <- io.EOF
588 err = <-sess.ErrCh
589 c.Check(err, Equals, io.EOF)
590}
591
592/****************************************************************
593 Reset() tests
594****************************************************************/
595
596func (cs *clientSessionSuite) TestResetFailsWithoutProtocolator(c *C) {
597 sess, err := NewSession("", nil, 0, "wah", debuglog)
598 c.Assert(err, IsNil)
599 sess.Protocolator = nil
600 err = sess.Reset()
601 c.Assert(err, NotNil)
602 c.Check(err.Error(), Matches, ".*protocol constructor\\.")
603}
604
605func (cs *clientSessionSuite) TestResetFailsWithNoAddress(c *C) {
606 sess, err := NewSession("", nil, 0, "wah", debuglog)
607 c.Assert(err, IsNil)
608 err = sess.Reset()
609 c.Assert(err, NotNil)
610 c.Check(err.Error(), Matches, ".*dial.*address.*")
611}
612
613func (cs *clientSessionSuite) TestResets(c *C) {
614 upCh := make(chan interface{}, 5)
615 downCh := make(chan interface{}, 5)
616 srv, err := net.Listen("tcp", "localhost:0")
617 c.Assert(err, IsNil)
618 defer srv.Close()
619
620 sess, err := NewSession(srv.Addr().String(), nil, 0, "wah", debuglog)
621 c.Assert(err, IsNil)
622 proto := &testProtocol{up: upCh, down: downCh}
623 sess.Connection = &testConn{Name: "TestResets"}
624 sess.Protocolator = func(_ net.Conn) protocol.Protocol { return proto }
625
626 sess.Reset()
627
628 // wheee
629 err = <-sess.ErrCh
630 c.Assert(err, NotNil) // some random tcp error because
631 // there's nobody talking to the port
632}

Subscribers

People subscribed via source and target branches