Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for deadlines #60

Merged
merged 2 commits into from
May 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions multiplex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,58 @@ 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 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()

_, 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
Expand Down