Skip to content

Commit

Permalink
Fix flaky DefaultPooledConnectionProviderTest#testDisposeInactivePool…
Browse files Browse the repository at this point in the history
…sInBackground (#3237)

There are random DefaultPooledConnectionProviderTest#testDisposeInactivePoolsInBackground failures

DefaultPooledConnectionProviderTest > testDisposeInactivePoolsInBackground(boolean, boolean, boolean) > [5] enableEvictInBackground=true, isHttp2=false, isBuiltInMetrics=false FAILED
    org.opentest4j.AssertionFailedError:
    expected: true
     but was: false
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at reactor.netty.resources.DefaultPooledConnectionProviderTest.testDisposeInactivePoolsInBackground(DefaultPooledConnectionProviderTest.java:729)

DefaultPooledConnectionProviderTest > testDisposeInactivePoolsInBackground(boolean, boolean, boolean) > [8] enableEvictInBackground=true, isHttp2=true, isBuiltInMetrics=true FAILED
    org.opentest4j.AssertionFailedError:
    expected: null
     but was: io.micrometer.core.instrument.internal.DefaultGauge@78e01239
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at reactor.netty.resources.DefaultPooledConnectionProviderTest.testDisposeInactivePoolsInBackground(DefaultPooledConnectionProviderTest.java:733)
  • Loading branch information
violetagg authored May 13, 2024
1 parent 1546625 commit dca81cb
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}
}
}
Expand Down Expand Up @@ -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() {
}
Expand All @@ -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();
}
}
}

0 comments on commit dca81cb

Please sign in to comment.