Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io.vertx.junit5.VertxTestContext.awaitCompletion is not being called properly #85

Closed
cvgaviao opened this issue Sep 13, 2020 · 0 comments
Labels

Comments

@cvgaviao
Copy link

Version

4.0.0-SNAPSHOT

Context

My junit5 based tests are finishing before the execution of future calls unless I use a CountDownLatch on my own.

  @Test
  @Timeout(value = 50, timeUnit = TimeUnit.SECONDS)
  void start_http_server1(VertxTestContext pTestContext, ApplicationLauncher pLauncher)
    throws Throwable {

    pLauncher.launch().onComplete(pTestContext.succeeding(app -> {
      Vertx vertx = app.getVertx();
      WebClient client = WebClient.create(vertx);
      client.get(8080,
                 "localhost",
                 "/ping")
        .as(BodyCodec.string())
        .send(pTestContext.succeeding(response -> pTestContext.verify(() -> {
          assertThat(response.body()).isEqualTo("pong");
          pTestContext.completeNow();
        })));
    }));
  }

I noted in the source code that a CountDownLatch already exists in the VertxTestContext class, but somehow it is not being reached/used.

So, doing some debugging I've noted that the io.vertx.junit5.VertxTestContext.awaitCompletion, that calls the latch, is being called inside the joinActiveTestContexts method, which is called in all the test lifecycle methods (beforeAll, beforeEach, and others).
But it will reach the latch ONLY IF a VertxTestContext instance was already created.

private void joinActiveTestContexts(ExtensionContext extensionContext) throws Exception {
    ContextList currentContexts = store(extensionContext).remove(TEST_CONTEXT_KEY, ContextList.class);
    if (currentContexts != null) {  <---- **condition1**
      for (VertxTestContext context : currentContexts) {
       ...

        if (context.awaitCompletion(timeoutDuration, timeoutUnit)) {

And, in the debug I'm doing, that is never true, just because the VertxTestContext instance that is stored in currentContexts checked above is being created only in the method io.vertx.junit5.VertxExtension.resolveParameter, which is always called after all other lifecycle methods, so the condition1 is aways false.

@cvgaviao cvgaviao added the bug label Sep 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant