Add tests that check for EOF on pipe close

This commit is contained in:
John Starks
2016-03-14 16:33:35 -07:00
parent f778f05015
commit 0c1e4a09ec
+33
View File
@@ -2,6 +2,7 @@ package winio
import (
"bufio"
"io"
"net"
"os"
"syscall"
@@ -174,6 +175,38 @@ func TestCloseAbortsListen(t *testing.T) {
}
}
func ensureEOFOnClose(t *testing.T, r io.Reader, w io.Closer) {
b := make([]byte, 10)
w.Close()
n, err := r.Read(b)
if n > 0 {
t.Errorf("unexpected byte count %d", n)
}
if err != io.EOF {
t.Errorf("expected EOF: %v", err)
}
}
func TestCloseClientEOFServer(t *testing.T) {
c, s, err := getConnection()
if err != nil {
t.Fatal(err)
}
defer c.Close()
defer s.Close()
ensureEOFOnClose(t, c, s)
}
func TestCloseServerEOFClient(t *testing.T) {
c, s, err := getConnection()
if err != nil {
t.Fatal(err)
}
defer c.Close()
defer s.Close()
ensureEOFOnClose(t, s, c)
}
func TestAcceptAfterCloseFails(t *testing.T) {
l, err := ListenPipe(testPipeName, "")
if err != nil {