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

webtransport: fix flaky accept queue test #1938

Merged
merged 1 commit into from
Dec 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 41 additions & 8 deletions p2p/transport/webtransport/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,17 +473,50 @@ func TestAcceptQueueFilledUp(t *testing.T) {
return cl.Dial(context.Background(), ln.Multiaddr(), serverID)
}

for i := 0; i < 16; i++ {
conn, err := newConn()
require.NoError(t, err)
defer conn.Close()
const num = 16 + 1 // one more than the accept queue capacity
// Dial one more connection than the accept queue can hold.
errChan := make(chan error, num)
for i := 0; i < num; i++ {
go func() {
conn, err := newConn()
if err != nil {
errChan <- err
return
}
_, err = conn.AcceptStream()
errChan <- err
}()
}

conn, err := newConn()
if err == nil {
_, err = conn.AcceptStream()
// Since the handshakes complete asynchronously, we won't know _which_ one is rejected,
// so the only thing we can test for is that exactly one connection attempt is rejected.
select {
case <-errChan:
case <-time.After(time.Second):
t.Fatal("expected one connection to be rejected")
}
select {
case <-errChan:
t.Fatal("only expected one connection to be rejected")
case <-time.After(100 * time.Millisecond):
}

// test shutdown
require.NoError(t, ln.Close())
var count int
timer := time.NewTimer(time.Second)
defer timer.Stop()
for i := 0; i < 16; i++ {
select {
case <-errChan:
count++
if count == 16 {
return
}
case <-timer.C:
t.Fatal("shutdown failed")
}
}
require.Error(t, err)
}

type reportingRcmgr struct {
Expand Down