diff --git a/reactor-netty-http/src/test/java/reactor/netty/resources/DefaultPooledConnectionProviderTest.java b/reactor-netty-http/src/test/java/reactor/netty/resources/DefaultPooledConnectionProviderTest.java index 57930a259..cf6175a00 100644 --- a/reactor-netty-http/src/test/java/reactor/netty/resources/DefaultPooledConnectionProviderTest.java +++ b/reactor-netty-http/src/test/java/reactor/netty/resources/DefaultPooledConnectionProviderTest.java @@ -669,12 +669,20 @@ void testDisposeInactivePoolsInBackground(boolean enableEvictInBackground, boole } MeterRegistrarImpl meterRegistrar; - String metricsName = ""; + CountDownLatch meterRemoved = new CountDownLatch(1); + String metricsName = CONNECTION_PROVIDER_PREFIX + ACTIVE_CONNECTIONS; + String metricsTagName = ""; if (isBuiltInMetrics) { meterRegistrar = null; builder.metrics(true); - metricsName = isHttp2 ? "http2.testDisposeInactivePoolsInBackground" : "testDisposeInactivePoolsInBackground"; + metricsTagName = isHttp2 ? "http2.testDisposeInactivePoolsInBackground" : "testDisposeInactivePoolsInBackground"; + + registry.config().onMeterRemoved(meter -> { + if (metricsName.equals(meter.getId().getName())) { + meterRemoved.countDown(); + } + }); } else { meterRegistrar = new MeterRegistrarImpl(); @@ -711,7 +719,7 @@ void testDisposeInactivePoolsInBackground(boolean enableEvictInBackground, boole assertThat(meterRegistrar.registered.get()).isTrue(); } else { - assertGauge(registry, CONNECTION_PROVIDER_PREFIX + ACTIVE_CONNECTIONS, NAME, metricsName).isNotNull(); + assertGauge(registry, metricsName, NAME, metricsTagName).isNotNull(); } if (enableEvictInBackground) { @@ -726,14 +734,18 @@ void testDisposeInactivePoolsInBackground(boolean enableEvictInBackground, boole assertThat(provider.isDisposed()).isEqualTo(enableEvictInBackground); if (meterRegistrar != null) { + if (enableEvictInBackground) { + assertThat(meterRegistrar.latch.await(30, TimeUnit.SECONDS)).isTrue(); + } assertThat(meterRegistrar.deRegistered.get()).isEqualTo(enableEvictInBackground); } else { if (enableEvictInBackground) { - assertGauge(registry, CONNECTION_PROVIDER_PREFIX + ACTIVE_CONNECTIONS, NAME, metricsName).isNull(); + assertThat(meterRemoved.await(30, TimeUnit.SECONDS)).isTrue(); + assertGauge(registry, metricsName, NAME, metricsTagName).isNull(); } else { - assertGauge(registry, CONNECTION_PROVIDER_PREFIX + ACTIVE_CONNECTIONS, NAME, metricsName).isNotNull(); + assertGauge(registry, metricsName, NAME, metricsTagName).isNotNull(); } } } @@ -869,6 +881,7 @@ void testHttp2PoolAndGoAway() { static final class MeterRegistrarImpl implements ConnectionProvider.MeterRegistrar { AtomicBoolean registered = new AtomicBoolean(); AtomicBoolean deRegistered = new AtomicBoolean(); + final CountDownLatch latch = new CountDownLatch(1); MeterRegistrarImpl() { } @@ -881,6 +894,7 @@ public void registerMetrics(String poolName, String id, SocketAddress remoteAddr @Override public void deRegisterMetrics(String poolName, String id, SocketAddress remoteAddress) { deRegistered.compareAndSet(false, true); + latch.countDown(); } } }