0

How properly test webflux method with long operation

For example Spring Webflux / Reactor release calling thread

@GetMapping("/foo")
public Mono<Void> bar() {
    return Mono.fromCallable(() -> someService.veryLongSyncOperation())
            .subscribeOn(Schedulers.elastic())
            .then();
}

I return Mono but veryLongSyncOperation works.

So how properly write test with StepVerifier for such method without Thread.sleep(XXX); Get results of veryLongSyncOperation and check them.

LeshaRB
  • 1,345
  • 2
  • 23
  • 44
  • could you clarify which method you want to test? do you want to test your entire reactive chain which contains long operation or you want to test the method with long operation? – kerbermeister Feb 20 '23 at 16:09
  • @kerbermeister method veryLongSyncOperation is private. So I want test chain. And get results after method veryLongSyncOperation will be finish – LeshaRB Feb 20 '23 at 20:12
  • you are returning `Mono` so what is it you actually want to assert? – Toerktumlare Feb 21 '23 at 01:43
  • @Toerktumlare This is just someone else's example, my method will be create record, fast logic and return id. But it must also run a method that will enrich the created record in the database from other systems. This method is private... So I want to know how to test this? – LeshaRB Feb 21 '23 at 02:51
  • 1
    tbh, we cant write a fictional test, for some code that you have not posted. I suggest you read the reactor documentation on how to test reactive workflows. Then you read the spring boot documentations chapter on testing. Then you try to write a test, and if you get stuck, you post your code with full error logs and we will help you through your problem there and then. – Toerktumlare Feb 21 '23 at 04:05

0 Answers0