Skip to content

Commit

Permalink
[QUIC] Add synchronize for streams available callback (dotnet#106678)
Browse files Browse the repository at this point in the history
* Add synchronize for streams available callback

* Feedback
  • Loading branch information
ManickaP authored Aug 21, 2024
1 parent 1140d4d commit 14eca7c
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,13 @@ public async Task GetStreamCapacity_SumInvariant()
{
int maxStreamIndex = 0;
const int Limit = 5;
SemaphoreSlim streamsAvailableFired = new SemaphoreSlim(0);

var clientOptions = CreateQuicClientOptions(new IPEndPoint(0, 0));
clientOptions.StreamCapacityCallback = (connection, args) =>
{
Interlocked.Add(ref maxStreamIndex, args.BidirectionalIncrement);
streamsAvailableFired.Release();
};

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

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

while (maxStreamIndex < Limit)
{
await streamsAvailableFired.WaitAsync().WaitAsync(PassingTestTimeout);
}
Assert.Equal(Limit, maxStreamIndex);

Queue<(QuicStream client, QuicStream server)> streams = new();
Expand Down Expand Up @@ -509,8 +515,11 @@ public async Task GetStreamCapacity_SumInvariant()
}
}

// give time to update the count
await Task.Delay(1000);
// wait for the callback
while (maxStreamIndex < 3 * Limit)
{
await streamsAvailableFired.WaitAsync().WaitAsync(PassingTestTimeout);
}

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

0 comments on commit 14eca7c

Please sign in to comment.