Skip to content

Commit

Permalink
[test] Fix flaky DefaultPooledConnectionProviderTest#testDisposeInact…
Browse files Browse the repository at this point in the history
…ivePoolsInBackground

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 committed May 9, 2024
1 parent 066a645 commit 7620206
Showing 1 changed file with 21 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,10 +719,14 @@ 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) {
if (meterRegistrar != null) {
provider.onDispose.subscribe(null, null, meterRemoved::countDown);
}

assertThat(latch.await(5, TimeUnit.SECONDS)).isTrue();
}

Expand All @@ -726,14 +738,18 @@ void testDisposeInactivePoolsInBackground(boolean enableEvictInBackground, boole

assertThat(provider.isDisposed()).isEqualTo(enableEvictInBackground);
if (meterRegistrar != null) {
if (enableEvictInBackground) {
assertThat(meterRemoved.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

0 comments on commit 7620206

Please sign in to comment.