Skip to content

Commit 58b105e

Browse files
committed
- fix test
1 parent a5e96f4 commit 58b105e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Controls/tests/Core.UnitTests/ButtonUnitTest.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,19 @@ public async Task ButtonWithCommandBindingCanBeGarbageCollected()
2828
buttonWeakRef = new WeakReference(button);
2929
proxyWeakRef = new WeakReference(((ICommandElement)button).CleanupTracker);
3030
proxyProxyWeakRef = new WeakReference(((ICommandElement)button).CleanupTracker?.Proxy);
31+
32+
await TestHelpers.Collect();
3133
await TestHelpers.Collect();
3234

3335
// Make sure everything is still alive if the button is still in scope
36+
// We need to reference the button here again to keep it alive
37+
// awaiting a Task appears to move us to a new scope and causes the button to be collected
38+
Assert.NotNull(button);
3439
Assert.True(buttonWeakRef.IsAlive);
3540
Assert.True(proxyWeakRef.IsAlive);
3641
Assert.True(proxyProxyWeakRef.IsAlive);
37-
}
42+
}
43+
3844

3945
Assert.False(await buttonWeakRef.WaitForCollect());
4046
Assert.False(await proxyWeakRef.WaitForCollect());
@@ -71,8 +77,12 @@ public async Task ButtonWithWeakEventHandlerIsntCollectedTooEarly()
7177
proxyWeakRef = new WeakReference(((ICommandElement)button).CleanupTracker);
7278
proxyProxyWeakRef = new WeakReference(((ICommandElement)button).CleanupTracker?.Proxy);
7379
await TestHelpers.Collect();
80+
await TestHelpers.Collect();
7481

7582
// Make sure everything is still alive if the button is still in scope
83+
// We need to reference the button here again to keep it alive
84+
// awaiting a Task appears to move us to a new scope and causes the button to be collected
85+
Assert.NotNull(button);
7686
Assert.True(buttonWeakRef.IsAlive);
7787
Assert.True(proxyWeakRef.IsAlive);
7888
Assert.True(proxyProxyWeakRef.IsAlive);

0 commit comments

Comments
 (0)