Hello All,
Our team recently started using Vert.x and we’re having some issues with testing.
We use JUnit5, and would love to stick to it, if possible (we say is possible given Vert.x’s JUnit5 integration is at a “Technical Preview” stage).
The main issue is that the test constantly times out and basically disregards the context.completeNow() call.
To try and isolate any potential mishaps on our side, we wrote some very simple code to better understand what we’re doing wrong, but we still haven’ figured it out.
Bellow please find the relevant code:
TestDao includes only 1 method:
//TestDao
public void foo(Handler<AsyncResult<Void>> handler) {
vertx.fileSystem().createFile(Paths.get("/", "tmp", "foo").toString(), handler);
}
ServiceVerticle class which extends AbstractVerticle and accepts TestDao in its constructor.
Our test is as follows:
//SampleTest
@Test
public void simpleTest(Vertx vertx, VertxTestContext context) {
final TestDao testDao = new TestDao();
vertx.deployVerticle(new ServiceVerticle(testDao), context.succeeding( id -> {
test.foo(
context.succeeding(
result -> {
context.verify(
() -> {
assertThat(Paths.get("/", "tmp", "foo").toFile().exists()).isTrue(); //We use Google's Truth Library
context.completeNow();
});
}));
}));
}
}
The error we get is `Closing the Vertx context timed out`
We also get the following warning `WARNING: You're already on a Vert.x context, are you sure you want to create a new Vertx instance?`
By plugging a few print statements before the assertion and after the #completeNow() we know that the block is being run, but we’re not sure what’s happening next.
Interestingly, including vertx.close(), in either the deployment callback or the verify callback makes the test pass. But we’d assume that #completeNow() should suffice.
Any help would be greatly appreciated.