Skip to content

Commit 46991ae

Browse files
add a randomized test for accepting streams
1 parent 64daf71 commit 46991ae

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

streams_map_incoming_generic_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"bytes"
55
"context"
66
"errors"
7+
"math/rand"
8+
"time"
79

810
"github.com/golang/mock/gomock"
911
"github.com/lucas-clemente/quic-go/internal/protocol"
@@ -257,4 +259,44 @@ var _ = Describe("Streams Map (incoming)", func() {
257259
Expect(m.DeleteStream(1)).To(Succeed())
258260
})
259261
})
262+
263+
Context("randomized tests", func() {
264+
const num = 1000
265+
266+
BeforeEach(func() { maxNumStreams = num })
267+
268+
It("opens and accepts streams", func() {
269+
rand.Seed(GinkgoRandomSeed())
270+
ids := make([]protocol.StreamNum, num)
271+
for i := 0; i < num; i++ {
272+
ids[i] = protocol.StreamNum(i + 1)
273+
}
274+
rand.Shuffle(len(ids), func(i, j int) { ids[i], ids[j] = ids[j], ids[i] })
275+
276+
const timeout = 5 * time.Second
277+
done := make(chan struct{}, 2)
278+
go func() {
279+
defer GinkgoRecover()
280+
ctx, cancel := context.WithTimeout(context.Background(), timeout)
281+
defer cancel()
282+
for i := 0; i < num; i++ {
283+
_, err := m.AcceptStream(ctx)
284+
Expect(err).ToNot(HaveOccurred())
285+
}
286+
done <- struct{}{}
287+
}()
288+
289+
go func() {
290+
defer GinkgoRecover()
291+
for i := 0; i < num; i++ {
292+
_, err := m.GetOrOpenStream(ids[i])
293+
Expect(err).ToNot(HaveOccurred())
294+
}
295+
done <- struct{}{}
296+
}()
297+
298+
Eventually(done, timeout*3/2).Should(Receive())
299+
Eventually(done, timeout*3/2).Should(Receive())
300+
})
301+
})
260302
})

0 commit comments

Comments
 (0)