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

Flaky Clipboard Unit Tests #3456

Closed
Tracked by #8607
weltkante opened this issue Jun 16, 2020 · 10 comments
Closed
Tracked by #8607

Flaky Clipboard Unit Tests #3456

weltkante opened this issue Jun 16, 2020 · 10 comments
Assignees
Labels
area-Clipboard Issues related to Clipboard test-bug Problem in test source code (most likely) test-enhancement Improvements of test source code
Milestone

Comments

@weltkante
Copy link
Contributor

weltkante commented Jun 16, 2020

.NET Core Version:
master

Have you experienced this same bug with .NET Framework?:
no

Problem description:
Noticed as a flaky test:

System.Windows.Forms.Tests.TextBoxBaseTests.TextBoxBase_Paste_InvokeNotEmpty_Success [FAIL]
Assert.Equal() Failure
� (pos 1)
Expected: abc
Actual: a
� (pos 1)
Stack Trace:
F:\workspace_work\1\s\src\System.Windows.Forms\tests\UnitTests\TextBoxBaseTests.cs(5957,0): at System.Windows.Forms.Tests.TextBoxBaseTests.TextBoxBase_Paste_InvokeNotEmpty_Success()

Test seems to assume clipboard is empty/nonfunctional (there is at least one more test along these, should review for more clipboard-dependent tests)

Also any clipboard tests need to be [Collection("Sequential")] to avoid overlapping with other clipboard tests. Is it worth making the whole test class sequential just due to that single test? should the test be moved?

Expected behavior:
Clipboard based tests initialize clipboard to be in known state and are marked for sequential execution

Minimal repro:
none, flaky test

@RussKie
Copy link
Member

RussKie commented Jun 17, 2020

I wonder if we could employ Trait decorations, e.g. something like:

        [Trait(Category.Synchronous, Category.Clipboard)] // arbitrary strings represented by consts
        [WinFormsFact]
        public void TextBoxBase_Paste_InvokeNotEmpty_Success()
        {
            // ...
        }

...and then update our CI configs to run tests separately:

winforms/eng/ci.yml

Lines 98 to 107 in 0f90af4

# Run Unit Tests
# Tests are run with /m:1 to work around https://github.com/tonerdo/coverlet/issues/364
- script: eng\cibuild.cmd
-test
-configuration $(_BuildConfig)
$(_OfficialBuildIdArgs)
/p:Coverage=$(_Coverage)
/bl:$(BUILD.SOURCESDIRECTORY)\artifacts\log\$(_BuildConfig)\Test.binlog
/m:1
displayName: Run Unit Tests

        # Run Unit Tests
        # Tests are run with /m:1 to work around https://github.com/tonerdo/coverlet/issues/364
        - script: eng\cibuild.cmd
            -test
            -configuration $(_BuildConfig)
            $(_OfficialBuildIdArgs)
            /p:Coverage=$(_Coverage)
            /bl:$(BUILD.SOURCESDIRECTORY)\artifacts\log\$(_BuildConfig)\Test.binlog
            /m:1
           -trait "Synchronous=Clipboard"
          displayName: Run Unit Tests (Synchronous)

        - script: eng\cibuild.cmd
            -test
            -configuration $(_BuildConfig)
            $(_OfficialBuildIdArgs)
            /p:Coverage=$(_Coverage)
            /bl:$(BUILD.SOURCESDIRECTORY)\artifacts\log\$(_BuildConfig)\Test.binlog
            /m:1
           -notrait "Synchronous=Clipboard"
          displayName: Run Unit Tests

Got some inspiration from http://www.brendanconnolly.net/organizing-tests-with-xunit-traits/

@RussKie RussKie added area-Infrastructure test-bug Problem in test source code (most likely) test-enhancement Improvements of test source code labels Jun 17, 2020
@weltkante
Copy link
Contributor Author

weltkante commented Jun 19, 2020

Failed test Clipboard_SetText_InvokeStringTextDataFormat_GetReturnsExpected in CI run of PR #3473:

Assert.Equal() Failure\r\n ↓ (pos 0)\r\nExpected: text\r\nActual: \r\n ↑ (pos 0)

Since clipboard tests are not [Collection("Sequential")] its possible another test (from a different class) cleared the clipboard and interfered with this test.

@weltkante
Copy link
Contributor Author

Failed test TextBoxBase_Paste_InvokeNotEmpty_Success in CI run of PR #3511

@RussKie RussKie self-assigned this Jul 9, 2020
@RussKie
Copy link
Member

RussKie commented Jul 9, 2020

FYI I started looking into adding traits

@RussKie RussKie added this to the 6.0 milestone Sep 4, 2020
@JeremyKuhne
Copy link
Member

JeremyKuhne commented Sep 24, 2020

Failed again:

TextBoxBase_Paste_InvokeNotEmpty_Success
Assert.Equal() Failure\r\n           ↓ (pos 1)\r\nExpected: abc\r\nActual:   a\r\n           ↑ (pos 1)
 at System.Windows.Forms.Tests.TextBoxBaseTests.TextBoxBase_Paste_InvokeNotEmpty_Success() in /_/src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.cs:line 5957

@RussKie
Copy link
Member

RussKie commented Apr 7, 2022

@RussKie RussKie added the area-Clipboard Issues related to Clipboard label May 5, 2022
@RussKie
Copy link
Member

RussKie commented May 5, 2022

Related to #6269

@merriemcgaw merriemcgaw modified the milestones: .NET 7.0, .NET 8.0 Aug 11, 2022
@ghost ghost added 🚧 work in progress Work that is current in progress and removed 🚧 work in progress Work that is current in progress labels Mar 14, 2023
@JeremyKuhne
Copy link
Member

This is a matter of making sure everything that might touch the clipboard is in a non-parallelized collection and ensuring that everything has sufficient retries. I've had some success in the clipboard tests in my thirtytwo project with them running stably. See: https://github.com/JeremyKuhne/thirtytwo/blob/main/src/thirtytwo_tests/ClipboardTestCollection.cs

@Tanya-Solyanik
Copy link
Member

@LeafShi1 - you already fixed this in #11606, right?

@LeafShi1
Copy link
Member

TextBoxBase_Paste_InvokeNotEmpty_Success

Yes

@github-actions github-actions bot locked and limited conversation to collaborators Aug 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Clipboard Issues related to Clipboard test-bug Problem in test source code (most likely) test-enhancement Improvements of test source code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants