Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
Signed-off-by: David Golub <[email protected]>
  • Loading branch information
dgolub committed Jul 24, 2023
1 parent f0bd89d commit b8d8194
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions pipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,63 @@ func TestTimeoutPendingWrite(t *testing.T) {
<-serverDone
}

func TestDisconnectPipe(t *testing.T) {
l, err := ListenPipe(testPipeName, nil)
if err != nil {
t.Fatal(err)
}
defer l.Close()

const testData = "foo"
serverDone := make(chan struct{})

go func() {
s, err := l.Accept()
if err != nil {
t.Fatal(err)
return
}
defer func() {
s.Close()
close(serverDone)
}()

if _, err := s.Write([]byte(testData)); err != nil {
t.Fatal(err)
}

if err := s.(PipeConn).Flush(); err != nil {
t.Fatal(err)
}

if err := s.(PipeConn).Disconnect(); err != nil {
t.Fatal(err)
}
}()

client, err := DialPipe(testPipeName, nil)
if err != nil {
t.Fatal(err)
}
defer client.Close()

buf := make([]byte, len(testData))
if _, err = client.Read(buf); err != nil {
t.Fatal(err)
}

dataRead := string(buf)
if dataRead != testData {
t.Fatalf("incorrect data read %q", dataRead)
}

if _, err = client.Read(buf); err == nil {
t.Fatal("read should fail")
}

<-serverDone
}

type CloseWriter interface {
CloseWrite() error
}
Expand Down

0 comments on commit b8d8194

Please sign in to comment.