Skip to content

Commit

Permalink
Fixes vert-x3#56 Intermittent failure in MetricsTest#testHttpMetricsO…
Browse files Browse the repository at this point in the history
…nClose

Allow http server metrics to be completely removed from the registry
  • Loading branch information
tsegismont committed Dec 23, 2016
1 parent f68c179 commit 03c2478
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/test/java/io/vertx/ext/dropwizard/MetricsTest.java
Expand Up @@ -52,6 +52,7 @@
import io.vertx.core.net.NetSocket;
import io.vertx.ext.dropwizard.impl.AbstractMetrics;
import io.vertx.ext.dropwizard.impl.Helper;
import io.vertx.test.core.Repeat;
import io.vertx.test.core.RepeatRule;
import io.vertx.test.core.TestUtils;
import org.junit.Rule;
Expand All @@ -74,6 +75,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 @@ -333,6 +335,7 @@ private void test(int code, String metricName) throws Exception {
}

@Test
@Repeat(times = 100)
public void testHttpMetricsOnClose() throws Exception {
int requests = 6;
CountDownLatch latch = new CountDownLatch(requests);
Expand All @@ -359,9 +362,17 @@ public void testHttpMetricsOnClose() throws Exception {

await();

JsonObject metrics = metricsService.getMetricsSnapshot(server);
JsonObject metrics;
long start = System.currentTimeMillis();
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 +1026,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 +1043,7 @@ public void testScheduledMetricConsumer() {

await();
}

@Test
public void testMetricsCleanupedOnVertxClose() throws Exception {
CountDownLatch latch1 = new CountDownLatch(1);
Expand Down Expand Up @@ -1268,7 +1279,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 03c2478

Please sign in to comment.