Repository navigation
Keep the caller's SynchronizationContext after ToTask - #2016
Merged
Merged
Conversation
ToTask cleared the current SynchronizationContext before building the task (#1774), and never put it back, so the caller's await captured no context and resumed on the thread pool. Under TUnit's [STAThreadExecutor] that moved the rest of every test that awaited Verify off the STA thread that owns its windows. Each window the test then closed or disposed waited on the STA thread, which was not pumping: about 0.7s per test, and controls disposed from a thread that does not own them. The pipeline still runs with no context. Once it has started, ToTask puts back any context other than the ones WinForms, WPF and Avalonia install when a control is created, which stay cleared, as nothing pumps them during a test.
This was referenced Nov 20, 2026
This was referenced Nov 23, 2026
andy-the-messenger-robot Bot
pushed a commit
to ccswe-avalonia/CCSWE.Avalonia.ViewLocator
that referenced
this pull request
Nov 23, 2026
Updated [CCSWE.Avalonia.Material](https://github.com/ccswe-avalonia/CCSWE.Avalonia.Material) from 12.3.4 to 12.3.5. <details> <summary>Release notes</summary> _Sourced from [CCSWE.Avalonia.Material's releases](https://github.com/ccswe-avalonia/CCSWE.Avalonia.Material/releases)._ No release notes found for this version range. Commits viewable in [compare view](https://github.com/ccswe-avalonia/CCSWE.Avalonia.Material/commits). </details> Updated [Verify.NUnit](https://github.com/VerifyTests/Verify) from 33.7.0 to 33.7.1. <details> <summary>Release notes</summary> _Sourced from [Verify.NUnit's releases](https://github.com/VerifyTests/Verify/releases)._ ## 33.7.1 - [x] [#2016](VerifyTests/Verify#2016) Keep the caller's SynchronizationContext after ToTask Commits viewable in [compare view](VerifyTests/Verify@33.7.0...33.7.1). </details> Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore <dependency name> major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore <dependency name> minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore <dependency name>` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore <dependency name>` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore <dependency name> <ignore condition>` will remove the ignore condition of the specified dependency and ignore conditions </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This was referenced Nov 23, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SettingsTask.ToTask()clears the currentSynchronizationContextbefore building the task (#1774), so the pipeline doesn't capture a UI framework's context that nothing pumps. It never put the context back, though. The caller'sawaittherefore captured no context and resumed on the thread pool.Under TUnit's
[STAThreadExecutor], that moved the rest of every test that awaitsVerifyoff the STA thread that owns its windows. TUnit's context runs posted continuations, but it was gone by the time the caller's await looked for one. Each window the test then hid or disposed (theusing var form = ...afterawait Verify(...)) had to be handled by the STA thread, which wasn't pumping window messages. That cost about 0.7s per test, and controls were disposed from a thread that doesn't own them.Change
ToTask()puts the caller's context back before the caller's await captures one, unless it is a context WinForms, WPF or Avalonia installs when a control is created:WindowsFormsSynchronizationContext,DispatcherSynchronizationContextandAvaloniaSynchronizationContext. Those stay cleared, as Clear synchronization context in to task() #1774 intended, since a continuation posted to one would never run. They are matched by full type name, including subclasses, because Verify references none of those frameworks.Tests
CallerKeepsItsSynchronizationContext: an ordinary context is current again afterToTask(), and the pipeline never posts to it. Fails without the change.UiSynchronizationContextStaysCleared: a stand-in for Avalonia's context stays cleared.Effect
In Lode (a WinForms app whose window tests run under
[STAThreadExecutor], one at a time), swapping in this build took the suite from 121s to 64s, with all 454 tests passing. Tests that show a window and thenawait Verifywent from 0.9–1.2s each to about 0.15s.