-
Notifications
You must be signed in to change notification settings - Fork 997
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
Remove dependency on RemoteExecutor in tests #7500
Conversation
-Allows the test to be un-skipped without destablising the test suite.
...em.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/Application.ParkingWindowTests.cs
Outdated
Show resolved
Hide resolved
This comment was marked as outdated.
This comment was marked as outdated.
src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ApplicationTests.cs
Show resolved
Hide resolved
[WinFormsFact] | ||
public unsafe void ListViewInsertionMark_AppearsAfterItem_GetInsertMark_Success() | ||
{ | ||
Application.EnableVisualStyles(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Visual styles are enabled at the base level
winforms/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/Infra/ControlTestBase.cs
Lines 23 to 27 in c290164
protected ControlTestBase(ITestOutputHelper testOutputHelper) | |
{ | |
TestOutputHelper = testOutputHelper; | |
Application.EnableVisualStyles(); |
For intents and purposes of the tests we're porting in this PR, we'd likely want to be able to toggle visual styles. Perhaps you could do something like this:
[UseDefaultXunitCulture]
public abstract class ControlTestBase : IAsyncLifetime, IDisposable
{
protected ControlTestBase(ITestOutputHelper testOutputHelper, bool enableVisualStyles)
{
if (enableVisualStyles)
{
Application.EnableVisualStyles();
}
}
protected ControlTestBase(ITestOutputHelper testOutputHelper)
: this(testOutputHelper, enableVisualStyles: true)
{
}
public class ListViewInsertionMarkVisualStylesOnTests : ControlTestBase
{
public ListViewInsertionMarkTests(ITestOutputHelper testOutputHelper)
: base(testOutputHelper, enableVisualStyles: true)
{
}
public class ListViewInsertionMarkVisualStylesOffTests : ControlTestBase
{
public ListViewInsertionMarkTests(ITestOutputHelper testOutputHelper)
: base(testOutputHelper: enableVisualStyles: false)
{
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've provided a way for the tests to toggle visual styles like you suggested but for this particular test, does it make sense to test with visual styles off?
src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/CommonDialogTests.cs
Show resolved
Hide resolved
...ests/IntegrationTests/UIIntegrationTests/ListViewGroup.ListViewGroupAccessibleObjectTests.cs
Show resolved
Hide resolved
src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/ListViewTests.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/TaskDialogTests.cs
Show resolved
Hide resolved
No. I've been adjusting to a new schedule, pardon me. I'm close to having the changes ready and will make it a priority now. |
-These tests pass on my local command line but fail in VS. -Need to get clarification on the purpose of toggling the visual styles for the these tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Progressing nicely
src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/TabPageTests.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/TabPageTests.cs
Outdated
Show resolved
Hide resolved
...ystem.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/ProfessionalColorTableTests.cs
Outdated
Show resolved
Hide resolved
{ | ||
} | ||
|
||
[WinFormsTheory(Skip = "Deadlocks under x86, see: https://github.com/dotnet/winforms/issues/3254")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 May interesting to see if this is still an issue with this move
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I un-skip the test and change [WinformsTheory]
to [Theory]
, the test executes and passes successfully. If I leave it as [WinformsTheory]
, the test hangs on SystemEventsHelper.SendMessageOnUserPreferenceChanged(category)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for testing. At a glance it doesn't look like there's anything that requires an affinitisation to the UI thread, so I think it'd be safe to go with [Theory]
.
src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewTests.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/CommonDialogTests.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/CommonDialogTests.cs
Outdated
Show resolved
Hide resolved
...em.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/Application.ParkingWindowTests.cs
Outdated
Show resolved
Hide resolved
[WinFormsFact] | ||
public void Application_EnableVisualStyles_InvokeBeforeGettingRenderWithVisualStyles_Success() | ||
{ | ||
Application.EnableVisualStyles(); | ||
Assert.True(Application.UseVisualStyles); | ||
Assert.True(Application.RenderWithVisualStyles); | ||
} | ||
|
||
[WinFormsFact] | ||
public void Application_EnableVisualStyles_InvokeAfterGettingRenderWithVisualStyles_Success() | ||
{ | ||
Assert.True(Application.UseVisualStyles); | ||
Assert.True(Application.RenderWithVisualStyles); | ||
|
||
Application.EnableVisualStyles(); | ||
Assert.True(Application.UseVisualStyles, "New Visual Styles will not be applied on Winforms app. This is a high priority bug and must be looked into"); | ||
Assert.True(Application.RenderWithVisualStyles); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to run with visual styles on and off, e.g. similar to what you've defined in ListViewInsertionMarkVisualStylesOnTests and ListViewInsertionMarkVisualStylesOffTests.
DataGridViewCellMouseEventArgs e = (DataGridViewCellMouseEventArgs)testData[1]; | ||
bool expected = (bool)testData[2]; | ||
|
||
Application.EnableVisualStyles(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted above
@willibrandon I got a notification of a comment but I can't seem to locate it, sorry.... It looks like we have a lot of ongoing discussions, and I find it hard to keep track of all of them. Do you think you could rebase and address any remaining pending comments? |
@RussKie - Someone should take the delete button away from me. Sometimes I'm second guessing myself so much that it is too tempting not to click it. With that said, I have been made acutely aware of how confusing this can be and that I should treat this like email. I will do my best to never click the delete button ever again. |
Haha, all good. I do post and then delete sometimes, though generally I try to post another message instead. |
I have some feedback left to address on this, and working towards that now. |
[WinFormsFact] | ||
public unsafe void ListViewInsertionMark_VisualStylesOff_NotAvailable() | ||
{ | ||
Assert.False(Application.UseVisualStyles); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could use some help understanding why Application.UseVisualStyles
is true here even though we pass a value of false
for enableVisualStyles
to the ControlTestBase
base constructor. It seems the toggling of visual styles might be problematic since this test seems to be affected by other UITests
enabling visual styles.
Did I miss something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gah... In short, it looks like I underappreciated how the tests from this project are executed. All tests from this project are run in a single process, and, because some tests do enable the visual styles, depending on the order of execution tests (that expect the state of visual styles on or off) will fail. If you run this test in isolation it will succeed.
There are multiple ways to resolve this, and after spending several hours exploring some of them, none appears particlualry painless.
E.g.,
- we can condition the tests using
ConditionalFact
, but it won't work for STA-bound tests, and we'll have to exendWinFormsFact
(andWinFormsTheory
) to be conditional. This likely require an update the Xunit.StaFact library, as some infra is private and doesn't allow an easy overriding. - We can pepper the code with something like the following:
<PropertyGroup Condition="'$(TestVisualStylesOn)' == ''"> <TestVisualStylesOn>true</TestVisualStylesOn> </PropertyGroup> <PropertyGroup Condition="'$(TestVisualStylesOn)' == 'true'"> <DefineConstants>$(DefineConstants);VISUAL_STYLES_ON</DefineConstants> </PropertyGroup>
We'd also need to wrap all callsites with:#if VISUAL_STYLES_ON [WinFormsFact(Skip = "Not supported with Visual Styles enabled")] #else [WinFormsFact] #endif [WinFormsFact] [VisualStylesEnabled(false)] public void Application_VisualStylesOn_must_not_be_enabled() { Assert.False(Application.UseVisualStyles, "Tests in this configuration must not have VisualStyles enabled."); Assert.False(Application.RenderWithVisualStyles); }
Running from a command line we'd need to add#if VISUAL_STYLES_ON Application.EnableVisualStyles(); #endif
/p:TestVisualStylesOn=false
to run without the visual styles. - We can add traits, and decorate test classes and/or specific tests with traits. This would require finding a way how to pass
-trait VisualStylesEnabled=false
(example) to the test runner (which is part of microsoft.dotnet.arcade.sdk). - We can try to update to Xuni v3, which has
Skip
functionality - Need ability to skip test programmatically xunit/xunit#2073 (comment)
I also tried this, but it didn't appear to work - instead of skipping the test it would still fail it:
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class SkipIfVisualStylesAttribute : BeforeAfterTestAttribute
{
public bool Enable { get; set; }
public override unsafe void Before(MethodInfo methodUnderTest)
{
#if VISUAL_STYLES_ON
if (Enable)
throw new SkipException("Not supported with Visual Styles disabled");
#else
if (!Enable)
throw new SkipException("Not supported with Visual Styles enabled");
#endif
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So as a quick get out of jail card - we can wrap all tests that expect visual styles to be off with
#if VISUAL_STYLES_OFF
// tests
#endif
...and then we can finish this work at a later date.
@willibrandon sorry this fell through the cracks! I'm closing this now but if you're willing to pick it back up just holler and we can re-open it for you. |
My apologies. Sometimes I bite off more than I can chew 😩. These tests can be very finicky, and time-consuming. With that said, I don't want to give up on this, especially if #4500 is still an issue. I just might not be the best person to tackle this one yet. I'll see if I can get back to it, and if so, I will holler. |
Fixes #4500
Proposed changes
RemoteExecutor
in tests as it has been proven to be unstable.RemoteExecutor
to the UIIntegration test project.Customer Impact
Regression?
Risk
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow