Skip to content

Conversation

Copy link

Copilot AI commented Nov 26, 2025

Fixes #589

Fixes the intermittent test failures in RichSuggestBox tests by replacing Task.Delay(10) with CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync() to properly wait for UI updates to complete.

PR Type

  • Bugfix

What is the current behavior?

Test_RichSuggestBox_DeleteTokens, Test_RichSuggestBox_AddTokens, and other RichSuggestBox tests intermittently fail on WinUI 3 due to race conditions. The tests use await Task.Delay(10) to wait for UI updates, which isn't always sufficient for the WinUI 3 RichTextBox to complete its text changes and fire events.

What is the new behavior?

All Task.Delay(10) calls in RichSuggestBox tests have been replaced with CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { }), which properly waits for the composition rendering pass to complete before assertions run.

// Before
await Task.Delay(10);   // Wait for SelectionChanged to be invoked

// After  
await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { });   // Wait for SelectionChanged to be invoked

Analysis: The intermittent failures appear to be caused by differences in the WinUI 3 platform's text control event timing compared to WinUI 2. The CompositionTargetHelper approach is already used in other tests across the toolkit (e.g., SwitchPresenterTests, ConstrainedBox, TokenizingTextBox) and provides a more reliable synchronization mechanism.

PR Checklist

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • Tested code with current supported SDKs
  • Contains NO breaking changes

Other information

Replaced 9 occurrences of Task.Delay(10) across all RichSuggestBox tests:

  • 2 in Test_RichSuggestBox_DeleteTokens
  • 1 in Test_RichSuggestBox_ReplaceToken
  • 3 in Test_RichSuggestBox_FormatReset
  • 1 in Test_RichSuggestBox_Load
  • 2 in the helper method AddTokenAsync (used by multiple tests)
Original prompt

The test Test_RichSuggestBox_DeleteTokens in components/RichSuggestBox/tests/Test_RichSuggestBox.cs is intermittently failing, particularly on WinUI 3, as discussed in issue #589. To stabilize CI and allow further investigation into the underlying cause, add the [Ignore("Intermittent failure - see https://github.com/CommunityToolkit/Windows/issues/589")] attribute to this test. Ensure only this specific test is disabled, and reference the issue in the changes.

Summary:

This pull request was created as a result of the following prompt from Copilot chat.

The test Test_RichSuggestBox_DeleteTokens in components/RichSuggestBox/tests/Test_RichSuggestBox.cs is intermittently failing, particularly on WinUI 3, as discussed in issue #589. To stabilize CI and allow further investigation into the underlying cause, add the [Ignore("Intermittent failure - see https://github.com/CommunityToolkit/Windows/issues/589")] attribute to this test. Ensure only this specific test is disabled, and reference the issue in the changes.

Summary:


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…ittent failure

Co-authored-by: michael-hawker <24302614+michael-hawker@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ignore attribute to test for intermittent failure Add [Ignore] attribute to Test_RichSuggestBox_DeleteTokens for intermittent failure Nov 26, 2025
Copilot AI requested a review from michael-hawker November 26, 2025 18:52
Copilot finished work on behalf of michael-hawker November 26, 2025 18:52
@michael-hawker
Copy link
Member

Ironically also failed on Add Tokens too.

@copilot can you ignore that intermittent failing test as well?

…ent failure

Co-authored-by: michael-hawker <24302614+michael-hawker@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 26, 2025

Ironically also failed on Add Tokens too.

@copilot can you ignore that intermittent failing test as well?

Added [Ignore] attribute to Test_RichSuggestBox_AddTokens as well in 44e61bf.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • crl.godaddy.com
    • Triggering command: /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/A936EF26E74831CD646CD07ED0505593/missingpackages_workingdir --packages /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)
  • ocsp.godaddy.com
    • Triggering command: /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/A936EF26E74831CD646CD07ED0505593/missingpackages_workingdir --packages /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Add [Ignore] attribute to Test_RichSuggestBox_DeleteTokens for intermittent failure Add [Ignore] attribute to intermittently failing RichSuggestBox tests Nov 26, 2025
Copilot finished work on behalf of michael-hawker November 26, 2025 21:09
@michael-hawker
Copy link
Member

Hmm... now it's in CustomizeToken. I feel like there's some underlying issue with RichTextBox on Windows App SDK that is just tripping us up here, as I think we only see these fail in WinUI 3 regularly vs. WinUI 2?

@copilot instead of ignoring the tests, can you replace the Task delays across all the RichSuggestBox tests with the CompositionTargetHelper as suggested here: #589 (comment)

Please also provide any further analysis into the problem and potential solutions

Co-authored-by: michael-hawker <24302614+michael-hawker@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 26, 2025

Hmm... now it's in CustomizeToken. I feel like there's some underlying issue with RichTextBox on Windows App SDK that is just tripping us up here, as I think we only see these fail in WinUI 3 regularl...

Replaced all Task.Delay(10) calls with CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { }) across all RichSuggestBox tests in 0175d09. This properly waits for the composition rendering pass to complete instead of relying on a fixed delay.

Analysis: The intermittent failures appear to be caused by race conditions where Task.Delay(10) isn't always sufficient for the WinUI 3 RichTextBox to complete its text changes and fire events. This is consistent with the observation that failures happen primarily on WinUI 3 vs. WinUI 2, suggesting differences in the platform's text control event timing. The CompositionTargetHelper approach is already used in other tests across the toolkit and provides a more reliable synchronization mechanism.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • crl.godaddy.com
    • Triggering command: /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/Windows/Windows/components/Animations/samples/Animations.Samples.csproj --packages /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot (dns block)
    • Triggering command: /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/Windows/Windows/components/HeaderedControls/src/CommunityToolkit.WinUI.Controls.HeaderedControls.csproj --packages /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot (dns block)
    • Triggering command: /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/Windows/Windows/tooling/ProjectHeads/SingleComponent/Wasm/ProjectTemplate.Wasm.csproj --packages /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot (dns block)
  • ocsp.godaddy.com
    • Triggering command: /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/Windows/Windows/components/Animations/samples/Animations.Samples.csproj --packages /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot (dns block)
    • Triggering command: /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/Windows/Windows/components/HeaderedControls/src/CommunityToolkit.WinUI.Controls.HeaderedControls.csproj --packages /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot (dns block)
    • Triggering command: /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/Windows/Windows/tooling/ProjectHeads/SingleComponent/Wasm/ProjectTemplate.Wasm.csproj --packages /home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/Windows/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Add [Ignore] attribute to intermittently failing RichSuggestBox tests Replace Task.Delay with CompositionTargetHelper in RichSuggestBox tests Nov 26, 2025
Copilot finished work on behalf of michael-hawker November 26, 2025 22:36
@michael-hawker
Copy link
Member

Re-running all the checks again to see how it holds up, optimistic that first pass passed.

@michael-hawker michael-hawker marked this pull request as ready for review December 1, 2025 20:15
@michael-hawker
Copy link
Member

Re-running all checks again while waiting for @Arlodotexe review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RichSuggestBox Intermittent Test Failures

2 participants