diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/redis/FaultTolerantRedisClientTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/redis/FaultTolerantRedisClientTest.java index e70aa18d8..2d34a23d9 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/redis/FaultTolerantRedisClientTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/redis/FaultTolerantRedisClientTest.java @@ -1,26 +1,24 @@ package org.whispersystems.textsecuregcm.redis; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertThrows; + import io.github.resilience4j.circuitbreaker.CallNotPermittedException; import io.lettuce.core.RedisCommandTimeoutException; import io.lettuce.core.RedisException; import io.lettuce.core.resource.ClientResources; +import java.time.Duration; +import java.util.Optional; +import java.util.concurrent.ExecutionException; +import javax.annotation.Nullable; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import org.junit.jupiter.api.extension.RegisterExtension; import org.whispersystems.textsecuregcm.configuration.CircuitBreakerConfiguration; import org.whispersystems.textsecuregcm.configuration.RetryConfiguration; -import javax.annotation.Nullable; -import java.time.Duration; -import java.util.Optional; -import java.util.concurrent.ExecutionException; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import static org.junit.jupiter.api.Assertions.assertThrows; - // ThreadMode.SEPARATE_THREAD protects against hangs in the remote Redis calls, as this mode allows the test code to be // preempted by the timeout check @Timeout(value = 5, threadMode = Timeout.ThreadMode.SEPARATE_THREAD) @@ -60,13 +58,13 @@ class FaultTolerantRedisClientTest { faultTolerantRedisClient = buildRedisClient(null, ClientResources.builder()); final ExecutionException asyncException = assertThrows(ExecutionException.class, - () -> faultTolerantRedisClient.withConnection(connection -> connection.async().blpop(2 * TIMEOUT.toMillis() / 1000d, "key")) + () -> faultTolerantRedisClient.withConnection(connection -> connection.async().blpop(10 * TIMEOUT.toMillis() / 1000d, "key")) .get()); assertInstanceOf(RedisCommandTimeoutException.class, asyncException.getCause()); assertThrows(RedisCommandTimeoutException.class, - () -> faultTolerantRedisClient.withConnection(connection -> connection.sync().blpop(2 * TIMEOUT.toMillis() / 1000d, "key"))); + () -> faultTolerantRedisClient.withConnection(connection -> connection.sync().blpop(10 * TIMEOUT.toMillis() / 1000d, "key"))); } @Test @@ -87,11 +85,11 @@ class FaultTolerantRedisClientTest { // the first call should time out and open the breaker assertThrows(RedisCommandTimeoutException.class, - () -> faultTolerantRedisClient.withConnection(connection -> connection.sync().blpop(2 * TIMEOUT.toMillis() / 1000d, key))); + () -> faultTolerantRedisClient.withConnection(connection -> connection.sync().blpop(10 * TIMEOUT.toMillis() / 1000d, key))); // the second call gets blocked by the breaker final RedisException e = assertThrows(RedisException.class, - () -> faultTolerantRedisClient.withConnection(connection -> connection.sync().blpop(2 * TIMEOUT.toMillis() / 1000d, key))); + () -> faultTolerantRedisClient.withConnection(connection -> connection.sync().blpop(10 * TIMEOUT.toMillis() / 1000d, key))); assertInstanceOf(CallNotPermittedException.class, e.getCause()); // wait for breaker to be half-open