eclipse-vertx / vertx-junit5

Testing Vert.x applications with JUnit 5
Apache License 2.0
42 stars 30 forks source link

Add failing tests for running tests on a VertxThread #43

Closed matthewadams closed 6 years ago

matthewadams commented 6 years ago

This PR provides a response to @jponge 's question at https://groups.google.com/forum/?fromgroups#!topic/vertx/hZKptoExh1c

matthewadams commented 6 years ago

For anyone looking for the solution to the potential issue this PR attempted to identify, it's to use vertx.runOnContext():

@ExtendWith(VertxExtension.class)
@DisplayName("Configure extension to run tests in a VertxThread")
class RunOnVertxThreadTest {
  @Test
  public void ensureVertxThread(Vertx vertx) {
    vertx.runOnContext(event -> { ///////////////////  <- this is the fix
      assertTrue(Thread.currentThread() instanceof VertxThread);
      assertNotNull(Vertx.currentContext());
    });
  }
}