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

Intermittent test failure in LoseSyncContext() #549

Closed
crozone opened this issue Nov 15, 2023 · 3 comments
Closed

Intermittent test failure in LoseSyncContext() #549

crozone opened this issue Nov 15, 2023 · 3 comments

Comments

@crozone
Copy link
Collaborator

crozone commented Nov 15, 2023

We are intermittently seeing test failures from an assertion within Stateless.Tests.SynchronizationContextFixture.LoseSyncContext(), for example:

https://github.com/dotnet-state-machine/stateless/actions/runs/6823242739/job/18556789583

which failed with:

Assert.NotEqual() Failure
Expected: Not MaxConcurrencySyncContext { }
Actual:   MaxConcurrencySyncContext { }

This code, which uses await Task.Run(() => { }).ConfigureAwait(false); to lose the synchronization context, was introduced in PR #528 as an attempt to fix the same issue occurring with the previous strategy using await Task.Delay(TimeSpan.FromMilliseconds(1)).ConfigureAwait(false);.

It appears that await Task.Run(() => { }).ConfigureAwait(false); works most of the time, but there's something going on which means that it doesn't always lose the synchronization context. Is it possible that it's still completing synchronously?

@leeoades
Copy link
Contributor

That was exactly my thought - that it is clever enough to realise that executing the action synchronously is the most efficient thing to do, and as a result, just happens to retain the sync context. I guess we need to work out a more reliable mechanism to force this not to occur.

@leeoades
Copy link
Contributor

leeoades commented Dec 2, 2024

@crozone - Huge apologies for the ridiculously long time it has taken me to get around to fixing this. So much so that I've forgotten how to raise PRs and link to issues 🤣
#606

@crozone
Copy link
Collaborator Author

crozone commented Dec 3, 2024

Merged, thanks for your contribution!

@crozone crozone closed this as completed Dec 3, 2024
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

No branches or pull requests

2 participants