diff --git a/.travis.yml b/.travis.yml index 69bbab471b..7b5af500cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,12 +14,7 @@ install: - mono .nuget/nuget.exe install xunit.runner.console -Version 2.1.0 -OutputDirectory testrunner script: - xbuild /p:Configuration=Release Avalonia.travis-mono.sln - - mono ./testrunner/xunit.runner.console.2.1.0/tools/xunit.console.exe ./tests/Avalonia.Base.UnitTests/bin/Release/Avalonia.Base.UnitTests.dll - - mono ./testrunner/xunit.runner.console.2.1.0/tools/xunit.console.exe ./tests/Avalonia.Input.UnitTests/bin/Release/Avalonia.Input.UnitTests.dll - - mono ./testrunner/xunit.runner.console.2.1.0/tools/xunit.console.exe ./tests/Avalonia.Interactivity.UnitTests/bin/Release/Avalonia.Interactivity.UnitTests.dll - - mono ./testrunner/xunit.runner.console.2.1.0/tools/xunit.console.exe ./tests/Avalonia.Layout.UnitTests/bin/Release/Avalonia.Layout.UnitTests.dll - - mono ./testrunner/xunit.runner.console.2.1.0/tools/xunit.console.exe ./tests/Avalonia.Markup.UnitTests/bin/Release/Avalonia.Markup.UnitTests.dll - - mono ./testrunner/xunit.runner.console.2.1.0/tools/xunit.console.exe ./tests/Avalonia.Styling.UnitTests/bin/Release/Avalonia.Styling.UnitTests.dll + - ./tests/run-tests.sh notifications: email: false webhooks: diff --git a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Direct.cs b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Direct.cs index 12d1b7a5f0..1d8bb80cba 100644 --- a/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Direct.cs +++ b/tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Direct.cs @@ -335,44 +335,6 @@ namespace Avalonia.Base.UnitTests Assert.Equal("second", target.Foo); } - [Fact] - public void Binding_To_Direct_Property_Does_Not_Get_Collected() - { - var target = new Class2(); - - Func setupBinding = () => - { - var source = new Subject(); - var sub = target.Bind((AvaloniaProperty)Class1.FooProperty, source); - source.OnNext("foo"); - return new WeakReference(source); - }; - - var weakSource = setupBinding(); - - GC.Collect(); - - Assert.Equal("foo", target.Foo); - Assert.True(weakSource.IsAlive); - } - - [Fact] - public void Binding_To_Direct_Property_Gets_Collected_When_Completed() - { - var target = new Class2(); - var weakSource = SetupDirectBinding(target); - - Action completeSource = () => - { - ((ISubject)weakSource.Target).OnCompleted(); - }; - - completeSource(); - GC.Collect(); - - Assert.False(weakSource.IsAlive); - } - [Fact] public void Property_Notifies_Initialized() { @@ -447,13 +409,6 @@ namespace Avalonia.Base.UnitTests Assert.True(called); } - private WeakReference SetupDirectBinding(Class2 target) - { - var source = new Subject(); - var sub = target.Bind((AvaloniaProperty)Class1.FooProperty, source); - return new WeakReference(source); - } - private class Class1 : AvaloniaObject { public static readonly DirectProperty FooProperty = diff --git a/tests/Avalonia.LeakTests/Avalonia.LeakTests.csproj b/tests/Avalonia.LeakTests/Avalonia.LeakTests.csproj index 860a4074e3..0e45e0fcdd 100644 --- a/tests/Avalonia.LeakTests/Avalonia.LeakTests.csproj +++ b/tests/Avalonia.LeakTests/Avalonia.LeakTests.csproj @@ -59,12 +59,25 @@ ..\..\packages\System.Reactive.Interfaces.3.0.0\lib\net45\System.Reactive.Interfaces.dll True + + ..\..\packages\System.Reactive.Linq.3.0.0\lib\net45\System.Reactive.Linq.dll + True + + + ..\..\packages\System.Reactive.PlatformServices.3.0.0\lib\net45\System.Reactive.PlatformServices.dll + True + + + ..\..\packages\System.Reactive.Windows.Threading.3.0.0\lib\net45\System.Reactive.Windows.Threading.dll + True + + ..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll True @@ -83,6 +96,7 @@ + diff --git a/tests/Avalonia.LeakTests/AvaloniaObjectTests.cs b/tests/Avalonia.LeakTests/AvaloniaObjectTests.cs new file mode 100644 index 0000000000..8410c2aa3e --- /dev/null +++ b/tests/Avalonia.LeakTests/AvaloniaObjectTests.cs @@ -0,0 +1,84 @@ +using System; +using System.Reactive.Subjects; +using JetBrains.dotMemoryUnit; +using Xunit; +using Xunit.Abstractions; + +namespace Avalonia.LeakTests +{ + public class AvaloniaObjectTests + { + public AvaloniaObjectTests(ITestOutputHelper atr) + { + DotMemoryUnitTestOutput.SetOutputMethod(atr.WriteLine); + } + + [Fact] + public void Binding_To_Direct_Property_Does_Not_Get_Collected() + { + var target = new Class1(); + + Func setupBinding = () => + { + var source = new Subject(); + var sub = target.Bind((AvaloniaProperty)Class1.FooProperty, source); + source.OnNext("foo"); + return new WeakReference(source); + }; + + var weakSource = setupBinding(); + + GC.Collect(); + + Assert.Equal("foo", target.Foo); + Assert.True(weakSource.IsAlive); + } + + [Fact] + public void Binding_To_Direct_Property_Gets_Collected_When_Completed() + { + var target = new Class1(); + + Func setupBinding = () => + { + var source = new Subject(); + var sub = target.Bind((AvaloniaProperty)Class1.FooProperty, source); + return new WeakReference(source); + }; + + var weakSource = setupBinding(); + + Action completeSource = () => + { + ((ISubject)weakSource.Target).OnCompleted(); + }; + + completeSource(); + GC.Collect(); + + Assert.False(weakSource.IsAlive); + } + + private class Class1 : AvaloniaObject + { + public static readonly DirectProperty FooProperty = + AvaloniaProperty.RegisterDirect( + "Foo", + o => o.Foo, + (o, v) => o.Foo = v, + unsetValue: "unset"); + + private string _foo = "initial2"; + + static Class1() + { + } + + public string Foo + { + get { return _foo; } + set { SetAndRaise(FooProperty, ref _foo, value); } + } + } + } +} diff --git a/tests/Avalonia.LeakTests/Properties/AssemblyInfo.cs b/tests/Avalonia.LeakTests/Properties/AssemblyInfo.cs index 10149cf0af..4b66452274 100644 --- a/tests/Avalonia.LeakTests/Properties/AssemblyInfo.cs +++ b/tests/Avalonia.LeakTests/Properties/AssemblyInfo.cs @@ -1,6 +1,7 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using Xunit; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information @@ -34,3 +35,6 @@ using System.Runtime.InteropServices; // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] + +// Don't run tests in parallel. +[assembly: CollectionBehavior(DisableTestParallelization = true)] \ No newline at end of file diff --git a/tests/Avalonia.LeakTests/packages.config b/tests/Avalonia.LeakTests/packages.config index 939556d0e2..302ccfb214 100644 --- a/tests/Avalonia.LeakTests/packages.config +++ b/tests/Avalonia.LeakTests/packages.config @@ -4,8 +4,12 @@ + + + + diff --git a/tests/run-tests.sh b/tests/run-tests.sh new file mode 100755 index 0000000000..03e8c61137 --- /dev/null +++ b/tests/run-tests.sh @@ -0,0 +1,20 @@ +# !/bin/bash + +cd "$(dirname "$0")" + +tests=(Avalonia.*.UnitTests/) +exclude=("*Direct2D*/") +result=0 + +for del in ${exclude[@]}; do + tests=(${tests[@]/$del}) +done + +for test in ${tests[@]}; do + echo Running test $test + mono ../testrunner/xunit.runner.console.2.1.0/tools/xunit.console.exe ${test}bin/Release/${test%/}.dll -parallel none + + if [ $? -ne 0 ]; then result=1 ; fi +done + +exit $result