Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable tests #24912

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@
</PropertyGroup>
<PropertyGroup>
<MicrosoftNETTestSdkPackageVersion>17.6.0</MicrosoftNETTestSdkPackageVersion>
<XunitPackageVersion>2.6.6</XunitPackageVersion>
<XunitRunnerVisualStudioPackageVersion>2.8.0</XunitRunnerVisualStudioPackageVersion>
<XunitExtensibilityExecutionPackageVersion>2.6.6</XunitExtensibilityExecutionPackageVersion>
<XunitAssertPackageVersion>2.6.6</XunitAssertPackageVersion>
<XUnitAnalyzersPackageVersion>1.13.0</XUnitAnalyzersPackageVersion>
<XunitPackageVersion>2.9.0</XunitPackageVersion>
<XunitRunnerVisualStudioPackageVersion>2.8.2</XunitRunnerVisualStudioPackageVersion>
<XunitExtensibilityExecutionPackageVersion>2.9.0</XunitExtensibilityExecutionPackageVersion>
<XunitAssertPackageVersion>2.9.0</XunitAssertPackageVersion>
<XUnitAnalyzersPackageVersion>1.15.0</XUnitAnalyzersPackageVersion>
<XunitAbstractionsPackageVersion>2.0.3</XunitAbstractionsPackageVersion>
<NSubstitutePackageVersion>5.1.0</NSubstitutePackageVersion>
<CoverletCollectorPackageVersion>6.0.0</CoverletCollectorPackageVersion>
Expand Down
42 changes: 21 additions & 21 deletions src/Controls/tests/Core.UnitTests/NavigationPageLifecycleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,33 +126,33 @@ public async Task RemoveLastPage(bool useMaui)
Assert.Equal(1, pushedPage.DisappearingCount);
}

// [Theory]
// [InlineData(false)]
// [InlineData(true)]
// public async Task RemoveInnerPage(bool useMaui)
// {
// ContentPage initialPage = new ContentPage();
// ContentPage pushedPage = new ContentPage();
[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task RemoveInnerPage(bool useMaui)
{
ContentPage initialPage = new ContentPage();
ContentPage pushedPage = new ContentPage();

// ContentPage initialPageAppearing = null;
// ContentPage pageDisappeared = null;
ContentPage initialPageAppearing = null;
ContentPage pageDisappeared = null;

// NavigationPage nav = new TestNavigationPage(useMaui, initialPage);
// _ = new Window(nav);
// nav.SendAppearing();
NavigationPage nav = new TestNavigationPage(useMaui, initialPage);
_ = new Window(nav);
nav.SendAppearing();

// var pageToRemove = new ContentPage();
// await nav.PushAsync(pageToRemove);
// await nav.PushAsync(pushedPage);
var pageToRemove = new ContentPage();
await nav.PushAsync(pageToRemove);
await nav.PushAsync(pushedPage);


// initialPage.Appearing += (__, _)
// => throw new XunitException("Appearing Fired Incorrectly");
initialPage.Appearing += (__, _)
=> throw new XunitException("Appearing Fired Incorrectly");

// pushedPage.Disappearing += (__, _)
// => throw new XunitException("Appearing Fired Incorrectly");
pushedPage.Disappearing += (__, _)
=> throw new XunitException("Appearing Fired Incorrectly");

// nav.Navigation.RemovePage(pageToRemove);
// }
nav.Navigation.RemovePage(pageToRemove);
}
}
}
38 changes: 19 additions & 19 deletions src/Controls/tests/Core.UnitTests/ShellNavigatingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,25 +534,25 @@ public async Task ShellItemContentRouteWithGlobalRouteRelative(bool modal, int d
Assert.Equal("//animals/monkeys/details", shell.CurrentState.Location.ToString());
}

//[Theory]
//[InlineData(true)]
//[InlineData(false)]
//public async Task GotoSameGlobalRoutesCollapsesUriCorrectly(bool modal)
//{
// var shell = new Shell();
// var item1 = CreateShellItem<FlyoutItem>(asImplicit: true, shellItemRoute: "animals", shellContentRoute: "monkeys");

// if (modal)
// Routing.RegisterRoute("details", typeof(ShellModalTests.ModalTestPage));
// else
// Routing.RegisterRoute("details", typeof(ContentPage));

// shell.Items.Add(item1);

// await shell.GoToAsync("details");
// await shell.GoToAsync("details");
// Assert.Equal("//animals/monkeys/details/details", shell.CurrentState.Location.ToString());
//}
[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task GotoSameGlobalRoutesCollapsesUriCorrectly(bool modal)
{
var shell = new Shell();
var item1 = CreateShellItem<FlyoutItem>(asImplicit: true, shellItemRoute: "animals", shellContentRoute: "monkeys");

if (modal)
Routing.RegisterRoute("details", typeof(ShellModalTests.ModalTestPage));
else
Routing.RegisterRoute("details", typeof(ContentPage));

shell.Items.Add(item1);

await shell.GoToAsync("details");
await shell.GoToAsync("details");
Assert.Equal("//animals/monkeys/details/details", shell.CurrentState.Location.ToString());
}

[Fact]
public async Task ShellSectionWithGlobalRouteAbsolute()
Expand Down
13 changes: 13 additions & 0 deletions src/Controls/tests/Core.UnitTests/TestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,18 @@ public static async Task Collect()
GC.Collect();
GC.WaitForPendingFinalizers();
}


