diff options
author | Remi NGUYEN VAN <reminv@google.com> | 2024-04-02 16:11:17 +0900 |
---|---|---|
committer | Remi NGUYEN VAN <reminv@google.com> | 2024-04-04 19:35:52 +0900 |
commit | 7b5fb34f578a0aa50b69e3f4b53540b1c5ade0f0 (patch) | |
tree | f8f0e77a806e53adcbc2260a94033489de57c7a6 | |
parent | 4f5147d266435bcaedd5fe9f31a092a70de1e7bf (diff) | |
download | CaptivePortalLogin-7b5fb34f578a0aa50b69e3f4b53540b1c5ade0f0.tar.gz |
Add file exists logs to testDownloadFile
Some test runs are failing with "FileNotFoundException: open failed:
ENOENT" on openFileDescriptor in DownloadService. As the root cause is
not clear, add some logs to try to narrow down whether the file really
does not exist, and where it disappears when it does not exist.
Bug: 317602748
Test: atest
Change-Id: Ib67fb4a56283e7131da0b33b5cda390aa5cd668e
-rw-r--r-- | tests/src/com/android/captiveportallogin/DownloadServiceTest.kt | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/tests/src/com/android/captiveportallogin/DownloadServiceTest.kt b/tests/src/com/android/captiveportallogin/DownloadServiceTest.kt index 3946fe1..077e27e 100644 --- a/tests/src/com/android/captiveportallogin/DownloadServiceTest.kt +++ b/tests/src/com/android/captiveportallogin/DownloadServiceTest.kt @@ -28,6 +28,7 @@ import android.os.Bundle import android.os.IBinder import android.os.Parcel import android.os.Parcelable +import android.util.Log import android.widget.TextView import androidx.core.content.FileProvider import androidx.test.core.app.ActivityScenario @@ -102,6 +103,8 @@ private val NOTIFICATION_SCROLL_POLL_MS = 100L private val TEST_WIFI_CONFIG_TYPE = "application/x-wifi-config" +private val TAG = DownloadServiceTest::class.simpleName + @Rule val mServiceRule = ServiceTestRule() @@ -253,7 +256,8 @@ class DownloadServiceTest { while (true) { val file = File(testFilePath, "tmp$index$extension") if (!file.exists()) { - file.createNewFile() + // createNewFile only returns false if the file already exists (it throws on error) + assertTrue(file.createNewFile(), "$file was created after exists() check") return file } index++ @@ -280,15 +284,26 @@ class DownloadServiceTest { val testFile1 = createTestFile() val testFile2 = createTestFile() + assertTrue(testFile1.exists(), "$testFile1 did not exist after creation") + assertTrue(testFile2.exists(), "$testFile2 did not exist after creation") + assertNotEquals(testFile1.name, testFile2.name) openNotificationShade() + assertTrue(testFile1.exists(), "$testFile1 did not exist before starting download") + assertTrue(testFile2.exists(), "$testFile2 did not exist before starting download") + // Queue both downloads immediately: they should be started in order val binder = bindService(makeDownloadCompleteCallback()) startDownloadTask(binder, testFile1, TEST_TEXT_FILE_TYPE) startDownloadTask(binder, testFile2, TEST_TEXT_FILE_TYPE) - verify(connection, timeout(TEST_TIMEOUT_MS)).inputStream + try { + verify(connection, timeout(TEST_TIMEOUT_MS)).inputStream + } finally { + Log.i(TAG, "testFile1 exists after connecting: ${testFile1.exists()}") + Log.i(TAG, "testFile2 exists after connecting: ${testFile2.exists()}") + } val dlText1 = resources.getString(R.string.downloading_paramfile, testFile1.name) findNotification(UiSelector().textContains(dlText1)) |