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

STA for Fixture Collections #52

Open
fmanso opened this issue Jan 29, 2021 · 5 comments
Open

STA for Fixture Collections #52

fmanso opened this issue Jan 29, 2021 · 5 comments

Comments

@fmanso
Copy link

fmanso commented Jan 29, 2021

I tried to put some intialization code in a fixture collection and it is crashing because it is not STA.
Could it be possible to have fixture collection constructor and dispose on STA?

Thanks

@AArnott
Copy link
Owner

AArnott commented Jan 29, 2021

Maybe. I'm not sure if xunit gives an individual test attribute like [StaFact] control over how fixtures are initialized, given fixtures are shared across tests that may use different attributes, I'm not sure that would even make sense.

Maybe the better approach is for your fixture to not initialize itself, but rather leave it to the first test to call into it (from the STA) and then it can lazily initialize.

@magol
Copy link

magol commented Apr 30, 2021

This is a issue to me too. I have some heavy initialization in the fixture collection that must be run on the same STA thread as all tests. One solution is to make an API available to let the fixture collection to schedule code in the STA thread created for [StaFact]

@AArnott
Copy link
Owner

AArnott commented Apr 30, 2021

Each StaFact runs on a new STA thread (which is required for concurrent test execution.)
If you have data structures that remember the thread they were created on and must be accessed only from that thread, that's a more strict requirement than StaFact provides, since it is only designed to run the test on an STA thread. There's no concept of the STA thread.

@AArnott
Copy link
Owner

AArnott commented Apr 30, 2021

#54 tracks a similar requirement. So we might devise something clever here.

@xvan
Copy link

xvan commented Apr 4, 2022

Each StaFact runs on a new STA thread (which is required for concurrent test execution.)

If you mark a test class as a [Collection()] all StaFact tests seem to run on the same thread.

But when trying to use multiple classes with the same Collection name to share a fixture, the collection Fixture isn't constructed inside an StaThread.

AArnott added a commit that referenced this issue Jan 5, 2023
Bring back access tokens for AzP feed access
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

4 participants