diff options
author | E.Z. Hart <hartez@users.noreply.github.com> | 2017-04-13 08:40:05 -0600 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2017-04-13 16:15:43 +0100 |
commit | fc778eb9789f50634d48fb9ad127f211b3fcfcc7 (patch) | |
tree | c9ccf2077424aef0d5cdc7b6591fb82bac77d377 | |
parent | 811b9bc56777f92c223321436f2fc87b455185f0 (diff) | |
download | xamarin-forms-fc778eb9789f50634d48fb9ad127f211b3fcfcc7.tar.gz xamarin-forms-fc778eb9789f50634d48fb9ad127f211b3fcfcc7.tar.bz2 xamarin-forms-fc778eb9789f50634d48fb9ad127f211b3fcfcc7.zip |
Update ListProxyTest.WeakToWeak so it works in Release mode (#866)
* Update ListProxyTest.WeakToWeak so it works in Release mode
* Disable CS0414 for test
-rw-r--r-- | Xamarin.Forms.Core.UnitTests/ListProxyTests.cs | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/Xamarin.Forms.Core.UnitTests/ListProxyTests.cs b/Xamarin.Forms.Core.UnitTests/ListProxyTests.cs index 2d9cda41..cd94e717 100644 --- a/Xamarin.Forms.Core.UnitTests/ListProxyTests.cs +++ b/Xamarin.Forms.Core.UnitTests/ListProxyTests.cs @@ -423,29 +423,31 @@ namespace Xamarin.Forms.Core.UnitTests } } + // Need a member to keep this reference around, otherwise it gets optimized + // out early in Release mode during the WeakToWeak test +#pragma warning disable 0414 // Never accessed, it's just here to prevent GC + ListProxy _proxyForWeakToWeakTest; +#pragma warning restore 0414 + [Test] - [Ignore()] - //TODO: Need to figure why this is failing on release public void WeakToWeak() { WeakCollectionChangedList list = new WeakCollectionChangedList(); - var proxy = new ListProxy(list); + _proxyForWeakToWeakTest = new ListProxy(list); - Assert.True(list.AddObject()); + Assert.True(list.AddObject(), "GC hasn't run"); GC.Collect(); GC.WaitForPendingFinalizers(); - GC.Collect(); - Assert.IsTrue(list.AddObject()); + Assert.IsTrue(list.AddObject(), "GC run, but proxy should still hold a reference"); - proxy = null; + _proxyForWeakToWeakTest = null; GC.Collect(); GC.WaitForPendingFinalizers(); - GC.Collect(); - Assert.IsFalse(list.AddObject()); + Assert.IsFalse(list.AddObject(), "Proxy is gone and GC has run"); } public class WeakCollectionChangedList : List<object>, INotifyCollectionChanged @@ -467,7 +469,7 @@ namespace Xamarin.Forms.Core.UnitTests { bool invoked = false; var me = new object(); - + Console.WriteLine($"Handler count is {handlers.Count}"); foreach (var handler in handlers.ToList()) { if (handler.IsActive) @@ -477,6 +479,7 @@ namespace Xamarin.Forms.Core.UnitTests } else { + Console.WriteLine($"Handler is inactive"); handlers.Remove(handler); } } |