Fixed ProviderTestUtils.
- Increased ProviderTestUtils.IO_TIMEOUT to 2s (100ms was not long enough without retries).
- Removed file existance check from stageDir() (as that method does not create the directory).
Fixes: 134372686
Test: atest CtsProviderTestCases
Change-Id: I27997861a3ae6146a553da0e020bbac72568c95b
diff --git a/tests/tests/provider/src/android/provider/cts/MediaStore_Images_MediaTest.java b/tests/tests/provider/src/android/provider/cts/MediaStore_Images_MediaTest.java
index 9c72e41..a343c76 100644
--- a/tests/tests/provider/src/android/provider/cts/MediaStore_Images_MediaTest.java
+++ b/tests/tests/provider/src/android/provider/cts/MediaStore_Images_MediaTest.java
@@ -229,7 +229,9 @@
cleanExternalMediaFile(externalPath2);
int numBytes = 1337;
- FileUtils.createFile(new File(externalPath), numBytes);
+ File file = new File(externalPath);
+ FileUtils.createFile(file, numBytes);
+ ProviderTestUtils.waitUntilExists(file);
ContentValues values = new ContentValues();
values.put(Media.ORIENTATION, 0);
@@ -281,7 +283,7 @@
} finally {
// delete
assertEquals(1, mContentResolver.delete(uri, null, null));
- new File(externalPath).delete();
+ file.delete();
}
}
diff --git a/tests/tests/provider/src/android/provider/cts/ProviderTestUtils.java b/tests/tests/provider/src/android/provider/cts/ProviderTestUtils.java
index a106a1c..b2db009 100644
--- a/tests/tests/provider/src/android/provider/cts/ProviderTestUtils.java
+++ b/tests/tests/provider/src/android/provider/cts/ProviderTestUtils.java
@@ -72,7 +72,7 @@
private static final Pattern PATTERN_STORAGE_PATH = Pattern.compile(
"(?i)^/storage/[^/]+/(?:[0-9]+/)?");
- private static final Timeout IO_TIMEOUT = new Timeout("IO_TIMEOUT", 100, 2, 2_000);
+ private static final Timeout IO_TIMEOUT = new Timeout("IO_TIMEOUT", 2_000, 2, 2_000);
static Iterable<String> getSharedVolumeNames() {
// We test both new and legacy volume names
@@ -186,7 +186,7 @@
*
* @return existing file.
*/
- private static File waitUntilExists(File file) throws IOException {
+ public static File waitUntilExists(File file) throws IOException {
try {
return IO_TIMEOUT.run("file '" + file + "' doesn't exist yet", () -> {
return file.exists() ? file : null; // will retry if it returns null
@@ -203,7 +203,7 @@
File dir = Environment.buildPath(MediaStore.getVolumePath(volumeName), "Android", "media",
"android.provider.cts");
Log.d(TAG, "stageDir(" + volumeName + "): returning " + dir);
- return waitUntilExists(dir);
+ return dir;
}
static File stageDownloadDir(String volumeName) throws IOException {