summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-03-10 06:06:00 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-03-10 06:06:00 +0000
commit9514ec5bec3dace261bd5e8041f8e9815233e143 (patch)
treef68dfea420ffbd6a000c49ec7d73f67846d2cbc9
parent5db248c0ef0804199f513357019cde0e6a46a209 (diff)
parent5a935ec573d06ffdf4db7fb7af4fa57cfaf8a2dd (diff)
downloadandroid_platform_testing-9514ec5bec3dace261bd5e8041f8e9815233e143.tar.gz
android_platform_testing-9514ec5bec3dace261bd5e8041f8e9815233e143.tar.bz2
android_platform_testing-9514ec5bec3dace261bd5e8041f8e9815233e143.zip
Make the teardown leeway in ScheduledScenarioRunner configurable. am: 5a935ec573
Change-Id: Ia345ce670c1fecb3dda8e92d828c8764e61ede2d
-rw-r--r--libraries/health/runners/longevity/platform/src/android/platform/test/longevity/ScheduledScenarioRunner.java23
-rw-r--r--libraries/health/runners/longevity/platform/tests/src/android/platform/test/longevity/ProfileSuiteTest.java3
-rw-r--r--libraries/health/runners/longevity/platform/tests/src/android/platform/test/longevity/ScheduledScenarioRunnerTest.java26
3 files changed, 40 insertions, 12 deletions
diff --git a/libraries/health/runners/longevity/platform/src/android/platform/test/longevity/ScheduledScenarioRunner.java b/libraries/health/runners/longevity/platform/src/android/platform/test/longevity/ScheduledScenarioRunner.java
index f76a0df1..ffd54fee 100644
--- a/libraries/health/runners/longevity/platform/src/android/platform/test/longevity/ScheduledScenarioRunner.java
+++ b/libraries/health/runners/longevity/platform/src/android/platform/test/longevity/ScheduledScenarioRunner.java
@@ -57,7 +57,10 @@ public class ScheduledScenarioRunner extends LongevityClassRunner {
// Please note that in most cases (when the CUJ does not time out) the actual cushion for
// teardown is double the value below, as a cushion needs to be created inside the timeout
// rule and also outside of it.
- @VisibleForTesting static final long TEARDOWN_LEEWAY_MS = 3000;
+ // This parameter is configurable via the command line as the teardown time varies across CUJs.
+ @VisibleForTesting static final String TEARDOWN_LEEWAY_OPTION = "teardown-window_ms";
+ @VisibleForTesting static final long TEARDOWN_LEEWAY_DEFAULT = 3000L;
+ private long mTeardownLeewayMs = TEARDOWN_LEEWAY_DEFAULT;
private static final String LOG_TAG = ScheduledScenarioRunner.class.getSimpleName();
@@ -86,9 +89,13 @@ public class ScheduledScenarioRunner extends LongevityClassRunner {
mTotalTimeoutMs = max(timeout, 0);
// Ensure that the enforced timeout is non-negative. This cushion is built in so that the
// CUJ still has time for teardown steps when the test portion times out.
- mEnforcedTimeoutMs = max(mTotalTimeoutMs - TEARDOWN_LEEWAY_MS, 0);
+ mEnforcedTimeoutMs = max(mTotalTimeoutMs - mTeardownLeewayMs, 0);
mShouldIdle = shouldIdle;
mArguments = arguments;
+ mTeardownLeewayMs =
+ Long.parseLong(
+ arguments.getString(
+ TEARDOWN_LEEWAY_OPTION, String.valueOf(mTeardownLeewayMs)));
}
@Override
@@ -109,9 +116,9 @@ public class ScheduledScenarioRunner extends LongevityClassRunner {
// Run the underlying test and report exceptions.
statement.evaluate();
} finally {
- // If there is time left for idling (i.e. more than TEARDOWN_LEEWAY_MS),
+ // If there is time left for idling (i.e. more than mTeardownLeewayMs),
// and the scenario is set to stay in app, idle for the remainder of
- // its timeout window until TEARDOWN_LEEWAY_MS before the start time of
+ // its timeout window until mTeardownLeewayMs before the start time of
// the next scenario, before executing the scenario's @After methods.
// The above does not apply if current scenario is the last one, in
// which case the idle is never performed regardless of its after_test
@@ -125,7 +132,7 @@ public class ScheduledScenarioRunner extends LongevityClassRunner {
performIdleBeforeTeardown(
max(
getTimeRemainingForTimeoutRule()
- - TEARDOWN_LEEWAY_MS,
+ - mTeardownLeewayMs,
0));
}
}
@@ -254,4 +261,10 @@ public class ScheduledScenarioRunner extends LongevityClassRunner {
context.unregisterReceiver(receiver);
}
}
+
+ /** Expose the teardown leeway since tests rely on it for verifying timing. */
+ @VisibleForTesting
+ long getTeardownLeeway() {
+ return mTeardownLeewayMs;
+ }
}
diff --git a/libraries/health/runners/longevity/platform/tests/src/android/platform/test/longevity/ProfileSuiteTest.java b/libraries/health/runners/longevity/platform/tests/src/android/platform/test/longevity/ProfileSuiteTest.java
index 14d66de3..8d7237d3 100644
--- a/libraries/health/runners/longevity/platform/tests/src/android/platform/test/longevity/ProfileSuiteTest.java
+++ b/libraries/health/runners/longevity/platform/tests/src/android/platform/test/longevity/ProfileSuiteTest.java
@@ -291,7 +291,8 @@ public class ProfileSuiteTest {
long expectedTimeout =
suiteTimeoutMsecs
- TimeUnit.SECONDS.toMillis(4)
- - ScheduledScenarioRunner.TEARDOWN_LEEWAY_MS;
+ - ScheduledScenarioRunner
+ .TEARDOWN_LEEWAY_DEFAULT;
return abs(exceptionTimeout - expectedTimeout)
<= SCHEDULE_LEEWAY_MS;
});
diff --git a/libraries/health/runners/longevity/platform/tests/src/android/platform/test/longevity/ScheduledScenarioRunnerTest.java b/libraries/health/runners/longevity/platform/tests/src/android/platform/test/longevity/ScheduledScenarioRunnerTest.java
index d36cc36f..78bc467c 100644
--- a/libraries/health/runners/longevity/platform/tests/src/android/platform/test/longevity/ScheduledScenarioRunnerTest.java
+++ b/libraries/health/runners/longevity/platform/tests/src/android/platform/test/longevity/ScheduledScenarioRunnerTest.java
@@ -141,8 +141,7 @@ public class ScheduledScenarioRunnerTest {
exception
.getTimeUnit()
.toMillis(exception.getTimeout());
- long expectedTimeout =
- timeoutMs - ScheduledScenarioRunner.TEARDOWN_LEEWAY_MS;
+ long expectedTimeout = timeoutMs - runner.getTeardownLeeway();
return abs(exceptionTimeout - expectedTimeout)
<= TIMING_LEEWAY_MS;
});
@@ -196,8 +195,7 @@ public class ScheduledScenarioRunnerTest {
// the leeway set in @{link ScheduledScenarioRunner}.
verify(runner, times(1))
.performIdleBeforeNextScenario(
- getWithinMarginMatcher(
- ScheduledScenarioRunner.TEARDOWN_LEEWAY_MS, TIMING_LEEWAY_MS));
+ getWithinMarginMatcher(runner.getTeardownLeeway(), TIMING_LEEWAY_MS));
}
/** Test that a test set to stay in the app after the test idles after its @Test method. */
@@ -226,8 +224,7 @@ public class ScheduledScenarioRunnerTest {
verify(runner, times(1))
.performIdleBeforeTeardown(
getWithinMarginMatcher(
- timeoutMs - 2 * ScheduledScenarioRunner.TEARDOWN_LEEWAY_MS,
- TIMING_LEEWAY_MS));
+ timeoutMs - 2 * runner.getTeardownLeeway(), TIMING_LEEWAY_MS));
// Test should have passed.
verify(mRunNotifier, never()).fireTestFailure(any(Failure.class));
}
@@ -389,6 +386,23 @@ public class ScheduledScenarioRunnerTest {
Assert.assertTrue(abs(actualSleepDuration - expectedSleepMillis) <= TIMING_LEEWAY_MS);
}
+ /** Test that the teardown leeway override works. */
+ @Test
+ public void testTeardownLeewayOverride() throws Throwable {
+ Bundle args = new Bundle();
+ long leewayOverride = 1000L;
+ args.putString(
+ ScheduledScenarioRunner.TEARDOWN_LEEWAY_OPTION, String.valueOf(leewayOverride));
+ ScheduledScenarioRunner runner =
+ new ScheduledScenarioRunner(
+ ArgumentTest.class,
+ Scenario.newBuilder().build(),
+ TimeUnit.SECONDS.toMillis(6),
+ false,
+ args);
+ Assert.assertEquals(leewayOverride, runner.getTeardownLeeway());
+ }
+
/**
* Helper method to get an argument matcher that checks whether the input value is equal to
* expected value within a margin.