Re-enable CancelResume test without flakey data size comparison checks
Checking data sizes in NSURL::NSURLSession_DownloadTaskWithURL_WithCancelResume would intermittently cause failures, so re-enabling this test with just state checks. This is not going to catch as many types of regressions as the previous implementation but it shouldn't fail for passing code either.
@@ -654,10 +654,6 @@ public:
* Test to verify a download task call can be successfully made and can be cancelled/resumed at runtime.
*/
TEST_METHOD(DownloadTaskWithURL_WithCancelResume) {
- BEGIN_TEST_METHOD_PROPERTIES()
- TEST_METHOD_PROPERTY(L"Ignore", L"true")
- END_TEST_METHOD_PROPERTIES()
-
NSURLSessionDownloadTaskTestHelper* downloadTaskTestHelper = [[NSURLSessionDownloadTaskTestHelper alloc] init];
NSURLSession* session = [downloadTaskTestHelper createSession];
NSURL* url = [NSURL URLWithString:@"http://speedtest.ams01.softlayer.com/downloads/test500.zip"];
@@ -682,16 +678,7 @@ public:
ASSERT_EQ_MSG(500, std::lround(fileSizeInMB), "FAILED: Expected download file size does not match!");
// Make sure download is in progress.
- double lastBytesDownloaded = (double)downloadTaskTestHelper.totalBytesWritten / 1024 / 1024;
- LOG_INFO("Download in progress - %fMB", lastBytesDownloaded);
- [NSThread sleepForTimeInterval:0.5];
ASSERT_EQ(NSURLSessionTaskStateRunning, downloadTask.state);
- [NSThread sleepForTimeInterval:0.5];
- double currentBytesDownloaded = (double)downloadTaskTestHelper.totalBytesWritten / 1024 / 1024;
- LOG_INFO("Download in progress - %fMB", currentBytesDownloaded);
- ASSERT_GT_MSG(currentBytesDownloaded,
- lastBytesDownloaded,
- "FAILED: File download should be in progress, but no more has been downloaded!");
// Now cancel the download
__block NSCondition* conditionCancelled = [[NSCondition alloc] init];
@@ -712,19 +699,10 @@ public:
[conditionCancelled unlock];
// Make sure download has stopped.
- [NSThread sleepForTimeInterval:0.5];
ASSERT_EQ(NSURLSessionTaskStateCanceling, downloadTask.state);
- lastBytesDownloaded = (double)downloadTaskTestHelper.totalBytesWritten / 1024 / 1024;
- [NSThread sleepForTimeInterval:1];
- currentBytesDownloaded = (double)downloadTaskTestHelper.totalBytesWritten / 1024 / 1024;
- ASSERT_EQ_MSG(currentBytesDownloaded,
- lastBytesDownloaded,
- "FAILED: File download should have stopped, but downloaded an extra %.4f MB!",
- currentBytesDownloaded - lastBytesDownloaded);
- LOG_INFO("Download stuck at - %fMB", currentBytesDownloaded);
- LOG_INFO("Resuming download...");
// Now resume the download
+ LOG_INFO("Resuming download...");
downloadTask = [session downloadTaskWithResumeData:downloadResumeData];
[downloadTask resume];
@@ -740,16 +718,6 @@ public:
LOG_INFO("Download resumed");
// Make sure download is in progress again.
- lastBytesDownloaded = (double)downloadTaskTestHelper.totalBytesWritten / 1024 / 1024;
- LOG_INFO("Download in progress - %fMB", lastBytesDownloaded);
- [NSThread sleepForTimeInterval:0.5];
- currentBytesDownloaded = (double)downloadTaskTestHelper.totalBytesWritten / 1024 / 1024;
- LOG_INFO("Download in progress - %fMB", currentBytesDownloaded);
- ASSERT_GT_MSG(currentBytesDownloaded, lastBytesDownloaded, "FAILED: File download should be in progress!");
- [NSThread sleepForTimeInterval:0.5];
- lastBytesDownloaded = currentBytesDownloaded;
- currentBytesDownloaded = (double)downloadTaskTestHelper.totalBytesWritten / 1024 / 1024;
- LOG_INFO("Download in progress - %fMB", currentBytesDownloaded);
- ASSERT_GT_MSG(currentBytesDownloaded, lastBytesDownloaded, "FAILED: File download should be in progress!");
+ ASSERT_EQ(NSURLSessionTaskStateRunning, downloadTask.state);
}
};
\ No newline at end of file
