Skip to content

Commit 7418f36

Browse files
authored
Merge pull request #1544 from microsoft/dev/andarno/testStabilization
Fix flaky GC-based tests in AsyncLazyTests
2 parents b5f38e9 + 5af463e commit 7418f36

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

test/Microsoft.VisualStudio.Threading.Tests/AsyncLazyTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,11 @@ public async Task ValueFactoryReleasedAfterExecution()
153153
{
154154
WeakReference collectible = await this.ValueFactoryReleasedAfterExecution_Helper();
155155

156+
await Task.Yield();
156157
for (int i = 0; i < 3; i++)
157158
{
158-
await Task.Yield();
159-
GC.Collect();
159+
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, blocking: true);
160+
GC.WaitForPendingFinalizers();
160161
}
161162

162163
Assert.False(collectible.IsAlive);
@@ -167,10 +168,11 @@ public async Task AsyncPumpReleasedAfterExecution(bool throwInValueFactory)
167168
{
168169
WeakReference collectible = await this.AsyncPumpReleasedAfterExecution_Helper(throwInValueFactory);
169170

171+
await Task.Yield();
170172
for (int i = 0; i < 3; i++)
171173
{
172-
await Task.Yield();
173-
GC.Collect();
174+
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, blocking: true);
175+
GC.WaitForPendingFinalizers();
174176
}
175177

176178
Assert.False(collectible.IsAlive);

0 commit comments

Comments
 (0)