aboutsummaryrefslogtreecommitdiff
path: root/tests/vehiclehal_test
diff options
context:
space:
mode:
authorPavel Maltsev <pavelm@google.com>2017-09-20 13:57:00 -0700
committerPavel Maltsev <pavelm@google.com>2017-09-20 13:57:00 -0700
commitbe9a410995eb05c4a89efd709b55b627a46a796c (patch)
tree9459af2811631d6177979081b48eb4198d8acc4d /tests/vehiclehal_test
parent632840e8eb702b7c674e8f653091b2c2da5283a1 (diff)
downloadCar-be9a410995eb05c4a89efd709b55b627a46a796c.tar.gz
Fixed flaky e2e performance test
Run stress test multiple times to make sure at least one attempt succeed before giving up. Bug: 65944764 Test: runtest -x packages/services/Car/tests/vehiclehal_test Change-Id: I9a4a6dc0a3fdcc85270d52441b6bd20846177d3d
Diffstat (limited to 'tests/vehiclehal_test')
-rw-r--r--tests/vehiclehal_test/src/com/android/car/vehiclehal/test/E2ePerformanceTest.java28
1 files changed, 24 insertions, 4 deletions
diff --git a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/E2ePerformanceTest.java b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/E2ePerformanceTest.java
index 6675713f47..196a6d47f1 100644
--- a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/E2ePerformanceTest.java
+++ b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/E2ePerformanceTest.java
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
import android.annotation.Nullable;
@@ -47,6 +48,7 @@ import android.os.SystemClock;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.MediumTest;
+import android.util.Log;
import android.util.SparseArray;
import android.util.SparseIntArray;
@@ -259,6 +261,27 @@ public class E2ePerformanceTest {
final int EXPECTED_INVOCATIONS = 1000; // How many time get/set will be called.
final int EXPECTED_DURATION_MS = 2500;
+ // This is a stress test and it can be flaky because it shares resources with all currently
+ // running process. Let's have this number of attempt before giving up.
+ final int ATTEMPTS = 3;
+
+ for (int curAttempt = 0; curAttempt < ATTEMPTS; curAttempt++) {
+ long missingInvocations = stressTestHvacProperties(mgr, cfg,
+ EXPECTED_INVOCATIONS, EXPECTED_DURATION_MS);
+ if (missingInvocations == 0) return; // All done.
+
+ Log.w(TAG, "Failed to invoke get/set " + EXPECTED_INVOCATIONS
+ + " within " + EXPECTED_DURATION_MS + "ms"
+ + ", actually invoked: "
+ + (EXPECTED_INVOCATIONS - missingInvocations));
+ }
+ fail("Failed to invoke get/set " + EXPECTED_INVOCATIONS + " within "
+ + EXPECTED_DURATION_MS + "ms. Number of attempts: " + ATTEMPTS
+ + ". See logs for details.");
+ }
+
+ private long stressTestHvacProperties(CarHvacManager mgr, CarPropertyConfig<Float> cfg,
+ int EXPECTED_INVOCATIONS, int EXPECTED_DURATION_MS) throws InterruptedException {
CountDownLatch counter = new CountDownLatch(EXPECTED_INVOCATIONS);
List<Thread> threads = new ArrayList<>(Lists.newArrayList(
@@ -271,15 +294,12 @@ public class E2ePerformanceTest {
counter.await(EXPECTED_DURATION_MS, TimeUnit.MILLISECONDS);
long missingInvocations = counter.getCount();
- assertTrue("Failed to invoke get/set " + EXPECTED_INVOCATIONS
- + " within " + EXPECTED_DURATION_MS + "ms"
- + ", actually invoked: " + (EXPECTED_INVOCATIONS - missingInvocations),
- missingInvocations == 0);
for (Thread t : threads) {
t.join(10000); // Let thread join to not interfere with other test.
assertFalse(t.isAlive());
}
+ return missingInvocations;
}
private void invokeSetAndGetForHvacFloat(CarHvacManager mgr,