Skip to content

Commit

Permalink
[FIXED JENKINS-10421] Use Proc.joinWithTimeout to prevent adb hangs.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgenpt authored and orrc committed Sep 8, 2011
1 parent 0515f6c commit 4cd68f5
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/main/java/hudson/plugins/android_emulator/AndroidEmulator.java
Expand Up @@ -28,6 +28,7 @@
import hudson.util.ForkOutputStream;
import hudson.util.FormValidation;
import hudson.util.NullStream;
import hudson.util.StreamTaskListener;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
Expand All @@ -42,6 +43,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -646,17 +648,21 @@ private boolean waitForBootCompletion(final PrintStream logger, final Launcher l
ByteArrayOutputStream stream = new ByteArrayOutputStream(4);

// Run "getprop"
launcher.launch().cmds(bootCheckCmd).stdout(stream).start().join();

// Check output
String result = stream.toString().trim();
if (result.equals("1")) {
return true;
Proc proc = launcher.launch().cmds(bootCheckCmd).stdout(stream).start();
long waitTimeout = timeout / 8;
int retVal = proc.joinWithTimeout(waitTimeout, TimeUnit.MILLISECONDS, StreamTaskListener.fromStderr());

if (retVal == 0) {
// Check output
String result = stream.toString().trim();
if (result.equals("1")) {
return true;
}

// Otherwise continue...
Thread.sleep(sleep);
}

// Otherwise continue...
Thread.sleep(sleep);

// Ensure the emulator is connected to adb, in case it had crashed
launcher.launch().cmds(connectCmd).start().join();
}
Expand Down

0 comments on commit 4cd68f5

Please sign in to comment.