Correctly update shutdown timeout after each step in connection manager shutdown

Signed-off-by: Martin Ek <martin.ek@insurely.com>
pull/5873/head
Martin Ek 9 months ago
parent 7b29c420de
commit 2ea7c51024
No known key found for this signature in database

@ -512,7 +512,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
long startTime = System.nanoTime();
serviceManager.shutdownFutures(quietPeriod, unit);
timeoutInNanos = Math.max(0, timeoutInNanos - System.nanoTime() - startTime);
timeoutInNanos = Math.max(0, timeoutInNanos - (System.nanoTime() - startTime));
if (isInitialized()) {
List<CompletableFuture<Void>> futures = new ArrayList<>();
@ -524,7 +524,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
try {
startTime = System.nanoTime();
future.get(timeoutInNanos, TimeUnit.NANOSECONDS);
timeoutInNanos = Math.max(0, timeoutInNanos - System.nanoTime() - startTime);
timeoutInNanos = Math.max(0, timeoutInNanos - (System.nanoTime() - startTime));
} catch (Exception e) {
// skip
}
@ -535,7 +535,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
try {
startTime = System.nanoTime();
serviceManager.getExecutor().awaitTermination(timeoutInNanos, TimeUnit.NANOSECONDS);
timeoutInNanos = Math.max(0, timeoutInNanos - System.nanoTime() - startTime);
timeoutInNanos = Math.max(0, timeoutInNanos - (System.nanoTime() - startTime));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}

@ -858,4 +858,18 @@ public class RedissonTest extends RedisDockerTest {
r.shutdown();
}
@Test
public void testShutdownQuietPeriod() {
// On a very slow system this may give false positives,
// but at the same time a longer timeout would make the test suite slower
long quietPeriod = TimeUnit.MILLISECONDS.toMillis(50);
long timeOut = quietPeriod + TimeUnit.SECONDS.toMillis(2);
RedissonClient r = createInstance();
long startTime = System.currentTimeMillis();
r.shutdown(quietPeriod, timeOut, TimeUnit.MILLISECONDS);
long shutdownTime = System.currentTimeMillis() - startTime;
Assertions.assertTrue(shutdownTime > quietPeriod);
}
}

Loading…
Cancel
Save