Vert.x - Timed out Exception when testing

Java Conceptuel Diagram

About

This is a really common error when you start with Vert.x and I lost a couple of hours on that many times. I figure out, I will put it available to everybody.

Error

If you get an error like that when you are making a test.

Timed out
java.util.concurrent.TimeoutException: Timed out
	at io.vertx.ext.unit.impl.CompletionImpl.awaitSuccess(CompletionImpl.java:111)
	at net.bytle.api.db.DatabaseVerticleTest.getIt(DatabaseVerticleTest.java:102)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at io.vertx.ext.unit.junit.VertxUnitRunner.invokeTestMethod(VertxUnitRunner.java:95)
	at io.vertx.ext.unit.junit.VertxUnitRunner.lambda$invokeExplosively$0(VertxUnitRunner.java:114)
	at io.vertx.ext.unit.impl.TestContextImpl.run(TestContextImpl.java:90)
	at io.vertx.ext.unit.junit.VertxUnitRunner.invokeExplosively(VertxUnitRunner.java:130)
	at io.vertx.ext.unit.junit.VertxUnitRunner.access$000(VertxUnitRunner.java:39)
	at io.vertx.ext.unit.junit.VertxUnitRunner$1.evaluate(VertxUnitRunner.java:84)
	at io.vertx.ext.unit.junit.VertxUnitRunner$2.evaluate(VertxUnitRunner.java:196)

Solution

There is a lot of chance that's because, you didn't complete your async. ie you forgot the async.complete(); line.

Example:

@Test
public void getIt(TestContext context) {

	Async async = context.async();
	service.getIt(context.asyncAssertSuccess(body -> {
	  context.assertEquals(0, body.fieldNames().size(), "No key");
	  async.complete(); // Without this line, you will got a timed out exception
	}));
	async.awaitSuccess(2000);

}







Share this page:
Follow us:
Task Runner