Not sure if this is the right question, but in my akka http-based system, when processing a request, we have calls that behave differently in RouteTests vs real systems. Given the following code:
def fn(thing: Thing): EitherT[Future, Error, Thing] = {
if (someCondition) {
EitherT(Future.successful(Right(thing)))
} else {
EitherT(Future.successful(Left(error)))
}
}
def rollback(): EitherT[...] = {
// general cleanup
}
List(things).map(fn).sequence.leftMap {
case err =>
rollback()
rrr
}
In tests, the .sequence
completion only ever happens after all the fn()
executions complete, even if there is a failure.
In real life, a failure from one execution of fn()
will cause .sequence
to execute while other calls to fn() are still executing, which is undesired, but, afaik, expected. I want to test a workaround, but I am unable to simulate the real-world conditions inside a RouteTest, and I think this is because everything is running on one thread.
Is there a way to make the RouteTest simulate a multi-threaded scenario?
Thanks!