Skip to content

Commit

Permalink
Make the ActivityCTS test more reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan committed Dec 16, 2024
1 parent 40fdad5 commit a10c42e
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ namespace Yarp.ReverseProxy.Utilities.Tests;
public class ActivityCancellationTokenSourceTests
{
[Fact]
public void ActivityCancellationTokenSource_PoolsSources()
public async Task ActivityCancellationTokenSource_PoolsSources()
{
// This test can run in parallel with others making use of ActivityCancellationTokenSource
// A different thread could have already added/removed a source from the queue
// This test can run in parallel with others making use of ActivityCancellationTokenSource.
// A different thread could have already added/removed a source from the queue (hence the retries).

for (var i = 0; i < 1000; i++)
for (var i = 0; i < 10_000; i++)
{
var cts = ActivityCancellationTokenSource.Rent(TimeSpan.FromSeconds(10), CancellationToken.None);
cts.Return();
Expand All @@ -28,6 +28,8 @@ public void ActivityCancellationTokenSource_PoolsSources()
{
return;
}

await Task.Delay(1);
}

Assert.Fail("CancellationTokenSources were not pooled");
Expand Down

0 comments on commit a10c42e

Please sign in to comment.