Browse Source

Defer closing stream for reading

merge-testsuite-transports
Dennis Trautwein 4 years ago
parent
commit
d1d34d8802
  1. 5
      p2p/transport/testsuite/stream_suite.go
  2. 19
      p2p/transport/testsuite/transport_suite.go

5
p2p/transport/testsuite/stream_suite.go

@ -55,7 +55,7 @@ type Options struct {
}
func fullClose(t *testing.T, s mux.MuxedStream) {
if err := s.Close(); err != nil {
if err := s.CloseWrite(); err != nil {
t.Error(err)
s.Reset()
return
@ -67,6 +67,9 @@ func fullClose(t *testing.T, s mux.MuxedStream) {
if len(b) != 0 {
t.Error("expected to be done reading")
}
if err := s.Close(); err != nil {
t.Error(err)
}
}
func randBuf(size int) []byte {

19
p2p/transport/testsuite/transport_suite.go

@ -141,8 +141,8 @@ func SubtestBasic(t *testing.T, ta, tb transport.Transport, maddr ma.Multiaddr,
t.Fatalf("failed to write enough data (a->b)")
return
}
err = s.Close()
if err != nil {
if err = s.CloseWrite(); err != nil {
t.Fatal(err)
return
}
@ -155,6 +155,11 @@ func SubtestBasic(t *testing.T, ta, tb transport.Transport, maddr ma.Multiaddr,
if !bytes.Equal(testData, buf) {
t.Errorf("expected %s, got %s", testData, buf)
}
if err = s.Close(); err != nil {
t.Fatal(err)
return
}
}
func SubtestPingPong(t *testing.T, ta, tb transport.Transport, maddr ma.Multiaddr, peerA peer.ID) {
@ -265,7 +270,10 @@ func SubtestPingPong(t *testing.T, ta, tb transport.Transport, maddr ma.Multiadd
t.Error("failed to write enough data (a->b)")
return
}
s.Close()
if err = s.CloseWrite(); err != nil {
t.Fatal(err)
return
}
ret, err := ioutil.ReadAll(s)
if err != nil {
@ -276,6 +284,11 @@ func SubtestPingPong(t *testing.T, ta, tb transport.Transport, maddr ma.Multiadd
if !bytes.Equal(data, ret) {
t.Errorf("expected %q, got %q", string(data), string(ret))
}
if err = s.Close(); err != nil {
t.Fatal(err)
return
}
}(i)
}
wg.Wait()

Loading…
Cancel
Save