Skip to content

Commit

Permalink
am 95037fb: Merge "Fixing some flakiness of some DL Manager tests." i…
Browse files Browse the repository at this point in the history
…nto gingerbread

Merge commit '95037fb1a633f5bdeb4e0ece2d18a4974259c368' into gingerbread-plus-aosp

* commit '95037fb1a633f5bdeb4e0ece2d18a4974259c368':
  Fixing some flakiness of some DL Manager tests.
  • Loading branch information
tommynnguyen authored and Android Git Automerger committed Oct 5, 2010
2 parents f358cec + 95037fb commit daa9b8c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
20 changes: 13 additions & 7 deletions core/tests/coretests/src/android/app/DownloadManagerBaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class DownloadManagerBaseTest extends InstrumentationTestCase {
protected MockWebServer mServer = null;
protected String mFileType = "text/plain";
protected Context mContext = null;
protected MultipleDownloadsCompletedReceiver mReceiver = null;
protected static final int DEFAULT_FILE_SIZE = 130 * 1024; // 130kb
protected static final int FILE_BLOCK_READ_SIZE = 1024 * 1024;

Expand Down Expand Up @@ -131,12 +132,15 @@ public static class MultipleDownloadsCompletedReceiver extends BroadcastReceiver
*/
@Override
public void onReceive(Context context, Intent intent) {
Log.i(LOG_TAG, "Received Notification:");
if (intent.getAction().equalsIgnoreCase(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
++mNumDownloadsCompleted;
Log.i(LOG_TAG, "MultipleDownloadsCompletedReceiver got intent: " +
intent.getAction() + " --> total count: " + mNumDownloadsCompleted);
Bundle extras = intent.getExtras();
downloadIds.add(new Long(extras.getLong(DownloadManager.EXTRA_DOWNLOAD_ID)));
synchronized(this) {
++mNumDownloadsCompleted;
Log.i(LOG_TAG, "MultipleDownloadsCompletedReceiver got intent: " +
intent.getAction() + " --> total count: " + mNumDownloadsCompleted);
Bundle extras = intent.getExtras();
downloadIds.add(new Long(extras.getLong(DownloadManager.EXTRA_DOWNLOAD_ID)));
}
}
}

Expand Down Expand Up @@ -212,6 +216,7 @@ public void setUp() throws Exception {
mContext = getInstrumentation().getContext();
mDownloadManager = (DownloadManager)mContext.getSystemService(Context.DOWNLOAD_SERVICE);
mServer = new MockWebServer();
mReceiver = registerNewMultipleDownloadsReceiver();
// Note: callers overriding this should call mServer.play() with the desired port #
}

Expand Down Expand Up @@ -712,8 +717,9 @@ protected void doWaitForDownloadsOrTimeout(Query query, long poll, long timeoutM
Cursor cursor = mDownloadManager.query(query);

try {
// If we've finished the downloads then we're done
if (cursor.getCount() == 0) {
// @TODO: there may be a little cleaner way to check for success, perhaps
// via STATUS_SUCCESSFUL and/or STATUS_FAILED
if (cursor.getCount() == 0 && mReceiver.numDownloadsCompleted() > 0) {
break;
}
currentWaitTime = timeoutWait(currentWaitTime, poll, timeoutMillis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public class DownloadManagerIntegrationTest extends DownloadManagerBaseTest {
Environment.getRootDirectory().getAbsolutePath();
private final static String CACHE_DIR =
Environment.getDownloadCacheDirectory().getAbsolutePath();
protected MultipleDownloadsCompletedReceiver mReceiver = null;

/**
* {@inheritDoc}
Expand All @@ -72,7 +71,6 @@ public void setUp() throws Exception {
setWiFiStateOn(true);
mServer.play();
removeAllCurrentDownloads();
mReceiver = registerNewMultipleDownloadsReceiver();
}

/**
Expand Down Expand Up @@ -270,7 +268,7 @@ public void testDownloadToExternal_fileExists() throws Exception {
try {
verifyInt(cursor, DownloadManager.COLUMN_STATUS, DownloadManager.STATUS_FAILED);
verifyInt(cursor, DownloadManager.COLUMN_REASON,
DownloadManager.ERROR_FILE_ERROR);
DownloadManager.ERROR_FILE_ALREADY_EXISTS);
} finally {
cursor.close();
}
Expand Down Expand Up @@ -429,6 +427,7 @@ public void testDownloadToCache_whenFull() throws Exception {
}
}

Log.i(LOG_TAG, "Done creating filler file.");
assertTrue(DOWNLOAD_FILE_SIZE > (fs.getAvailableBlocks() * blockSize));
byte[] blobData = generateData(DOWNLOAD_FILE_SIZE, DataType.TEXT);
long dlRequest = doBasicDownload(blobData);
Expand Down

0 comments on commit daa9b8c

Please sign in to comment.