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

Execution Context (AsyncLocal) does not get transferred between [BeforeScenario] and the steps. #120

Closed
GedasFX opened this issue May 9, 2024 · 4 comments · Fixed by #126
Labels
bug Something isn't working

Comments

@GedasFX
Copy link

GedasFX commented May 9, 2024

Reqnroll Version

1.0.1

Which test runner are you using?

xUnit

Test Runner Version Number

2.6.5

.NET Implementation

.NET 8.0

Test Execution Method

ReSharper Test Runner

Content of reqnroll.json configuration file

No response

Issue Description

I have a setup in our tests where we have a service provider which generates services, and each of our tests is arranged as a separate request (scope). We also have some default value prefilling on before scenario (actual logic is more complex, but for sake of example it can be simplified).

The issue here is when we use IHttpContextAccessor, a singleton service, it internally uses AsyncLocal to keep track of the HTTP context. On Specflow, the assigned context in BeforeScenario, can be seen later in the service, however when using reqnroll, it cannot.

Steps to Reproduce

Successful commit (specflow): GedasFX/AsyncLocal_ReqNRoll@99c0c50
Failing commit (reqnroll): GedasFX/AsyncLocal_ReqNRoll@d444e22

Checkout the commits. There is a single test in the test suite.

Link to Repro Project

https://github.com/GedasFX/AsyncLocal_ReqNRoll

@GedasFX GedasFX added the bug Something isn't working label May 9, 2024
@GedasFX GedasFX changed the title Execution Context (AsyncLocal) does not get teansferred between bindings. Execution Context (AsyncLocal) does not get transferred between [BeforeScenario] and the steps. May 9, 2024
@gasparnagy
Copy link
Contributor

@GedasFX Could you please also make a commit where you use the latest beta of SpecFlow (4.0.31-beta) to see how the behavior was there?

@GedasFX
Copy link
Author

GedasFX commented May 10, 2024

@gasparnagy GedasFX/AsyncLocal_ReqNRoll@9feaa24 it's Its failing on 4.0.31-beta...

@gasparnagy
Copy link
Contributor

@GedasFX Thx. So this is a side effect of switching the testing to full async in SpecFlow v4. I remember that is was pretty tricky with the AsyncLocal and the execution context, but I don't remember all the details now. Fortunately there is a bunch of tests on the current behavior (https://github.com/reqnroll/Reqnroll/blob/main/Tests/Reqnroll.RuntimeTests/Bindings/BindingInvokerTests.cs#L268).

If you have a bit of time, you can review those tests, maybe it helps understanding the problem, but I can also look at that next week.

@GedasFX
Copy link
Author

GedasFX commented May 11, 2024

Oh I guess you guys sort of figured it out :D planned to check today ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants