eclipse-vertx / vertx-junit5

Testing Vert.x applications with JUnit 5
Apache License 2.0
44 stars 32 forks source link

Nested WebClient calls are not synchronized with JUnit 5 Lifecycle #75

Closed muthenberg closed 4 years ago

muthenberg commented 4 years ago

Version

Versions 3.8.5 and 3.9.0

Context

I have an application that needs to nest all REST-API calls in an authentication REST-API call. So all the tests have a WebClient, which does an authentication call and inside the succeeding handler of that authentication call does another call to the actual API endpoint using the acquired authentication token. However the test case finishes before the WebClient has finished and calls the @AfterEach method shutting down my environment.

Do you have a reproducer?

I cloned your vertx-gradle-starter project and modified the test case as a reproducer here: https://github.com/muthenberg/vertx-gradle-starter/tree/reproducer

Steps to reproduce

  1. Run MainVerticleTest from the reproducer
  2. Output is:
    Begin prepare
    End prepare
    Begin test
    End test
    response 2
    after
  3. I would expect
    Begin prepare
    End prepare
    Begin test
    response 2
    End test
    after
jponge commented 4 years ago

deployVerticle is an asynchronous operation, so System.out.println("End prepare"); is likely to be run before deployVerticle has completed. Same with System.out.println("End test");.

The JUnit5 lifecycle is respected, the extension is waiting for completion of the asynchronous tasks. It's just that your test and before/after methods will exit before these asynchronous tasks have completed.