summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com>2024-06-19 08:21:16 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-06-19 08:21:16 +0000
commitf2ce9773640df79dd3961cceae62fdf3972015b8 (patch)
tree37ca56b9a8f2e8f2c295a1d561e890a9483635f6
parentba7b2fdd0fb6d4c5d0cf4de1452c63d06b9a6349 (diff)
parent643c2abd0da1eeeaf3fdfac87ac82b748714682b (diff)
downloadCaptivePortalLogin-master.tar.gz
Merge "Randomly generate test filenames" into mainHEADmastermain
-rw-r--r--tests/src/com/android/captiveportallogin/DownloadServiceTest.kt10
1 files changed, 7 insertions, 3 deletions
diff --git a/tests/src/com/android/captiveportallogin/DownloadServiceTest.kt b/tests/src/com/android/captiveportallogin/DownloadServiceTest.kt
index 077e27e..232679e 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.os.SystemClock
import android.util.Log
import android.widget.TextView
import androidx.core.content.FileProvider
@@ -58,6 +59,7 @@ import java.util.concurrent.CompletableFuture
import java.util.concurrent.SynchronousQueue
import java.util.concurrent.TimeUnit.MILLISECONDS
import kotlin.math.min
+import kotlin.random.Random
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotEquals
@@ -105,6 +107,8 @@ private val TEST_WIFI_CONFIG_TYPE = "application/x-wifi-config"
private val TAG = DownloadServiceTest::class.simpleName
+private val random = Random(SystemClock.elapsedRealtimeNanos())
+
@Rule
val mServiceRule = ServiceTestRule()
@@ -250,9 +254,9 @@ class DownloadServiceTest {
testFilePath.mkdir()
// Do not use File.createTempFile, as it generates very long filenames that may not
// fit in notifications, making it difficult to find the right notification.
- // currentTimeMillis would generally be 13 digits. Use the bottom 8 to fit the filename and
- // a bit more text, even on very small screens (320 dp, minimum CDD size).
- var index = System.currentTimeMillis().rem(100_000_000)
+ // Use 8 digits to fit the filename and a bit more text, even on very small screens (320 dp,
+ // minimum CDD size).
+ var index = random.nextInt(100_000_000)
while (true) {
val file = File(testFilePath, "tmp$index$extension")
if (!file.exists()) {