Reputation: 1
Could someone advise if it’s possible to simulate the passage of time in Vert.x 4, and how to do so?
In Vert.x version 3, it was possible to simulate the passage of time in unit tests using TestScheduler, for example:
@Test
void simulateTimeFlow(Vertx vertx, VertxTestContext testContext) {
// Use a TestScheduler for controlling time
TestScheduler testScheduler = RxHelper.scheduler(vertx);
// Simulate time-based logic
vertx.setTimer(5000, id -> {
testContext.completeNow(); // Complete the test after 5 seconds (simulated)
});
// Advance the TestScheduler's time by 5 seconds
testScheduler.advanceTimeBy(5, TimeUnit.SECONDS);
// Await completion
testContext.awaitCompletion(5000, TimeUnit.MILLISECONDS);
}
It appears that this functionality is not available in Vert.x 4, which makes testing more complex applications challenging since unit tests need to wait for the actual configured time to complete. While configuring shorter wait times in unit tests is an option, it is not ideal. Ideally, there should be a way to inject a test clock into the Vert.x instance to control time during tests. However, Vert.x 4 does not provide a Clock in its API.
It tried using latest TestScheduler t = RxHelper.scheduler(vertx) but it only works for rx java vertx not core vertx instance.
I also looked for setClock in VertxOptions but obviously its not there.
Upvotes: 0
Views: 40