-
Notifications
You must be signed in to change notification settings - Fork 644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
- run 'stopContainer' in a Future (resolves #518) #528
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
import java.util.Arrays; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.concurrent.TimeoutException; | ||
import java.util.concurrent.*; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
|
@@ -25,6 +25,8 @@ | |
*/ | ||
public class WaitUtil { | ||
|
||
private static final int DEFAULT_DOCKER_TIMEOUT = 10; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 10s maybe a bit high as default, which is even used when no killGracePeriod is specified. In fact I wouldn't wait at all if no killGracePeriod is specified so simply skipping any wait when Any particular reason why you always want a wait when a shutdown happens ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't always want to wait - the docker container takes up to 10 seconds which is why i used that default. if it exited before then, the future would complete, so i don't think we were waiting any extra time w/ this. but whatever you think is best here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah - looking at your change, i'm not 100% sure that's correct either in terms of returning
if anything maybe it should be and now that i think about it, maybe that value should be padded by a second or two so we're sure we get the output back from the docker daemon. i think the only time there would be 'extra' waiting is if the docker daemon dies, and at that point you've got bigger problems. |
||
|
||
// how long to wait at max when doing a http ping | ||
private static final long DEFAULT_MAX_WAIT = 10 * 1000; | ||
|
||
|
@@ -48,6 +50,24 @@ public class WaitUtil { | |
|
||
private WaitUtil() {} | ||
|
||
public static long wait(int wait, Callable<Void> callable) throws ExecutionException, WaitTimeoutException { | ||
long now = System.currentTimeMillis(); | ||
wait = (wait == 0) ? DEFAULT_DOCKER_TIMEOUT : wait; | ||
|
||
try { | ||
FutureTask<Void> task = new FutureTask<>(callable); | ||
task.run(); | ||
|
||
task.get(wait, TimeUnit.SECONDS); | ||
} catch (@SuppressWarnings("unused") InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
} catch (@SuppressWarnings("unused") TimeoutException e) { | ||
throw new WaitTimeoutException("timed out waiting for execution to complete", delta(now)); | ||
} | ||
|
||
return delta(now); | ||
} | ||
|
||
public static long wait(int maxWait, WaitChecker ... checkers) throws WaitTimeoutException { | ||
return wait(maxWait, Arrays.asList(checkers)); | ||
} | ||
|
@@ -89,6 +109,7 @@ public static void sleep(long millis) { | |
Thread.sleep(millis); | ||
} catch (InterruptedException e) { | ||
// ... | ||
Thread.currentThread().interrupt(); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There will be only a wait if killGracePeriod is > 0. I think we should do the same with the new logic, which means when no wait specified we shouldn't wait at all.