vert-x3 / vertx-rx

Reactive Extensions for Vert.x
Apache License 2.0
145 stars 72 forks source link

RxJava 3 Vertx.deployVerticle failed #265

Closed hantsy closed 3 years ago

hantsy commented 3 years ago

I tried to use the Rxjava 3 vertx in Junit to deploy a Verticle, but it does not work as expected.

vertx.deployVerticle(new MainVerticle())
    .subscribe(
        data -> {
            log.info("deployed: {}", data);
            testContext.succeeding(id -> testContext.completeNow());
        },
        error -> log.error("error: {}", error)
    );

There is a timeout exception when running the testing codes.

Alternatively, I have to use the approach in the RxJava3Test.java to overcome this temporarily.

RxHelper
    .deployVerticle(vertx, new MainVerticle())
    .subscribe(
        message -> testContext.verify(() -> {
            log.info("deployed: {}", message);
            testContext.completeNow();
        }),
        testContext::failNow);
tsegismont commented 3 years ago

Can you share a complete reproducer? I just tried and I could not reproduce.

hantsy commented 3 years ago

Add https://github.com/hantsy/vertx-sandbox/blob/master/rxjava3/src/test/java/com/example/demo/TestMainVerticle_Issue265.java

tsegismont commented 3 years ago

The instructions for running the Postgres DB are missing

hantsy commented 3 years ago

There is a docker compose under the project root folder, see here.

tsegismont commented 3 years ago

Thanks.

This is not a bug, the issue in the test setup method:

vertx.deployVerticle(new MainVerticle())
    .subscribe(
        data -> {
            log.info("deployed: {}", data);
            // The following line creates a handler that is never used
            testContext.succeeding(id -> testContext.completeNow());
        },
        error -> log.error("error: {}", error)
    );

Change it to:

vertx.deployVerticle(new MainVerticle())
    .subscribe(
        data -> {
            log.info("deployed: {}", data);
            testContext.completeNow();
        },
        error -> {
            log.error("error: {}", error);
            // Without this line the test will timeout in case of failure to deploy the verticle
            testContext.failNow(Error);
        }
    );