diff options
author | Jeff Sharkey <jsharkey@android.com> | 2013-01-03 22:59:50 -0800 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2013-01-08 14:11:28 -0800 |
commit | 8ac10e0e0667a4fe35191deebb5fa9786bf4226c (patch) | |
tree | 8edfa0be4348b8f25a8dadaad6a9e8ae80525323 /tests/src/com/android/providers/downloads/DownloadProviderFunctionalTest.java | |
parent | 701d66efeff513a7509eeaafab6e47f4f6edb857 (diff) | |
download | android_packages_providers_DownloadProvider-8ac10e0e0667a4fe35191deebb5fa9786bf4226c.tar.gz android_packages_providers_DownloadProvider-8ac10e0e0667a4fe35191deebb5fa9786bf4226c.tar.bz2 android_packages_providers_DownloadProvider-8ac10e0e0667a4fe35191deebb5fa9786bf4226c.zip |
Clean up DownloadManager threading tests.
Change runUntilStatus() methods to polling with timeout instead of
requiring internal knowledge about threading.
Fix notification tests, and move opening of InputStream until after
handling headers to avoid FNFE. Always reset facade to defaults
before each test.
Change-Id: I6b2d6cfc4e685d2090c1133b1b2e89ae12760f8b
Diffstat (limited to 'tests/src/com/android/providers/downloads/DownloadProviderFunctionalTest.java')
-rw-r--r-- | tests/src/com/android/providers/downloads/DownloadProviderFunctionalTest.java | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/tests/src/com/android/providers/downloads/DownloadProviderFunctionalTest.java b/tests/src/com/android/providers/downloads/DownloadProviderFunctionalTest.java index 23d300f8..d5249378 100644 --- a/tests/src/com/android/providers/downloads/DownloadProviderFunctionalTest.java +++ b/tests/src/com/android/providers/downloads/DownloadProviderFunctionalTest.java @@ -16,14 +16,16 @@ package com.android.providers.downloads; +import static android.text.format.DateUtils.SECOND_IN_MILLIS; + import android.content.ContentValues; import android.database.Cursor; import android.net.ConnectivityManager; import android.net.Uri; import android.os.Environment; +import android.os.SystemClock; import android.provider.Downloads; import android.test.suitebuilder.annotation.LargeTest; -import android.util.Log; import com.google.mockwebserver.MockWebServer; import com.google.mockwebserver.RecordedRequest; @@ -31,6 +33,7 @@ import com.google.mockwebserver.RecordedRequest; import java.io.InputStream; import java.net.MalformedURLException; import java.net.UnknownHostException; +import java.util.concurrent.TimeoutException; /** * This test exercises the entire download manager working together -- it requests downloads through @@ -109,20 +112,22 @@ public class DownloadProviderFunctionalTest extends AbstractDownloadProviderFunc } } - private void runUntilStatus(Uri downloadUri, int status) throws Exception { - runService(); - boolean done = false; - while (!done) { - int rslt = getDownloadStatus(downloadUri); - if (rslt == Downloads.Impl.STATUS_RUNNING || rslt == Downloads.Impl.STATUS_PENDING) { - Log.i(TAG, "status is: " + rslt + ", for: " + downloadUri); - DownloadHandler.getInstance().waitUntilDownloadsTerminate(); - Thread.sleep(100); - } else { - done = true; + private void runUntilStatus(Uri downloadUri, int expected) throws Exception { + startService(null); + + int actual = -1; + + final long timeout = SystemClock.elapsedRealtime() + (15 * SECOND_IN_MILLIS); + while (SystemClock.elapsedRealtime() < timeout) { + actual = getDownloadStatus(downloadUri); + if (expected == actual) { + return; } + + SystemClock.sleep(100); } - assertEquals(status, getDownloadStatus(downloadUri)); + + throw new TimeoutException("Expected status " + expected + "; only reached " + actual); } protected int getDownloadStatus(Uri downloadUri) { |