Skip to content

Commit b31aff1

Browse files
Merged PR 716570: Fix flaky ResourcePoolTests for net7
Fix flaky ResourcePoolTests for net7
1 parent 142ef36 commit b31aff1

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Public/Src/Cache/ContentStore/Test/Utils/ResourcePoolTests.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using ContentStoreTest.Test;
2222
using FluentAssertions;
2323
using Xunit;
24+
using Xunit.Abstractions;
2425

2526
#nullable enable
2627

@@ -257,8 +258,9 @@ await pool.UseAsync(context, key, async wrapper =>
257258
public async Task ResourceInvalidationRespectsReferenceCountBeforeShutdown()
258259
{
259260
var stopLatch = TaskUtilities.CreateMutex(taken: true);
261+
var firstUseIsDone = new TaskCompletionSource<object>();
260262
Task? outstandingTask = null;
261-
263+
262264
CounterCollection<ResourcePoolCounters>? counters = null;
263265

264266
await RunTest<Key, Resource>(async (context, pool) =>
@@ -273,14 +275,10 @@ await pool.UseAsync(context, key, async wrapper =>
273275
wrapper2.ReferenceCount.Should().Be(2);
274276
stopLatch.Release();
275277

276-
try
277-
{
278-
await Task.Delay(Timeout.InfiniteTimeSpan, wrapper2.ShutdownToken);
279-
}
280-
catch (TaskCanceledException) { }
278+
// Waiting for the first UseAsync to be done before checking the states
279+
await firstUseIsDone.Task;
281280

282281
wrapper2.ReferenceCount.Should().Be(1);
283-
284282
counters[ResourcePoolCounters.CreatedResources].Value.Should().Be(1);
285283
counters[ResourcePoolCounters.ReleasedResources].Value.Should().Be(0);
286284
counters[ResourcePoolCounters.ShutdownAttempts].Value.Should().Be(0);
@@ -293,6 +291,9 @@ await pool.UseAsync(context, key, async wrapper =>
293291

294292
return BoolResult.Success;
295293
}).ShouldBeSuccess();
294+
295+
// Notifying that the first UseAsync is done.
296+
firstUseIsDone.SetResult(string.Empty);
296297
});
297298

298299
Contract.AssertNotNull(counters);

0 commit comments

Comments
 (0)