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

Switch to InheritableThreadLocal #1242

Closed
thokari opened this issue May 9, 2018 · 3 comments
Closed

Switch to InheritableThreadLocal #1242

thokari opened this issue May 9, 2018 · 3 comments

Comments

@thokari
Copy link

thokari commented May 9, 2018

I would like to write a test that does some concurrent activity.

For example:

someSteps.while_calling_endpoint_A_every_X_milliseconds_for_Y_seconds()
otherSteps.when_changing_some_data_using_endpoint_B()
someSteps.then_the_endpoint_A_will_not_have_shown_any_errors_during_that_time()

So assuming that in someSteps I would like to create a new Thread, then I will have the problem that the ThreadLocal variables (from other shared Steps) for that new thread is basically gone / null.

I propose to change every instance of ThreadLocal involved in Step decoration to InheritableThreadLocal in order to be able to create concurrent checking Threads from within @Steps, that can still access shared @Steps.

@wakaleo
Copy link
Member

wakaleo commented May 10, 2018

ThreadLocals are usually ThreadLocal for a reason - if they are not ThreadLocal, the reports won't get generated properly because the event bus needs to be one per thread. I'm not sure how an InheritableThreadLocal would work for this.

@wakaleo
Copy link
Member

wakaleo commented May 10, 2018

I think in the context you describe, the InheritableThreadLocal approach should work. Please feel free to test it out and provide a PR if it works.

@wakaleo
Copy link
Member

wakaleo commented May 13, 2018

This is potentially doable but causes problems with the SerenityParameterizedRunner, which runs separate tests in parallel in separate threads. Feel free to see if you can get it to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants