kezhuw commented on code in PR #464: URL: https://github.com/apache/curator/pull/464#discussion_r1209685713
########## curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java: ########## @@ -945,6 +949,58 @@ public void testGetSequentialChildren() throws Exception } } + private static class AlwaysRetry implements RetryPolicy { + private final int retryIntervalMs; + + public AlwaysRetry(int retryIntervalMs) { + this.retryIntervalMs = retryIntervalMs; + } + + @Override + public boolean allowRetry(Throwable exception) { + return true; + } + + @Override + public boolean allowRetry(int retryCount, long elapsedTimeMs, RetrySleeper retrySleeper) { + try { + retrySleeper.sleepFor(retryIntervalMs, TimeUnit.MILLISECONDS); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + } + return true; + } + } + + @Test + public void testBackgroundClosing() throws Exception + { + AlwaysRetry alwaysRetry = new AlwaysRetry(2); + CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), alwaysRetry); + client.start(); + try { + // given: error background request with always-retry policy + CompletableFuture<CuratorEvent> future = new CompletableFuture<>(); + client.delete().inBackground((ignored, event) -> future.complete(event)).forPath("/test"); + + // These chaos steps create chances to run into concurrent contentions. + // They could fail this test given enough runs if there are bugs. Review Comment: I am reluctant and possibly incapable to mock internals here. And I have seen all paths routed to `CuratorFrameworkImpl::closeOperation` with these chaos steps in IDEA's "Repeat until failure", there are `close`, `queueOperation` and `requeueSleepOperation`. That's it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@curator.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org