Deflake HealthConnectThreadSchedulerTest
- Decrease the delay used in a test to reduce the test time
- Change the assertion to be isAtLeast instead of isGreaterThan to account for the possibility of the task starting exactly after the time period.
- Change the assertion to be isAtMost instead of isLessThan to account for the case when it take exactly that long to finish.
Bug: 415847542
Test: unit test
Change-Id: Ic7e6477e5744f7cee3dfb0b381bcbc6bc49ff95c
Flag: TEST_ONLY
diff --git a/tests/unittests/src/com/android/server/healthconnect/HealthConnectThreadSchedulerTest.java b/tests/unittests/src/com/android/server/healthconnect/HealthConnectThreadSchedulerTest.java
index eb7455f..8bbad16 100644
--- a/tests/unittests/src/com/android/server/healthconnect/HealthConnectThreadSchedulerTest.java
+++ b/tests/unittests/src/com/android/server/healthconnect/HealthConnectThreadSchedulerTest.java
@@ -146,7 +146,7 @@
@Test
public void testSchedulePassiveTrackerTaskWithDelay() throws Exception {
- long delayMillis = 30000;
+ long delayMillis = 3000;
Instant startTime = Instant.now();
ScheduledFuture<?> future =
@@ -156,9 +156,9 @@
future.get(); // Wait for the task to run and complete
long durationMillis = ChronoUnit.MILLIS.between(startTime, Instant.now());
- assertThat(durationMillis).isGreaterThan(delayMillis); // Task should start after the delay
+ assertThat(durationMillis).isAtLeast(delayMillis - 1000); // Task should start after a delay
assertThat(durationMillis)
- .isLessThan(
+ .isAtMost(
delayMillis
+ 3000); // Task shouldn't take too long to finish after the delay
}