Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky DefaultPooledConnectionProviderTest#testDisposeInactivePoolsInBackground #3237

Merged
merged 2 commits into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
}
}
}