zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eolivelli <...@git.apache.org>
Subject [GitHub] zookeeper pull request #628: ZOOKEEPER-3140: Allow Followers to host Observe...
Date Sat, 15 Sep 2018 20:03:34 GMT
Github user eolivelli commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/628#discussion_r217894081
  
    --- Diff: src/java/test/org/apache/zookeeper/ZKTestCase.java ---
    @@ -75,4 +76,29 @@ public void failed(Throwable e, FrameworkMethod method) {
     
         };
     
    +    public interface WaitForCondition {
    +        /**
    +         * @return true when success
    +         */
    +        boolean evaluate();
    +    }
    +
    +    /**
    +     * Wait for condition to be true; otherwise fail the test if it exceed
    +     * timeout
    +     * @param msg       error message to print when fail
    +     * @param condition condition to evaluate
    +     * @param timeout   timeout in seconds
    +     * @throws InterruptedException
    +     */
    +    public void waitFor(String msg, WaitForCondition condition, int timeout)
    +            throws InterruptedException {
    +        for (int i = 0; i < timeout; ++i) {
    +            if (condition.evaluate()) {
    +                return;
    +            }
    +            Thread.sleep(1000);
    --- End diff --
    
    I also have such kind of facility in other projects, would it be better to have a inner
timeout of 100ms? This may save time


---

Mime
View raw message