Skip to content

Commit

Permalink
test: rename variables and expand comments
Browse files Browse the repository at this point in the history
0 functional changes.
  • Loading branch information
schmichael committed Aug 15, 2024
1 parent d96c90e commit 79d8b58
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,25 +754,27 @@ func TestManyStreams_PingPong(t *testing.T) {
drainErrorsUntil(t, errCh, 2*streams, 0, "")
}

// TestHalfClose asserts that half closed streams can still read.
func TestHalfClose(t *testing.T) {
client, server := testClientServer(t)

stream, err := client.Open()
clientStream, err := client.Open()
if err != nil {
t.Fatalf("err: %v", err)
}
if _, err = stream.Write([]byte("a")); err != nil {
if _, err = clientStream.Write([]byte("a")); err != nil {
t.Fatalf("err: %v", err)
}

stream2, err := server.Accept()
serverStream, err := server.Accept()
if err != nil {
t.Fatalf("err: %v", err)
}
stream2.Close() // Half close
serverStream.Close() // Half close

// Server reads 1 byte written by Client
buf := make([]byte, 4)
n, err := stream2.Read(buf)
n, err := serverStream.Read(buf)
if err != nil {
t.Fatalf("err: %v", err)
}
Expand All @@ -781,13 +783,14 @@ func TestHalfClose(t *testing.T) {
}

// Send more
if _, err = stream.Write([]byte("bcd")); err != nil {
if _, err = clientStream.Write([]byte("bcd")); err != nil {
t.Fatalf("err: %v", err)
}
stream.Close()
clientStream.Close()

// Read after close
n, err = stream2.Read(buf)
// Read after close always returns the bytes written but may or may not
// receive the EOF.
n, err = serverStream.Read(buf)
if err != nil {
t.Fatalf("err: %v", err)
}
Expand All @@ -796,7 +799,7 @@ func TestHalfClose(t *testing.T) {
}

// EOF after close
n, err = stream2.Read(buf)
n, err = serverStream.Read(buf)
if err != io.EOF {
t.Fatalf("err: %v", err)
}
Expand Down

0 comments on commit 79d8b58

Please sign in to comment.