From 19a8cb5f399591f6116b2893aaa4d0d7bcc339de Mon Sep 17 00:00:00 2001 From: vyzo Date: Thu, 23 May 2019 16:13:31 +0300 Subject: [PATCH] add test for read after close --- multiplex_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/multiplex_test.go b/multiplex_test.go index 9e66a80..9797b8d 100644 --- a/multiplex_test.go +++ b/multiplex_test.go @@ -455,6 +455,34 @@ func TestDeadline(t *testing.T) { } } +func TestReadAfterClose(t *testing.T) { + a, b := net.Pipe() + + mpa := NewMultiplex(a, false) + mpb := NewMultiplex(b, true) + + defer mpa.Close() + defer mpb.Close() + + sa, err := mpa.NewStream() + if err != nil { + t.Fatal(err) + } + sb, err := mpb.Accept() + if err != nil { + t.Fatal(err) + } + + sa.Close() + + time.Sleep(10 * time.Millisecond) + + _, err = sb.Read(make([]byte, 1024)) + if err != io.EOF { + t.Fatal("expected EOF") + } +} + func TestFuzzCloseStream(t *testing.T) { timer := time.AfterFunc(10*time.Second, func() { // This is really the *only* reliable way to set a timeout on