Skip to content

Commit 14eca7c

Browse files
authored
[QUIC] Add synchronize for streams available callback (#106678)
* Add synchronize for streams available callback * Feedback
1 parent 1140d4d commit 14eca7c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/libraries/System.Net.Quic/tests/FunctionalTests/QuicConnectionTests.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,13 @@ public async Task GetStreamCapacity_SumInvariant()
455455
{
456456
int maxStreamIndex = 0;
457457
const int Limit = 5;
458+
SemaphoreSlim streamsAvailableFired = new SemaphoreSlim(0);
458459

459460
var clientOptions = CreateQuicClientOptions(new IPEndPoint(0, 0));
460461
clientOptions.StreamCapacityCallback = (connection, args) =>
461462
{
462463
Interlocked.Add(ref maxStreamIndex, args.BidirectionalIncrement);
464+
streamsAvailableFired.Release();
463465
};
464466

465467
var listenerOptions = CreateQuicListenerOptions();
@@ -472,6 +474,10 @@ public async Task GetStreamCapacity_SumInvariant()
472474

473475
(QuicConnection clientConnection, QuicConnection serverConnection) = await CreateConnectedQuicConnection(clientOptions, listenerOptions);
474476

477+
while (maxStreamIndex < Limit)
478+
{
479+
await streamsAvailableFired.WaitAsync().WaitAsync(PassingTestTimeout);
480+
}
475481
Assert.Equal(Limit, maxStreamIndex);
476482

477483
Queue<(QuicStream client, QuicStream server)> streams = new();
@@ -509,8 +515,11 @@ public async Task GetStreamCapacity_SumInvariant()
509515
}
510516
}
511517

512-
// give time to update the count
513-
await Task.Delay(1000);
518+
// wait for the callback
519+
while (maxStreamIndex < 3 * Limit)
520+
{
521+
await streamsAvailableFired.WaitAsync().WaitAsync(PassingTestTimeout);
522+
}
514523

515524
// by now, we opened and closed 2 * Limit, and expect a budget of 'Limit' more
516525
Assert.Equal(3 * Limit, maxStreamIndex);

0 commit comments

Comments
 (0)