Skip to content

Commit e979aeb

Browse files
committed
--adb-timeout parameter added
1 parent 343fe17 commit e979aeb

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ Options:
104104
--method-name Test method name to run (must also use --class-name)
105105
--no-animations Disable animated gif generation
106106
--size Only run test methods annotated by testSize (small, medium, large)
107+
--adb-timeout Set maximum execution time per test in seconds (10min default)
107108
```
108109

109110
If you are using Maven for compilation, a plugin is provided for easy execution.

spoon-runner/src/main/java/com/squareup/spoon/SpoonDeviceRunner.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
public final class SpoonDeviceRunner {
3939
private static final String FILE_EXECUTION = "execution.json";
4040
private static final String FILE_RESULT = "result.json";
41-
private static final int ADB_TIMEOUT = 10 * 60 * 1000; //10m
4241
static final String TEMP_DIR = "work";
4342
static final String JUNIT_DIR = "junit-reports";
4443

@@ -48,6 +47,7 @@ public final class SpoonDeviceRunner {
4847
private final String serial;
4948
private final boolean debug;
5049
private final boolean noAnimations;
50+
private final int adbTimeout;
5151
private final File output;
5252
private final String className;
5353
private final String methodName;
@@ -66,21 +66,23 @@ public final class SpoonDeviceRunner {
6666
* @param output Path to output directory.
6767
* @param serial Device to run the test on.
6868
* @param debug Whether or not debug logging is enabled.
69+
* @param adbTimeout time in ms for longest test execution
6970
* @param classpath Custom JVM classpath or {@code null}.
7071
* @param instrumentationInfo Test apk manifest information.
7172
* @param className Test class name to run or {@code null} to run all tests.
7273
* @param methodName Test method name to run or {@code null} to run all tests. Must also pass
7374
* {@code className}.
7475
*/
7576
SpoonDeviceRunner(File sdk, File apk, File testApk, File output, String serial, boolean debug,
76-
boolean noAnimations, String classpath, SpoonInstrumentationInfo instrumentationInfo,
77+
boolean noAnimations, int adbTimeout, String classpath, SpoonInstrumentationInfo instrumentationInfo,
7778
String className, String methodName, IRemoteAndroidTestRunner.TestSize testSize) {
7879
this.sdk = sdk;
7980
this.apk = apk;
8081
this.testApk = testApk;
8182
this.serial = serial;
8283
this.debug = debug;
8384
this.noAnimations = noAnimations;
85+
this.adbTimeout = adbTimeout;
8486
this.output = output;
8587
this.className = className;
8688
this.methodName = methodName;
@@ -178,7 +180,7 @@ public DeviceResult run(AndroidDebugBridge adb) {
178180
try {
179181
logDebug(debug, "About to actually run tests for [%s]", serial);
180182
RemoteAndroidTestRunner runner = new RemoteAndroidTestRunner(testPackage, testRunner, device);
181-
runner.setMaxtimeToOutputResponse(ADB_TIMEOUT);
183+
runner.setMaxtimeToOutputResponse(adbTimeout);
182184
if (!Strings.isNullOrEmpty(className)) {
183185
if (Strings.isNullOrEmpty(methodName)) {
184186
runner.setClassName(className);

spoon-runner/src/main/java/com/squareup/spoon/SpoonRunner.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
public final class SpoonRunner {
3131
private static final String DEFAULT_TITLE = "Spoon Execution";
3232
public static final String DEFAULT_OUTPUT_DIRECTORY = "spoon-output";
33+
private static final int DEFAULT_ADB_TIMEOUT = 10 * 60; //10 minutes
3334

3435
private final String title;
3536
private final File androidSdk;
@@ -38,14 +39,15 @@ public final class SpoonRunner {
3839
private final File output;
3940
private final boolean debug;
4041
private final boolean noAnimations;
42+
private final int adbTimeout;
4143
private final String className;
4244
private final String methodName;
4345
private final Set<String> serials;
4446
private final String classpath;
4547
private final IRemoteAndroidTestRunner.TestSize testSize;
4648

4749
private SpoonRunner(String title, File androidSdk, File applicationApk, File instrumentationApk,
48-
File output, boolean debug, boolean noAnimations, Set<String> serials, String classpath,
50+
File output, boolean debug, boolean noAnimations, int adbTimeout, Set<String> serials, String classpath,
4951
String className, String methodName, IRemoteAndroidTestRunner.TestSize testSize) {
5052
this.title = title;
5153
this.androidSdk = androidSdk;
@@ -54,6 +56,7 @@ private SpoonRunner(String title, File androidSdk, File applicationApk, File ins
5456
this.output = output;
5557
this.debug = debug;
5658
this.noAnimations = noAnimations;
59+
this.adbTimeout = adbTimeout;
5760
this.className = className;
5861
this.methodName = methodName;
5962
this.classpath = classpath;
@@ -191,7 +194,7 @@ static boolean parseOverallSuccess(SpoonSummary summary) {
191194

192195
private SpoonDeviceRunner getTestRunner(String serial, SpoonInstrumentationInfo testInfo) {
193196
return new SpoonDeviceRunner(androidSdk, applicationApk, instrumentationApk, output, serial,
194-
debug, noAnimations, classpath, testInfo, className, methodName, testSize);
197+
debug, noAnimations, adbTimeout, classpath, testInfo, className, methodName, testSize);
195198
}
196199

197200
/** Build a test suite for the specified devices and configuration. */
@@ -208,6 +211,7 @@ public static class Builder {
208211
private String methodName;
209212
private boolean noAnimations;
210213
private IRemoteAndroidTestRunner.TestSize testSize;
214+
private int adbTimeout;
211215

212216
/** Identifying title for this execution. */
213217
public Builder setTitle(String title) {
@@ -259,6 +263,12 @@ public Builder setNoAnimations(boolean noAnimations) {
259263
return this;
260264
}
261265

266+
/** Set ADB timeout. */
267+
public Builder setAdbTimeout(int value) {
268+
this.adbTimeout = value;
269+
return this;
270+
}
271+
262272
/** Add a device serial for test execution. */
263273
public Builder addDevice(String serial) {
264274
checkNotNull(serial, "Serial cannot be null.");
@@ -317,7 +327,7 @@ public SpoonRunner build() {
317327
}
318328

319329
return new SpoonRunner(title, androidSdk, applicationApk, instrumentationApk, output, debug,
320-
noAnimations, serials, classpath, className, methodName, testSize);
330+
noAnimations, adbTimeout, serials, classpath, className, methodName, testSize);
321331
}
322332
}
323333

@@ -357,6 +367,9 @@ static class CommandLineArgs {
357367
@Parameter(names = { "--no-animations" }, description = "Disable animated gif generation")
358368
public boolean noAnimations;
359369

370+
@Parameter(names = { "--adb-timeout" }, description = "Set maximum execution time per test in seconds (10min default)")
371+
public int adbTimeoutSeconds = DEFAULT_ADB_TIMEOUT;
372+
360373
@Parameter(names = { "--debug" }, hidden = true)
361374
public boolean debug;
362375

@@ -416,6 +429,7 @@ public static void main(String... args) {
416429
.setAndroidSdk(parsedArgs.sdk)
417430
.setNoAnimations(parsedArgs.noAnimations)
418431
.setTestSize(parsedArgs.size)
432+
.setAdbTimeout(parsedArgs.adbTimeoutSeconds * 1000)
419433
.setClassName(parsedArgs.className)
420434
.setMethodName(parsedArgs.methodName)
421435
.useAllAttachedDevices()

0 commit comments

Comments
 (0)