From c202da86bab3465652d0b2ca73eb08bfe277e71b Mon Sep 17 00:00:00 2001 From: Andrei Onea Date: Mon, 25 Jan 2021 16:47:40 +0000 Subject: [PATCH] Improve flakiness of PlatformCompatGating test The PlatformCompatGating test did not close the ParcelFileDescriptor opened by UIAutomation.executeShellCommand, which is the likely culprit of the test throwing a java.io.InterruptedIOException randomly. The documentation for executeShellCommand requires the users to do the cleanup themselves. Test: atest PlatformCompatGating Bug: 178108878 Change-Id: Iaf4d82d5fe4170931d2c59f2978e545b15e940b0 --- .../tests/gating/PlatformCompatCommandNotInstalledTest.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/PlatformCompatGating/src/com/android/tests/gating/PlatformCompatCommandNotInstalledTest.kt b/tests/PlatformCompatGating/src/com/android/tests/gating/PlatformCompatCommandNotInstalledTest.kt index e9227e94da988..eb04f69077482 100644 --- a/tests/PlatformCompatGating/src/com/android/tests/gating/PlatformCompatCommandNotInstalledTest.kt +++ b/tests/PlatformCompatGating/src/com/android/tests/gating/PlatformCompatCommandNotInstalledTest.kt @@ -131,6 +131,10 @@ class PlatformCompatCommandNotInstalledTest { assertThat(platformCompat.isChangeEnabled(TEST_CHANGE_ID, appInfo)).isEqualTo(params.result) } - private fun command(command: String) = - FileReader(uiAutomation.executeShellCommand(command).fileDescriptor).readText() + private fun command(command: String): String { + val fileDescriptor = uiAutomation.executeShellCommand(command) + return String(ParcelFileDescriptor.AutoCloseInputStream(fileDescriptor).use { + inputStream -> inputStream.readBytes() + }) + } }