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
---