This is an automated email from the ASF dual-hosted git repository. lhotari pushed a commit to branch branch-4.2 in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit d93426e0a45091e77d3bb52d4a8ac1f1fc175352 Author: Oneby Wang <[email protected]> AuthorDate: Mon May 25 15:06:40 2026 +0800 [fix][test] Stabilize WebService rate limiting test (#25866) (cherry picked from commit 3b6a76096740870e87c93919b21ddbd1ee2cdeed) --- .../apache/pulsar/broker/web/WebServiceTest.java | 24 ++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/web/WebServiceTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/web/WebServiceTest.java index 0f9ccdf4af7..c307eb9b1ae 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/web/WebServiceTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/web/WebServiceTest.java @@ -269,7 +269,8 @@ public class WebServiceTest { @Test public void testRateLimiting() throws Exception { - setupEnv(false, false, false, false, 10.0, false); + double rateLimit = 10.0; + setupEnv(false, false, false, false, rateLimit, false); // setupEnv makes HTTP calls to create the cluster, tenant, and namespace. var metrics = pulsarTestContext.getOpenTelemetryMetricReader().collectAllMetrics(); @@ -283,7 +284,7 @@ public class WebServiceTest { // Make requests without exceeding the max rate for (int i = 0; i < 5; i++) { makeHttpRequest(false, false); - Thread.sleep(200); + Thread.sleep(rateLimitPauseMillis(rateLimit)); } metrics = pulsarTestContext.getOpenTelemetryMetricReader().collectAllMetrics(); @@ -573,13 +574,32 @@ public class WebServiceTest { } catch (ConflictException ce) { // This is OK. } + sleepForRateLimiter(rateLimit); + try { pulsarAdmin.tenants().createTenant("my-property", TenantInfo.builder().allowedClusters(Sets.newHashSet(config.getClusterName())).build()); + } catch (Exception e) { + // This is OK. + } + sleepForRateLimiter(rateLimit); + + try { pulsarAdmin.namespaces().createNamespace("my-property/my-namespace"); } catch (Exception e) { // This is OK. } + sleepForRateLimiter(rateLimit); + } + + private static void sleepForRateLimiter(double rateLimit) throws InterruptedException { + if (rateLimit > 0) { + Thread.sleep(rateLimitPauseMillis(rateLimit)); + } + } + + private static long rateLimitPauseMillis(double rateLimit) { + return (long) Math.ceil((1000.0 / rateLimit) * 2); } @AfterMethod(alwaysRun = true)
