Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure not raised when testing with a HttpServer #31

Closed
dadoonet opened this issue Jan 25, 2018 · 4 comments
Closed

Failure not raised when testing with a HttpServer #31

dadoonet opened this issue Jan 25, 2018 · 4 comments
Assignees
Labels
Milestone

Comments

@dadoonet
Copy link

I'm not getting a failure when testing this code and I don't understand where I'm doing something bad.
Hopefully you can help :)

@ExtendWith(VertxExtension.class)
class VertxTest {

    private final Logger logger = LogManager.getLogger(this.getClass());

    @BeforeEach
    void deployVertice(Vertx vertx, VertxTestContext testContext) {
        vertx.deployVerticle(new FakeVertice(), testContext.succeeding(id -> {
            logger.info(" -> test webhook verticle deployed {}", id);
            logger.info("deployVertice {}", vertx.deploymentIDs());
        }));
    }

    @Test
    void testDeployVertice(Vertx vertx, VertxTestContext testContext) {
        testContext.verify(() -> {
            logger.info("testDeployVertice {}", vertx.deploymentIDs());
            assertFalse(vertx.deploymentIDs().isEmpty());
            testContext.completeNow();
        });
    }

    @Test
    void testPostValidate(Vertx vertx, VertxTestContext testContext) {
        // Create the WebClient to connect to our Vertx instance
        WebClient webClient = WebClient.create(vertx,
                new WebClientOptions()
                        .setDefaultHost("localhost")
                        .setDefaultPort(8080));

        HttpRequest<Buffer> request = webClient.get("/");
        request.send(testContext.succeeding(result -> testContext.verify(() -> {
            logger.fatal("CODE {}", result.statusCode());
            assertEquals(200, result.statusCode());

            logger.fatal("JSON {}", result.bodyAsString());
            logger.fatal("MESSAGE {}", result.bodyAsJsonObject().getString("message"));
            logger.fatal("JSON {}", result.bodyAsString());
        })));
    }


    static class FakeVertice extends AbstractVerticle {

        @Override
        public void start(Future<Void> futureVertx) {
            Router router = Router.router(vertx);
            router.route(HttpMethod.GET, "/")
                    .handler(routingContext -> {
                        // Write to the response and end it
                        HttpServerResponse response = routingContext.response();
                        response.setStatusCode(400);
                        String json = new JsonObject().put("message", "Vert.x is running!").encodePrettily();
                        response.putHeader("content-type", "application/json");
                        response.putHeader("content-length", "" + json.length());
                        response.write(json).end();
                    });

            vertx.createHttpServer().requestHandler(router::accept)
                    .listen(8080, ar -> {
                        if (ar.succeeded()) {
                            futureVertx.complete();
                        }
                        if (ar.failed()) {
                            futureVertx.fail("Can not start");
                        }
                    });

        }
    }
}

The test is passing and the log is:

19:06:13,351 INFO  [f.b.w.VertxTest]  -> test webhook verticle deployed 8e0df37a-78ac-4c8c-9692-be50cb81c3e2
19:06:13,353 INFO  [f.b.w.VertxTest] deployVertice [8e0df37a-78ac-4c8c-9692-be50cb81c3e2]
19:06:13,803 FATAL [f.b.w.VertxTest] CODE 400

Any idea?

@jponge
Copy link
Member

jponge commented Jan 26, 2018

Let me check :-)

@jponge jponge self-assigned this Jan 26, 2018
@jponge jponge added the bug label Jan 26, 2018
@jponge jponge added this to the 3.5.1 milestone Jan 26, 2018
@jponge
Copy link
Member

jponge commented Jan 26, 2018

I confirm there is a bug. I'm working on a fix now.

@jponge
Copy link
Member

jponge commented Jan 26, 2018

Doing some checks on a simpler reproducer, but it looks like an exception is being swallowed somewhere.

@jponge
Copy link
Member

jponge commented Jan 26, 2018

The problem is related to the changes introduced in #5, and that have inherent correctness issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants