From 8917d6087c3c770aa88e25bdfe646a8d8c3c44de Mon Sep 17 00:00:00 2001 From: vyzo Date: Thu, 23 May 2019 01:09:51 +0300 Subject: [PATCH] add deadline test --- multiplex_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/multiplex_test.go b/multiplex_test.go index 4445d3c..9e66a80 100644 --- a/multiplex_test.go +++ b/multiplex_test.go @@ -429,6 +429,32 @@ func TestOpenAfterClose(t *testing.T) { mpb.Close() } +func TestDeadline(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) + } + _, err = mpb.Accept() + if err != nil { + t.Fatal(err) + } + + sa.SetDeadline(time.Now().Add(time.Second)) + + _, err = sa.Read(make([]byte, 1024)) + if err != errTimeout { + t.Fatal("expected timeout") + } +} + func TestFuzzCloseStream(t *testing.T) { timer := time.AfterFunc(10*time.Second, func() { // This is really the *only* reliable way to set a timeout on