public static async Task<bool> WaitForCollect(this WeakReference reference)
{
for (int i = 0; i < 40 && reference.IsAlive; i++)
{
await Task.Yield();
GC.Collect();
GC.WaitForPendingFinalizers();
}

return reference.IsAlive;
}
}
}
8 changes: 2 additions & 6 deletions src/Controls/tests/Core.UnitTests/VisualElementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,8 @@ public async Task ClipDoesNotLeak(Type type)
{
var geometry = (Geometry)Activator.CreateInstance(type);
var reference = new WeakReference(new VisualElement { Clip = geometry });

await Task.Yield();
GC.Collect();
GC.WaitForPendingFinalizers();

Assert.False(reference.IsAlive, "VisualElement should not be alive!");

Assert.False(await reference.WaitForCollect(), "VisualElement should not be alive!");
}

[Fact]
Expand Down
20 changes: 20 additions & 0 deletions src/Core/tests/UnitTests/TestHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Threading.Tasks;

namespace Microsoft.Maui.UnitTests
{
internal static class TestHelpers
{
public static async Task<bool> WaitForCollect(this WeakReference reference)
{
for (int i = 0; i < 40 && reference.IsAlive; i++)
{
await Task.Yield();
GC.Collect();
GC.WaitForPendingFinalizers();
}

return reference.IsAlive;
}
}
}
6 changes: 1 addition & 5 deletions src/Core/tests/UnitTests/Views/BorderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ public async Task BorderStrokeShapeDoesNotLeak(Type type)

strokeShape = null;

await Task.Yield();
GC.Collect();
GC.WaitForPendingFinalizers();

Assert.False(reference.IsAlive, "Border should not be alive!");
Assert.False(await reference.WaitForCollect(), "Border should not be alive!");
}

[Fact]
Expand Down
12 changes: 2 additions & 10 deletions src/Core/tests/UnitTests/Views/ShapeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ public async Task ShapeFillDoesNotLeak()
var fill = new SolidColorBrush(Colors.Red);
var reference = new WeakReference(new Rectangle { Fill = fill });

await Task.Yield();
GC.Collect();
GC.WaitForPendingFinalizers();

Assert.False(reference.IsAlive, "Shape should not be alive!");
Assert.False(await reference.WaitForCollect(), "Shape should not be alive!");
}

[Fact]
Expand Down Expand Up @@ -75,11 +71,7 @@ public async Task ShapeStrokeDoesNotLeak()
var stroke = new SolidColorBrush(Colors.Red);
var reference = new WeakReference(new Rectangle { Stroke = stroke });

await Task.Yield();
GC.Collect();
GC.WaitForPendingFinalizers();

Assert.False(reference.IsAlive, "Shape should not be alive!");
Assert.False(await reference.WaitForCollect(), "Shape should not be alive!");
}
}
}
34 changes: 19 additions & 15 deletions src/Core/tests/UnitTests/WeakListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ public class WeakListTests
public async Task ObjectsAreEvicted_GetEnumerator()
{
var expected = new object();
var list = new WeakList<object> { expected, new object() };
var evict = new object();
WeakReference weakReference = new WeakReference(evict);
var list = new WeakList<object> { expected, evict };
evict = null;
list.CleanupThreshold = 1;

await Task.Yield();
GC.Collect();
GC.WaitForPendingFinalizers();

Assert.False(await weakReference.WaitForCollect(), "Object failed to be collected");

foreach (var item in list)
{
Expand All @@ -31,12 +32,13 @@ public async Task ObjectsAreEvicted_GetEnumerator()
public async Task ObjectsAreEvicted_Remove()
{
var expected = new object();
var list = new WeakList<object> { expected, new object() };
var evict = new object();
WeakReference weakReference = new WeakReference(evict);
var list = new WeakList<object> { expected, evict };
evict = null;
list.CleanupThreshold = 1;

await Task.Yield();
GC.Collect();
GC.WaitForPendingFinalizers();
Assert.False(await weakReference.WaitForCollect(), "Object failed to be collected");

list.Remove(expected);

Expand All @@ -47,14 +49,16 @@ public async Task ObjectsAreEvicted_Remove()
public async Task ObjectsAreEvicted_Add()
{
var expected = new object();
var list = new WeakList<object> { expected, new object() };
var evict = new object();
WeakReference weakReference = new WeakReference(evict);
var list = new WeakList<object> { expected, evict };
evict = null;
list.CleanupThreshold = 1;

Assert.False(await weakReference.WaitForCollect(), "Object failed to be collected");

await Task.Yield();
GC.Collect();
GC.WaitForPendingFinalizers();

list.Add(new object());
var triggerCleanup = new object();
list.Add(triggerCleanup);

Assert.Equal(2, list.Count);
Assert.Equal(expected, list.First());
Expand Down
Loading