|
4 | 4 | "bytes"
|
5 | 5 | "context"
|
6 | 6 | "errors"
|
| 7 | + "math/rand" |
| 8 | + "time" |
7 | 9 |
|
8 | 10 | "github.com/golang/mock/gomock"
|
9 | 11 | "github.com/lucas-clemente/quic-go/internal/protocol"
|
@@ -257,4 +259,44 @@ var _ = Describe("Streams Map (incoming)", func() {
|
257 | 259 | Expect(m.DeleteStream(1)).To(Succeed())
|
258 | 260 | })
|
259 | 261 | })
|
| 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 | + }) |
260 | 302 | })
|
0 commit comments