Thread pool scheduling event listener behave differently when it is run on xunit app #2202
-
Not sure if this is a bug, so I decided to start a discussion. I have an event listener class that listens to thread pool scheduling events. Here is the code ;
When i run this code in a console application as ;
I get following output ;
So 3 tasks were scheduled to run on thread pool, and our event listener class captured Enqueue and Dequeue events for all these 3 tasks.
This is the output ;
So , we were unable to capture "Enqueue" event for the first task that was scheduled to run on thread pool, but we only received Dequeue event for that task. I wonder what would cause this behaviour. Why this class was not able to capture first Enqueue event when it was run in Xunit project, but it successfully captured all the events when it was run in a console application. Here is source code of the whole sample : https://github.com/NazmiAltun/ThreadPoolSchedulingEventListener |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I honestly don't know the answer to this question, but here is some information about the way xUnit.net works that might contribute to you finding an answer. We have two synchronization contexts (that is, classes which derive from
In normal operation we use them both. It's possible that one or both of these are somehow interfering with what you're trying to do, although my understanding is that simply calling You can't turn off |
Beta Was this translation helpful? Give feedback.
I honestly don't know the answer to this question, but here is some information about the way xUnit.net works that might contribute to you finding an answer.
We have two synchronization contexts (that is, classes which derive from
SynchronizationContext
):AsyncTestSyncContext
andMaxConcurrencySyncContext
.AsyncTestSyncContext
allows us to support tests that are written asasync void
and still track the proper lifetime of the test method.MaxConcurrencySyncContext
allows us to create a limited set of worker threads to be used for schedulingTask
s that we have created, so as to limit the number of threads that are allowed to run in parallel at any given time.In normal operation we use t…