Tests: @Async probably does not run synchronously under the test profile #212
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
AGENTS.mdand several tests assume@Asyncruns synchronously under thetestprofile becauseTestAsyncConfigprovides aSyncTaskExecutor.While fixing #207 this turned out to be doubtful (reasoned from the code, not proven by a run): Spring resolves the default async executor with
getBean(TaskExecutor.class), andTestAsyncConfigalso declares a@Primary taskScheduler(a single-threadThreadPoolTaskScheduler, which is aTaskExecutortoo). The primary bean wins, so@Asynclisteners would run on thetest-scheduling-thread, in parallel with the test's next request. Comments inPhase3IntegrationTest("@Async listener may also create a duplicate", "may not fire in time") point the same way, and it explains how #207 could race in CI.To do
@Asyncuses in tests (log the thread name in a listener, or assert on it).@Asyncpicks (e.g. anAsyncConfigurer, or name the beantaskExecutorand drop@Primaryfrom the scheduler), then remove workarounds in tests that wait for or tolerate async listeners.AGENTS.mdeither way.