Browse Source

Moved some leak tests to LeakTests.

So they can be debugged in dotMemory.
Steven Kirk 9 years ago
parent
commit
50b0b687cd

+ 1 - 1
src/Markup/Avalonia.Markup/Data/PropertyAccessorNode.cs

@@ -12,7 +12,7 @@ namespace Avalonia.Markup.Data
 {
     internal class PropertyAccessorNode : ExpressionNode
     {
-        private bool _enableValidation;
+        private readonly bool _enableValidation;
         private IPropertyAccessor _accessor;
 
         public PropertyAccessorNode(string propertyName, bool enableValidation)

+ 1 - 0
tests/Avalonia.LeakTests/Avalonia.LeakTests.csproj

@@ -84,6 +84,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="ControlTests.cs" />
+    <Compile Include="ExpressionObserverTests.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>

+ 74 - 0
tests/Avalonia.LeakTests/ExpressionObserverTests.cs

@@ -0,0 +1,74 @@
+using System;
+using System.Collections.Generic;
+using Avalonia.Collections;
+using Avalonia.Markup.Data;
+using Avalonia.UnitTests;
+using JetBrains.dotMemoryUnit;
+using Xunit;
+using Xunit.Abstractions;
+
+namespace Avalonia.LeakTests
+{
+    [DotMemoryUnit(FailIfRunWithoutSupport = false)]
+    public class ExpressionObserverTests
+    {
+        public ExpressionObserverTests(ITestOutputHelper atr)
+        {
+            DotMemoryUnitTestOutput.SetOutputMethod(atr.WriteLine);
+        }
+
+        [Fact]
+        public void Should_Not_Keep_Source_Alive_ObservableCollection()
+        {
+            Func<ExpressionObserver> run = () =>
+            {
+                var source = new { Foo = new AvaloniaList<string> {"foo", "bar"} };
+                var target = new ExpressionObserver(source, "Foo");
+
+                target.Subscribe(_ => { });
+                return target;
+            };
+
+            var result = run();
+
+            dotMemory.Check(memory => 
+                Assert.Equal(0, memory.GetObjects(where => where.Type.Is<AvaloniaList<string>>()).ObjectsCount));
+        }
+
+        [Fact]
+        public void Should_Not_Keep_Source_Alive_NonIntegerIndexer()
+        {
+            Func<ExpressionObserver> run = () =>
+            {
+                var source = new { Foo = new NonIntegerIndexer() };
+                var target = new ExpressionObserver(source, "Foo");
+
+                target.Subscribe(_ => { });
+                return target;
+            };
+
+            var result = run();
+
+            dotMemory.Check(memory =>
+                Assert.Equal(0, memory.GetObjects(where => where.Type.Is<NonIntegerIndexer>()).ObjectsCount));
+        }
+
+        private class NonIntegerIndexer : NotifyingBase
+        {
+            private readonly Dictionary<string, string> _storage = new Dictionary<string, string>();
+
+            public string this[string key]
+            {
+                get
+                {
+                    return _storage[key];
+                }
+                set
+                {
+                    _storage[key] = value;
+                    RaisePropertyChanged(CommonPropertyNames.IndexerName);
+                }
+            }
+        }
+    }
+}

+ 3 - 39
tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_Indexer.cs

@@ -192,55 +192,19 @@ namespace Avalonia.Markup.UnitTests.Data
             Assert.Equal(0, data.Foo.PropertyChangedSubscriptionCount);
         }
 
-        [Fact]
-        public void Should_Not_Keep_Source_Alive_ObservableCollection()
-        {
-            Func<Tuple<ExpressionObserver, WeakReference>> run = () =>
-            {
-                var source = new { Foo = new AvaloniaList<string> { "foo", "bar" } };
-                var target = new ExpressionObserver(source, "Foo");
-                return Tuple.Create(target, new WeakReference(source.Foo));
-            };
-
-            var result = run();
-            result.Item1.Subscribe(x => { });
-
-            GC.Collect();
-
-            Assert.Null(result.Item2.Target);
-        }
-
-        [Fact]
-        public void Should_Not_Keep_Source_Alive_NonIntegerIndexer()
-        {
-            Func<Tuple<ExpressionObserver, WeakReference>> run = () =>
-            {
-                var source = new { Foo = new NonIntegerIndexer() };
-                var target = new ExpressionObserver(source, "Foo");
-                return Tuple.Create(target, new WeakReference(source));
-            };
-
-            var result = run();
-            result.Item1.Subscribe(x => { });
-
-            GC.Collect();
-
-            Assert.Null(result.Item2.Target);
-        }
-
         private class NonIntegerIndexer : NotifyingBase
         {
-            private Dictionary<string, string> storage = new Dictionary<string, string>();
+            private readonly Dictionary<string, string> _storage = new Dictionary<string, string>();
 
             public string this[string key]
             {
                 get
                 {
-                    return storage[key];
+                    return _storage[key];
                 }
                 set
                 {
-                    storage[key] = value;
+                    _storage[key] = value;
                     RaisePropertyChanged(CommonPropertyNames.IndexerName);
                 }
             }