Config customization not respected
wermerb opened this issue · comments
Hi,
My intent is to use BlockHound during unit tests and I wanted to give some exceptions. If I understand correctly, with the provided BlockHoundIntegration class, BlockHound should not trigger for the provided configurations.
Expected Behavior
Should not throw BlockingOperationError.
Actual Behavior
It throws BlockingOperationError
Steps to Reproduce
I've provided a demo application: gradlew test
demo.zip
Your Environment
- JVM version (
java -version
): Oracle JDK 11.0.6 - OS and version (eg
uname -a
): Windows 10
I think that the usual "Mono is asynchronous" caveat applies here: BlockHound can't probably attach the execution phase of the lambda that invokes sleep
to the fail()
method (which only assembles the Mono
without subscribing to it). So what's visible in the stack when the blocking call is attempted is the lamba, the subscribe call and the test method.
In order to allow this particular blocking call, you could use lambda$fail$0
as the method name.
Better yet, I'd advise you to extract that to a relevant method (let's call it example()
), replace the lambda with the method's reference and configure BlockHound to allow said method:
@Component
public class BlockHoundDemo {
public void example(Long l) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException();
}
}
public Mono<Long> fail() {
return Mono.delay(Duration.ofSeconds(1)).doOnNext(this::example);
}
}
and
builder.allowBlockingCallsInside("com.example.demo.BlockHoundDemo", "example");
@simonbasle Thank you very much for the explanation indeed it works :)