|
13 | 13 |
|
14 | 14 | import io.vertx.core.AbstractVerticle;
|
15 | 15 | import io.vertx.core.DeploymentOptions;
|
| 16 | +import io.vertx.core.Future; |
16 | 17 | import io.vertx.core.Promise;
|
17 | 18 | import io.vertx.core.Vertx;
|
18 | 19 | import io.vertx.ext.unit.Async;
|
19 | 20 | import io.vertx.ext.unit.TestContext;
|
20 | 21 | import io.vertx.ext.unit.junit.VertxUnitRunner;
|
21 | 22 | import io.vertx.sqlclient.PoolOptions;
|
| 23 | +import io.vertx.sqlclient.SqlConnection; |
22 | 24 | import org.junit.After;
|
23 | 25 | import org.junit.Before;
|
24 | 26 | import org.junit.Test;
|
@@ -79,14 +81,23 @@ public void start() {
|
79 | 81 | latch.awaitSuccess(20_000);
|
80 | 82 | vertx.undeploy(deployment.get())
|
81 | 83 | .compose(v -> PgConnection.connect(vertx, options))
|
82 |
| - .compose(conn -> conn.query(COUNT_CONNECTIONS_QUERY) |
83 |
| - .execute().compose(res -> { |
84 |
| - int num = res.iterator().next().getInteger(0); |
85 |
| - return conn.close().map(num); |
86 |
| - }) |
87 |
| - ).onComplete(ctx.asyncAssertSuccess(num -> { |
88 |
| - ctx.assertEquals(1, num); |
89 |
| - })); |
| 84 | + .compose(conn -> waitUntilConnCountIs(conn, 10, 1) |
| 85 | + ).onComplete(ctx.asyncAssertSuccess()); |
| 86 | + } |
| 87 | + |
| 88 | + private Future<Void> waitUntilConnCountIs(SqlConnection conn, int remaining, int expectedCount) { |
| 89 | + if (remaining > 0) { |
| 90 | + return conn.query(COUNT_CONNECTIONS_QUERY).execute().compose(res -> { |
| 91 | + int num = res.iterator().next().getInteger(0); |
| 92 | + if (num == expectedCount) { |
| 93 | + return Future.succeededFuture(); |
| 94 | + } else { |
| 95 | + return waitUntilConnCountIs(conn, remaining - 1, expectedCount); |
| 96 | + } |
| 97 | + }); |
| 98 | + } else { |
| 99 | + return Future.failedFuture("Could not count"); |
| 100 | + } |
90 | 101 | }
|
91 | 102 |
|
92 | 103 | @Test
|
|
0 commit comments