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

Unstable test: TransitionToMainThreadRaisedWhenSwitchingToMainThread #44

Closed
AArnott opened this issue Jan 14, 2017 · 1 comment
Closed
Assignees
Labels

Comments

@AArnott
Copy link
Member

AArnott commented Jan 14, 2017

This test has been observed to fail

   TransitionToMainThreadRaisedWhenSwitchingToMainThread [FAIL]
      Assert.Equal() Failure
      Expected: 1
      Actual:   0
      Stack Trace:
        src\Microsoft.VisualStudio.Threading.Tests.Shared\JoinableTaskTests.cs(529,0): at Microsoft.VisualStudio.Threading.Tests.JoinableTaskTests.<>c__DisplayClass19_0.<<TransitionToMainThreadRaisedWhenSwitchingToMainThread>b__0>d.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
        src\Microsoft.VisualStudio.Threading.Shared\JoinableTask.cs(519,0): at Microsoft.VisualStudio.Threading.JoinableTask.<JoinAsync>d__76.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
        src\Microsoft.VisualStudio.Threading.Shared\JoinableTask.cs(884,0): at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread()
        src\Microsoft.VisualStudio.Threading.Shared\JoinableTask.cs(497,0): at Microsoft.VisualStudio.Threading.JoinableTask.Join(CancellationToken cancellationToken)
        src\Microsoft.VisualStudio.Threading.Tests.Shared\JoinableTaskTests.cs(546,0): at Microsoft.VisualStudio.Threading.Tests.JoinableTaskTests.TransitionToMainThreadRaisedWhenSwitchingToMainThread()
@sharwell
Copy link
Member

I fixed this by adding a small delay after these assertions to ensure the background operation doesn't complete before the code awaits the result.

@AArnott AArnott self-assigned this May 23, 2017
AArnott added a commit that referenced this issue May 23, 2017
…oMainThread

If the threadpool executed the Task.Run delegate fast enough, the returned Task can actually be completed before the calling thread tries to await on it, leading to the next assertion to fail because the main thread transitions never took place.

I fix this by forcing a yield in all cases.

Fixes #44
@AArnott AArnott closed this as completed in a1ce385 Jun 3, 2017
AArnott added a commit that referenced this issue Apr 11, 2022
Add machine-wide .NET install support off Windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants