-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
151 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package memory | ||
|
||
import ( | ||
"github.com/stretchr/testify/require" | ||
"io" | ||
"testing" | ||
) | ||
|
||
func TestStreamSimpleReadWriteClose(t *testing.T) { | ||
//client, server := getDetachedDataChannels(t) | ||
ra, wb := io.Pipe() | ||
rb, wa := io.Pipe() | ||
|
||
clientStr := newStream(0, ra, wa) | ||
serverStr := newStream(0, rb, wb) | ||
|
||
// send a foobar from the client | ||
n, err := clientStr.Write([]byte("foobar")) | ||
require.NoError(t, err) | ||
require.Equal(t, 6, n) | ||
require.NoError(t, clientStr.CloseWrite()) | ||
// writing after closing should error | ||
_, err = clientStr.Write([]byte("foobar")) | ||
require.Error(t, err) | ||
//require.False(t, clientDone.Load()) | ||
|
||
// now read all the data on the server side | ||
b, err := io.ReadAll(serverStr) | ||
require.NoError(t, err) | ||
require.Equal(t, []byte("foobar"), b) | ||
// reading again should give another io.EOF | ||
n, err = serverStr.Read(make([]byte, 10)) | ||
require.Zero(t, n) | ||
require.ErrorIs(t, err, io.EOF) | ||
//require.False(t, serverDone.Load()) | ||
|
||
// send something back | ||
_, err = serverStr.Write([]byte("lorem ipsum")) | ||
require.NoError(t, err) | ||
require.NoError(t, serverStr.CloseWrite()) | ||
|
||
// and read it at the client | ||
//require.False(t, clientDone.Load()) | ||
b, err = io.ReadAll(clientStr) | ||
require.NoError(t, err) | ||
require.Equal(t, []byte("lorem ipsum"), b) | ||
|
||
// stream is only cleaned up on calling Close or Reset | ||
clientStr.Close() | ||
serverStr.Close() | ||
//require.Eventually(t, func() bool { return clientDone.Load() }, 5*time.Second, 100*time.Millisecond) | ||
// Need to call Close for cleanup. Otherwise the FIN_ACK is never read | ||
require.NoError(t, serverStr.Close()) | ||
//require.Eventually(t, func() bool { return serverDone.Load() }, 5*time.Second, 100*time.Millisecond) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters