Skip to content

PublishedEvents should see events published from asynchronous event listeners, too #116

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
odrotbohm opened this issue Jan 13, 2023 · 0 comments
Assignees
Labels
in: test support Spring Boot integration testing type: enhancement Major enhanvements, new features
Milestone

Comments

@odrotbohm
Copy link
Member

Currently, PublishedEvents is backed by a ThreadLocal to isolate the test execution from others potentially running in parallel. That unfortunately means, that events published asynchronous event listeners are not seen by PublishedEvents as they are published by the task executing thread.

We should switch to an InheritableThreadLocal for the event capturing to see all events that originate in threads spawned by the test executing one as well.

@odrotbohm odrotbohm added in: test support Spring Boot integration testing type: enhancement Major enhanvements, new features labels Jan 13, 2023
@odrotbohm odrotbohm added this to the 0.3 milestone Jan 13, 2023
@odrotbohm odrotbohm self-assigned this Jan 13, 2023
odrotbohm added a commit that referenced this issue Jan 13, 2023
…eners as well.

The ApplicationListener we deploy to capture events published  during a test method execution now uses an InheritableThreadLocal so that events published on threads spawned from the main test execution thread also end up in the PublishedEvents instance prepared for the test method.

Also, the registration of that particular event listener avoids duplicate registrations by inspecting the application context in use for the test method execution for an already registered listener, falling back to registering one.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
in: test support Spring Boot integration testing type: enhancement Major enhanvements, new features
Projects
None yet
Development

No branches or pull requests

1 participant