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

fix flaky TestStBackpressureStreamWrite test #1212

Merged
merged 1 commit into from Oct 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 7 additions & 10 deletions p2p/test/backpressure/backpressure_test.go
Expand Up @@ -28,8 +28,8 @@ func TestStBackpressureStreamWrite(t *testing.T) {
h2, err := bhost.NewHost(swarmt.GenSwarm(t), nil)
require.NoError(t, err)

// setup sender handler on 1
h1.SetStreamHandler(protocol.TestingID, func(s network.Stream) {
// setup sender handler on 2
h2.SetStreamHandler(protocol.TestingID, func(s network.Stream) {
defer s.Reset()
<-ctx.Done()
})
Expand All @@ -40,19 +40,16 @@ func TestStBackpressureStreamWrite(t *testing.T) {
t.Fatal("Failed to connect:", err)
}

// open a stream, from 2->1, this is our reader
s, err := h2.NewStream(ctx, h1.ID(), protocol.TestingID)
if err != nil {
t.Fatal(err)
}
// open a stream, from 1->2, this is our reader
s, err := h1.NewStream(ctx, h2.ID(), protocol.TestingID)
require.NoError(t, err)
defer s.Reset()

// If nobody is reading, we should eventually timeout.
// If nobody is reading, we should eventually time out.
require.NoError(t, s.SetWriteDeadline(time.Now().Add(100*time.Millisecond)))
data := make([]byte, 16*1024)
for i := 0; i < 5*1024; i++ { // write at most 100MiB
_, err := s.Write(data)
if err != nil {
if _, err := s.Write(data); err != nil {
require.True(t, os.IsTimeout(err), err)
return
}
Expand Down