From cc92e1ee1d152c2b1c0410b7c5eedb858961326f Mon Sep 17 00:00:00 2001 From: Julien Desprez Date: Mon, 4 Jul 2016 16:43:07 +0100 Subject: Speed up some unit tests Gain of around 5 seconds in the unit test execution. Bug: 26383631 Change-Id: I2f2e6e6adf6db267b9a3adf4d9e9f2d3303f25d4 --- src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/com/android/tradefed/targetprep') diff --git a/src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java b/src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java index e0076aa14..96ec06979 100644 --- a/src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java +++ b/src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java @@ -23,6 +23,7 @@ import com.android.tradefed.log.LogUtil.CLog; import com.android.tradefed.util.CommandResult; import com.android.tradefed.util.CommandStatus; import com.android.tradefed.util.FileUtil; +import com.android.tradefed.util.IRunUtil; import com.android.tradefed.util.RunUtil; import com.android.tradefed.util.ZipUtil; @@ -565,7 +566,7 @@ public class FastbootDeviceFlasher implements IDeviceFlasher { attempts++; CLog.w("Could not find version for '%s'. Output '%s', retrying.", imageName, queryOutput); - RunUtil.getDefault().sleep(RETRY_SLEEP * (attempts - 1) + getRunUtil().sleep(RETRY_SLEEP * (attempts - 1) + new Random(System.currentTimeMillis()).nextInt(RETRY_SLEEP)); continue; } @@ -574,6 +575,13 @@ public class FastbootDeviceFlasher implements IDeviceFlasher { "Could not find version for '%s' after %d retry attempts", imageName, attempts)); } + /** + * Exposed for testing. + */ + protected IRunUtil getRunUtil() { + return RunUtil.getDefault(); + } + /** * Helper method to execute fastboot command. * -- cgit v1.2.3