mirror of
https://github.com/jlengrand/vert.x.git
synced 2026-03-10 08:51:19 +00:00
Improve MetricsTest#testBroadcastMessage to avoid race when the metrics has not yet fully published the collected metrics which are asserted
This commit is contained in:
@@ -108,8 +108,7 @@ public class MetricsTest extends VertxTestBase {
|
||||
AtomicInteger receiveCount = new AtomicInteger();
|
||||
for (Vertx vertx : to) {
|
||||
MessageConsumer<Object> consumer = vertx.eventBus().consumer(ADDRESS1);
|
||||
consumer.completionHandler(done -> {
|
||||
assertTrue(done.succeeded());
|
||||
consumer.completionHandler(onSuccess(v -> {
|
||||
if (broadcastCount.incrementAndGet() == to.length) {
|
||||
String msg = TestUtils.randomAlphaString(10);
|
||||
if (publish) {
|
||||
@@ -118,14 +117,15 @@ public class MetricsTest extends VertxTestBase {
|
||||
from.eventBus().send(ADDRESS1, msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}));
|
||||
consumer.handler(msg -> {
|
||||
if (receiveCount.incrementAndGet() == to.length) {
|
||||
assertEquals(new HashSet<>(Arrays.asList(expected)), new HashSet<>(eventBusMetrics.getSentMessages()));
|
||||
testComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
waitUntil(() -> eventBusMetrics.getSentMessages().size() == expected.length);
|
||||
assertEquals(new HashSet<>(Arrays.asList(expected)), new HashSet<>(eventBusMetrics.getSentMessages()));
|
||||
await();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user