From 5180de23e77139dd6971dfd48269242e3e3562d9 Mon Sep 17 00:00:00 2001 From: Steve Howard Date: Tue, 20 Jul 2010 12:04:02 -0700 Subject: Fix bug with deciding when to restart a download. In previous refactoring I had combined the code for starting a download (from DownloadService.insertDownload()) and restarting a download (from DownloadService.updateDownload()). I'd missed the fact that the former checks DownloadInfo.isReadyToStart() while the latter checks DownloadInfo.isReadyToRestart(). This cause a race condition where multiple startService() calls during a download would cause the service to try to spawn a second thread for the same running download. I've fixed the bug and added a test case to exercise this. Change-Id: Ia968331a030137daac7c8b5792a01e3e19065b38 --- .../providers/downloads/PublicApiFunctionalTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests/src') diff --git a/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java b/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java index a9810fc1..e34c66e6 100644 --- a/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java +++ b/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java @@ -309,6 +309,19 @@ public class PublicApiFunctionalTest extends AbstractDownloadManagerFunctionalTe enqueueResponse(HTTP_OK, FILE_CONTENT); download.runUntilStatus(DownloadManager.STATUS_SUCCESSFUL); } + + /** + * Test for race conditions when the service is flooded with startService() calls while running + * a download. + */ + public void testFloodServiceWithStarts() throws Exception { + enqueueResponse(HTTP_OK, FILE_CONTENT); + Download download = enqueueRequest(getRequest()); + while (download.getStatus() != DownloadManager.STATUS_SUCCESSFUL) { + startService(null); + Thread.sleep(10); + } + } private DownloadManager.Request getRequest() throws MalformedURLException { return getRequest(getServerUri(REQUEST_PATH)); -- cgit v1.2.3