问题
I'm using Vert.x 3.5.3
. I have this (simple) Verticle:
class DialPadVerticle : AbstractVerticle() {
private companion object : KLogging()
override fun start(future: Future<Void>) {
vertx.eventBus().consumer(Address.DIALPAD_COMBINATIONS) { message: Message<Int> ->
val input = message.body()
logger.info { "Received: $input" }
message.reply(JsonObject().put("result", DialPad().combinations(input)))
}
future.complete()
}
override fun stop(future: Future<Void>) {
logger.debug { "Stopping ${this.javaClass.simpleName} (${deploymentID()})...DONE" }
future.complete()
}
}
...and I'm trying to build a unit test skeleton for it using the experimental (yet) vertx-junit5
. So far, I have this:
@ExtendWith(VertxExtension::class)
@DisplayName("Dial pad verticle should...")
internal class DialPadVerticleTest {
@BeforeEach
fun prepare(vertx: Vertx, testContext: VertxTestContext) {
vertx.deployVerticle(DialPadVerticle(), testContext.succeeding())
}
@Test
@Throws(Exception::class)
@DisplayName("Consume Message<Int> correctly")
fun `consume message correctly`(vertx: Vertx, testContext: VertxTestContext) {
vertx.eventBus().send<JsonObject>(Address.DIALPAD_COMBINATIONS, 5) {
// Assertions.assertThat(it.succeeded()).isTrue()
testContext.verify {
testContext.completeNow()
}
}
}
}
But every time I try to run that from within IntelliJ, I'm getting:
java.util.concurrent.TimeoutException: The test execution timed out
at io.vertx.junit5.VertxExtension.joinActiveTestContexts(VertxExtension.java:213)
at io.vertx.junit5.VertxExtension.beforeTestExecution(VertxExtension.java:171)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeTestExecutionCallbacks$4(TestMethodTestDescriptor.java:141)
at org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeMethodsOrCallbacksUntilExceptionOccurs(TestMethodTestDescriptor.java:155)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeTestExecutionCallbacks(TestMethodTestDescriptor.java:140)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:111)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:58)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:113)
at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$2(HierarchicalTestExecutor.java:121)
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:121)
at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$2(HierarchicalTestExecutor.java:121)
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:121)
at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:55)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:43)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Is this somehow a bug on the vertx-junit5
library? I've noticed also that, if the Verticles relies on some external config, even though I pass the correct DeploymentOptions().setConfig(JsonObject().put(...))
as second parameter to deployVerticle
, it doesn't read those.
回答1:
I ran your code and noticed that the execution never reached the test method.
You need to also close your context in @BeforeEach
methods:
@BeforeEach
fun prepare(vertx: Vertx, testContext: VertxTestContext) {
vertx.deployVerticle(DialPadVerticle(), testContext.succeeding {
testContext.completeNow()
})
}
testContext.succeeding
only provides a AsyncResult
handler that checks that the result succeeded, but it does not mark the whole test context as having completed. It simplifies checking intermediary steps.
Now the test passes just fine!
回答2:
Would you have a minimal reproducer project somewhere?
来源:https://stackoverflow.com/questions/51490655/vert-x-test-halts-with-timeoutexception-the-test-execution-timed-out