@cryptotaxi247 / kubo / commits / 7217d6a23

fix mock notification test

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Sep 3, 2015 at 14:28 UTC 7217d6a23632fcdd9037989e1c1fe32091d95fdb
2 files changed +16 -6
p2p/net/mock/mock_notif_test.go
+11 -6
@@ -111,10 +111,8 @@ func TestNotifications(t *testing.T) {
111 }
112 }
113
114 - streams := make(chan inet.Stream)
114 for _, s := range nets {
115 s.SetStreamHandler(func(s inet.Stream) {
117 - streams <- s
116 s.Close()
117 })
118 }
@@ -123,10 +121,17 @@ func TestNotifications(t *testing.T) {
121 // unsure where these are coming from
122 for i := range nets {
123 n := notifiees[i]
126 - testOCStream(n, nil)
127 - testOCStream(n, nil)
128 - testOCStream(n, nil)
129 - testOCStream(n, nil)
124 + for j := 0; j < len(nets)-1; j++ {
125 + testOCStream(n, nil)
126 + }
127 + }
128 +
129 + streams := make(chan inet.Stream)
130 + for _, s := range nets {
131 + s.SetStreamHandler(func(s inet.Stream) {
132 + streams <- s
133 + s.Close()
134 + })
135 }
136
137 // open a streams in each conn
p2p/protocol/identify/id.go
+5
@@ -80,6 +80,8 @@ func (ids *IDService) IdentifyConn(c inet.Conn) {
80 if err != nil {
81 log.Debugf("error opening initial stream for %s", ID)
82 log.Event(context.TODO(), "IdentifyOpenFailed", c.RemotePeer())
83 + c.Close()
84 + return
85 } else {
86 bwc := ids.Host.GetBandwidthReporter()
87 s = mstream.WrapStream(s, ID, bwc)
@@ -88,6 +90,9 @@ func (ids *IDService) IdentifyConn(c inet.Conn) {
90 if err := protocol.WriteHeader(s, ID); err != nil {
91 log.Debugf("error writing stream header for %s", ID)
92 log.Event(context.TODO(), "IdentifyOpenFailed", c.RemotePeer())
93 + s.Close()
94 + c.Close()
95 + return
96 }
97 ids.ResponseHandler(s)
98 }