Checks inside thenEventually { } / thenContinually { } run on Dispatchers.IO, so user-owned ThreadLocals (e.g. a tracking id holder) are unset there. KensaThreadContextElement only carries Kensa's own contexts and there is no extension point.
Add withCoroutineContextProviders(vararg providers: () -> CoroutineContext) to KensaConfigurator. kensaThreadContext() invokes each provider on the test thread and folds the elements into the polling context, so ThreadLocal.asContextElement() captures the current value at poll start.
Kensa.configure().withCoroutineContextProviders(TrackingContext::asContextElement)
Checks inside
thenEventually { }/thenContinually { }run onDispatchers.IO, so user-owned ThreadLocals (e.g. a tracking id holder) are unset there.KensaThreadContextElementonly carries Kensa's own contexts and there is no extension point.Add
withCoroutineContextProviders(vararg providers: () -> CoroutineContext)toKensaConfigurator.kensaThreadContext()invokes each provider on the test thread and folds the elements into the polling context, soThreadLocal.asContextElement()captures the current value at poll start.