From 588d04b25b94e9318a68e7801fe34ee5b5d7e0f0 Mon Sep 17 00:00:00 2001 From: Leah Thomas Date: Wed, 9 Mar 2022 10:30:11 -0600 Subject: [PATCH] fix: update rate limiting test so it's not flaky --- .../computation/DistributingExecutorTest.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/ksqldb-rest-app/src/test/java/io/confluent/ksql/rest/server/computation/DistributingExecutorTest.java b/ksqldb-rest-app/src/test/java/io/confluent/ksql/rest/server/computation/DistributingExecutorTest.java index 931cb34f81bb..5c228ca63003 100644 --- a/ksqldb-rest-app/src/test/java/io/confluent/ksql/rest/server/computation/DistributingExecutorTest.java +++ b/ksqldb-rest-app/src/test/java/io/confluent/ksql/rest/server/computation/DistributingExecutorTest.java @@ -506,7 +506,7 @@ CommonCreateConfigs.VALUE_FORMAT_PROPERTY, new StringLiteral("json") public void shouldThrowIfRateLimitHit() { // Given: final DistributingExecutor rateLimitedDistributor = new DistributingExecutor( - new KsqlConfig(ImmutableMap.of(KsqlRestConfig.KSQL_COMMAND_TOPIC_RATE_LIMIT_CONFIG, 0.5)), + new KsqlConfig(ImmutableMap.of(KsqlRestConfig.KSQL_COMMAND_TOPIC_RATE_LIMIT_CONFIG, 0.25)), queue, DURATION_10_MS, (ec, sc) -> InjectorChain.of(schemaInjector, topicInjector), @@ -521,13 +521,20 @@ public void shouldThrowIfRateLimitHit() { // Then: - final KsqlRestException e = assertThrows( - KsqlRestException.class, - () -> rateLimitedDistributor.execute(CONFIGURED_STATEMENT, executionContext, securityContext) - ); - - assertEquals(e.getResponse().getStatus(), 429); - final KsqlErrorMessage errorMessage = (KsqlErrorMessage) e.getResponse().getEntity(); - assertTrue(errorMessage.getMessage().contains("DDL/DML rate is crossing the configured rate limit of statements/second")); + boolean exceptionFound = false; + try { + rateLimitedDistributor.execute(CONFIGURED_STATEMENT, executionContext, securityContext); + rateLimitedDistributor.execute(CONFIGURED_STATEMENT, executionContext, securityContext); + rateLimitedDistributor.execute(CONFIGURED_STATEMENT, executionContext, securityContext); + rateLimitedDistributor.execute(CONFIGURED_STATEMENT, executionContext, securityContext); + } catch (Exception e) { + assertTrue(e instanceof KsqlRestException); + final KsqlRestException restException = (KsqlRestException) e; + assertEquals(restException.getResponse().getStatus(), 429); + final KsqlErrorMessage errorMessage = (KsqlErrorMessage) restException.getResponse().getEntity(); + assertTrue(errorMessage.getMessage().contains("DDL/DML rate is crossing the configured rate limit of statements/second")); + exceptionFound = true; + } + assertTrue(exceptionFound); } }