From 25e20bd4b91ea5f92b6d35d7e8b4290ea8cc544d Mon Sep 17 00:00:00 2001 From: meiyi Date: Wed, 29 Jul 2026 15:35:56 +0800 Subject: [PATCH] [fix](fe) Make MetaServiceProxy rate-limit test deterministic ### What problem does this PR solve? Issue Number: None Related PR: #66219 Problem Summary: MetaServiceProxyTest exhausted rate-limit permits through repeated calls with a one-second refresh period, so scheduler delays could replenish permits and make the assertion flaky. Consume the configured limit for a longer burst window with one weighted request, derive that weight explicitly from the QPS and burst settings, and return immediately completed mocked futures so async callbacks do not remain pending. ### Release note None ### Check List (For Author) - Test: Unit Test - `./run-fe-ut.sh --run org.apache.doris.cloud.rpc.MetaServiceProxyTest` (11 tests passed on the development machine) - FE Checkstyle passed with 0 violations - Behavior changed: No - Does this need documentation: No --- .../doris/cloud/rpc/MetaServiceProxyTest.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/fe/fe-core/src/test/java/org/apache/doris/cloud/rpc/MetaServiceProxyTest.java b/fe/fe-core/src/test/java/org/apache/doris/cloud/rpc/MetaServiceProxyTest.java index 7638bfa774d581..d790d091fc2792 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/cloud/rpc/MetaServiceProxyTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/cloud/rpc/MetaServiceProxyTest.java @@ -22,6 +22,7 @@ import org.apache.doris.common.jmockit.Deencapsulation; import org.apache.doris.rpc.RpcException; +import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.SettableFuture; import org.junit.After; import org.junit.Assert; @@ -315,11 +316,18 @@ public void testGetInstanceRateLimitedBeforeRpc() throws RpcException { @Test public void testGetVisibleVersionAsyncRateLimitedBeforeRpc() throws RpcException { - enableRateLimit(1, "", 1, 0); + // Consume limitForPeriod = qpsPerCore * CPU_CORES * burstSeconds in one weighted request. + // A long burst window also prevents a refresh before the assertion if the scheduler stalls. + int qpsPerCore = 1; + int rateLimitBurstSeconds = 60; + int limitForPeriod = qpsPerCore * CPU_CORES * rateLimitBurstSeconds; + enableRateLimit(qpsPerCore, "", rateLimitBurstSeconds, 0); MetaServiceProxy proxy = new MetaServiceProxy(); MetaServiceClient client = mockNormalClient(); putClient(proxy, client); - consumeRateLimitPermits(proxy, "getPartitionVersion"); + Mockito.when(client.getVisibleVersionAsync(Mockito.any())) + .thenReturn(Futures.immediateFuture(okGetVersionResponse())); + proxy.getVisibleVersionAsync(buildBatchPartitionVersionRequest(limitForPeriod)); try { proxy.getVisibleVersionAsync(Cloud.GetVersionRequest.newBuilder().build()); @@ -328,7 +336,7 @@ public void testGetVisibleVersionAsyncRateLimitedBeforeRpc() throws RpcException Assert.assertTrue(e.getMessage().contains("meta service rpc rate limited")); } - Mockito.verify(client, Mockito.never()).getVisibleVersionAsync(Mockito.any()); + Mockito.verify(client, Mockito.times(1)).getVisibleVersionAsync(Mockito.any()); Mockito.verify(client, Mockito.never()).shutdown(Mockito.anyBoolean()); } @@ -338,8 +346,8 @@ public void testBatchGetVisibleVersionAsyncConsumesMultipleRateLimitPermits() th MetaServiceProxy proxy = new MetaServiceProxy(); MetaServiceClient client = mockNormalClient(); putClient(proxy, client); - SettableFuture future = SettableFuture.create(); - Mockito.when(client.getVisibleVersionAsync(Mockito.any())).thenReturn(future); + Mockito.when(client.getVisibleVersionAsync(Mockito.any())) + .thenReturn(Futures.immediateFuture(okGetVersionResponse())); proxy.getVisibleVersionAsync(buildBatchTableVersionRequest(CPU_CORES));