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

Remove dependency on RemoteExecutor in tests #7500

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Xunit;
using Xunit.Abstractions;

namespace System.Windows.Forms.UITests
{
public class ParkingWindowTests : ControlTestBase
{
public ParkingWindowTests(ITestOutputHelper testOutputHelper)
: base(testOutputHelper)
{
}

[WinFormsFact]
public void ParkingWindow_DoesNotThrowOnGarbageCollecting()
{
Control.CheckForIllegalCrossThreadCalls = true;

Form form = InitFormWithControlToGarbageCollect();
willibrandon marked this conversation as resolved.
Show resolved Hide resolved

try
{
// Force garbage collecting to access combobox from another (GC) thread.
GC.Collect();

GC.WaitForPendingFinalizers();
}
catch (Exception ex)
{
Assert.True(ex is null, $"Expected no exception, but got: {ex?.Message}"); // Actually need to check whether GC.Collect() does not throw exception.
}
}

private Form InitFormWithControlToGarbageCollect()
{
Form form = new Form();
ComboBox? comboBox = new ComboBox
{
DropDownStyle = ComboBoxStyle.DropDown
};

form.Controls.Add(comboBox);
form.Show();

// Park combobox handle in ParkingWindow.
comboBox.Parent = null;

// Recreate combobox handle to set parent to ParkingWindow.
comboBox.DropDownStyle = ComboBoxStyle.DropDownList;

// Lose the reference to combobox to allow Garbage collecting combobox.
willibrandon marked this conversation as resolved.
Show resolved Hide resolved
comboBox = null;

return form;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.

using System.Runtime.InteropServices;
using Microsoft.DotNet.RemoteExecutor;
using Xunit;
using static System.Windows.Forms.Application;
using static Interop;
Expand All @@ -12,53 +11,6 @@ namespace System.Windows.Forms.Tests
{
public class ParkingWindowTests
{
[WinFormsFact(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")]
public void ParkingWindow_DoesNotThrowOnGarbageCollecting()
{
using RemoteInvokeHandle invokerHandle = RemoteExecutor.Invoke(() =>
{
Control.CheckForIllegalCrossThreadCalls = true;

Form form = InitFormWithControlToGarbageCollect();

try
{
// Force garbage collecting to access combobox from another (GC) thread.
GC.Collect();

GC.WaitForPendingFinalizers();
}
catch (Exception ex)
{
Assert.True(ex is null, "Expected no exception, but got: " + ex.Message); // Actually need to check whether GC.Collect() does not throw exception.
}
});

// verify the remote process succeeded
Assert.Equal(RemoteExecutor.SuccessExitCode, invokerHandle.ExitCode);
}

private Form InitFormWithControlToGarbageCollect()
{
Form form = new Form();
ComboBox comboBox = new ComboBox();
comboBox.DropDownStyle = ComboBoxStyle.DropDown;

form.Controls.Add(comboBox);
form.Show();

// Park combobox handle in ParkingWindow.
comboBox.Parent = null;

// Recreate combobox handle to set parent to ParkingWindow.
comboBox.DropDownStyle = ComboBoxStyle.DropDownList;

// Lose the reference to combobox to allow Garbage collecting combobox.
comboBox = null;

return form;
}

[WinFormsFact]
public void ParkingWindow_Unaware()
{
Expand Down