From aa381d3b4800b5e004afb3d7dfbb5819ca175d6c Mon Sep 17 00:00:00 2001 From: Lee Shombert Date: Thu, 3 Oct 2024 12:36:44 -0700 Subject: Correct an ApplicationSharedMemory unit test The test `ApplicationSharedMemory.canRead()` verifies that the network time can be read from shared memory. The read will throw if the time is not initialized, either because there is no time source or because the feature that writes to shared memory is disabled. This change accepts the particular `DateTimeException`. Note that an exception is thrown only if the memory was actually read, which means the test passed. Flag: EXEMPT test-only Bug: 365575551 Test: atest * ApplicationSharedMemoryTest32 Change-Id: I455cb5b6e8b8a04557929495dfda8979f9da8e89 --- .../src/com/android/internal/os/ApplicationSharedMemoryTest.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/Internal/src/com/android/internal/os/ApplicationSharedMemoryTest.java b/tests/Internal/src/com/android/internal/os/ApplicationSharedMemoryTest.java index e3a129fb1059..d03ad5cb2877 100644 --- a/tests/Internal/src/com/android/internal/os/ApplicationSharedMemoryTest.java +++ b/tests/Internal/src/com/android/internal/os/ApplicationSharedMemoryTest.java @@ -61,8 +61,13 @@ public class ApplicationSharedMemoryTest { @Test public void canRead() { ApplicationSharedMemory instance = ApplicationSharedMemory.getInstance(); - instance.getLatestNetworkTimeUnixEpochMillisAtZeroElapsedRealtimeMillis(); - // Don't actually care about the value of the above. + try { + instance.getLatestNetworkTimeUnixEpochMillisAtZeroElapsedRealtimeMillis(); + // Don't actually care about the value of the above. + } catch (java.time.DateTimeException e) { + // This exception is okay during testing. It means there was no time source, which + // could be because of network problems or a feature being flagged off. + } } /** Application processes should not have mutable access. */ -- cgit v1.2.3-59-g8ed1b