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

Conversation

willibrandon
Copy link
Contributor

@willibrandon willibrandon commented Jul 27, 2022

Fixes #4500

Proposed changes

  • Remove dependency on RemoteExecutor in tests as it has been proven to be unstable.
  • Migrate tests that change global state and that rely on RemoteExecutor to the UIIntegration test project.

Customer Impact

  • Test methods should not be skipped.

Regression?

  • No

Risk

  • Minimal

Test methodology

  • Ran unit and integration tests and observed for any signs of destabilisation.

Test environment(s)

  • 7.0.100-preview.6.22352.1
Microsoft Reviewers: Open in CodeFlow

-Allows the test to be un-skipped without destablising the test suite.
@willibrandon willibrandon requested a review from a team as a code owner July 27, 2022 07:02
@ghost ghost assigned willibrandon Jul 27, 2022
@RussKie RussKie added the test-enhancement Improvements of test source code label Jul 27, 2022
@RussKie RussKie enabled auto-merge (squash) July 27, 2022 07:30
@RussKie RussKie disabled auto-merge July 27, 2022 07:30
@willibrandon

This comment was marked as outdated.

@RussKie RussKie added the waiting-author-feedback The team requires more information from the author label Jul 29, 2022
@ghost ghost removed the waiting-author-feedback The team requires more information from the author label Jul 29, 2022
[WinFormsFact]
public unsafe void ListViewInsertionMark_AppearsAfterItem_GetInsertMark_Success()
{
Application.EnableVisualStyles();
Copy link
Member

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

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)
        {
        }

Copy link
Contributor Author

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?

@RussKie RussKie added the waiting-author-feedback The team requires more information from the author label Aug 1, 2022
@ghost ghost removed the waiting-author-feedback The team requires more information from the author label Aug 9, 2022
@RussKie RussKie added the waiting-author-feedback The team requires more information from the author label Aug 10, 2022
@ghost ghost removed the waiting-author-feedback The team requires more information from the author label Aug 18, 2022
@RussKie RussKie added the waiting-author-feedback The team requires more information from the author label Aug 24, 2022
@ghost ghost removed the waiting-author-feedback The team requires more information from the author label Aug 24, 2022
@RussKie RussKie added the waiting-author-feedback The team requires more information from the author label Sep 15, 2022
@willibrandon
Copy link
Contributor Author

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.

@ghost ghost removed the waiting-author-feedback The team requires more information from the author label Sep 15, 2022
-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.
Copy link
Member

@RussKie RussKie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Progressing nicely

{
}

[WinFormsTheory(Skip = "Deadlocks under x86, see: https://github.com/dotnet/winforms/issues/3254")]
Copy link
Member

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

Copy link
Contributor Author

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).

Copy link
Member

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].

Comment on lines 19 to 36
[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);
}
Copy link
Member

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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted above

@RussKie RussKie added the waiting-author-feedback The team requires more information from the author label Sep 16, 2022
@ghost ghost removed the waiting-author-feedback The team requires more information from the author label Sep 17, 2022
@RussKie
Copy link
Member

RussKie commented Sep 21, 2022

@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?

@willibrandon
Copy link
Contributor Author

@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.

@RussKie
Copy link
Member

RussKie commented Sep 23, 2022

Haha, all good. I do post and then delete sometimes, though generally I try to post another message instead.

@willibrandon
Copy link
Contributor Author

I have some feedback left to address on this, and working towards that now.

@RussKie RussKie added the waiting-author-feedback The team requires more information from the author label Sep 28, 2022
@ghost ghost removed the waiting-author-feedback The team requires more information from the author label Sep 29, 2022
[WinFormsFact]
public unsafe void ListViewInsertionMark_VisualStylesOff_NotAvailable()
{
Assert.False(Application.UseVisualStyles);
Copy link
Contributor Author

@willibrandon willibrandon Sep 29, 2022

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?

Copy link
Member

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.,

  1. we can condition the tests using ConditionalFact, but it won't work for STA-bound tests, and we'll have to exend WinFormsFact (and WinFormsTheory) to be conditional. This likely require an update the Xunit.StaFact library, as some infra is private and doesn't allow an easy overriding.
  2. 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>
    #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);
       }
    We'd also need to wrap all callsites with:
    #if VISUAL_STYLES_ON
            Application.EnableVisualStyles();
    #endif
    Running from a command line we'd need to add /p:TestVisualStylesOn=false to run without the visual styles.
  3. 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).
  4. 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
        }
    }

Copy link
Member

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.

@JeremyKuhne JeremyKuhne added the draft draft PR label Oct 4, 2023
@merriemcgaw
Copy link
Member

@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.

@willibrandon
Copy link
Contributor Author

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.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
draft draft PR test-enhancement Improvements of test source code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove dependency on RemoteExecutor in tests
4 participants