Skip to content

Commit

Permalink
Merge pull request #57 from tsegismont/issue/56
Browse files Browse the repository at this point in the history
Fixes #56 Intermittent failure in MetricsTest#testHttpMetricsOnClose
  • Loading branch information
vietj committed Feb 10, 2017
2 parents bbc2b83 + 2cae3dc commit 9ab8aa9
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/test/java/io/vertx/ext/dropwizard/MetricsTest.java
Expand Up @@ -74,6 +74,7 @@
import java.util.concurrent.atomic.AtomicReference;

import static io.vertx.test.core.TestUtils.*;
import static java.util.concurrent.TimeUnit.*;

/**
* @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
Expand Down Expand Up @@ -359,9 +360,18 @@ public void testHttpMetricsOnClose() throws Exception {

await();

JsonObject metrics = metricsService.getMetricsSnapshot(server);
JsonObject metrics;
long start = System.currentTimeMillis();
// This allows http server metrics to be completely removed from the registry
do {
metrics = metricsService.getMetricsSnapshot(server);
if (metrics != null && metrics.isEmpty()) {
break;
}
MILLISECONDS.sleep(100);
} while (System.currentTimeMillis() - start < 5000);
assertNotNull(metrics);
assertTrue(metrics.isEmpty());
assertEquals(Collections.emptyMap(), metrics.getMap());

metrics = metricsService.getMetricsSnapshot(client);
assertNotNull(metrics);
Expand Down Expand Up @@ -1015,7 +1025,7 @@ public void testScheduledMetricConsumer() {
ScheduledMetricsConsumer consumer = new ScheduledMetricsConsumer(vertx).
filter((name, metric) -> name.startsWith(baseName));

consumer.start(300, TimeUnit.MILLISECONDS, (name, metric) -> {
consumer.start(300, MILLISECONDS, (name, metric) -> {
assertTrue(name.startsWith(baseName));
if (count.get() == 0) {
if (name.equals(baseName + ".messages.sent")) {
Expand All @@ -1032,7 +1042,7 @@ public void testScheduledMetricConsumer() {

await();
}

@Test
public void testMetricsCleanupedOnVertxClose() throws Exception {
CountDownLatch latch1 = new CountDownLatch(1);
Expand Down Expand Up @@ -1268,7 +1278,7 @@ public void testJsonMetricsTypes() {
}

private void assertMetricType(String expectedType, Metric metric) {
assertMetricType(expectedType, Helper.convertMetric(metric, TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS));
assertMetricType(expectedType, Helper.convertMetric(metric, MILLISECONDS, MILLISECONDS));
}

private void assertMetricType(String expectedType, JsonObject metric) {
Expand Down

0 comments on commit 9ab8aa9

Please sign in to comment.