simplify downloadUninterruptedTests to improve reliability
Test downloads with actual files, not dynamically generated things. Testing with the progress reports is really hard with multiple URLs, so just test progress with a single URL for now, and multiple URLs can still be tested without the progress check. fixes #650 https://gitlab.com/fdroid/fdroidclient/issues/650
This commit is contained in:
parent
00c6db81a7
commit
d6ed2a5e8a
@ -16,13 +16,11 @@ import static org.junit.Assert.fail;
|
||||
public class HttpDownloaderTest {
|
||||
|
||||
String[] urls = {
|
||||
"https://www.google.com",
|
||||
"https://en.wikipedia.org/wiki/Index.html",
|
||||
"https://mirrors.kernel.org/debian/dists/stable/Release",
|
||||
"https://f-droid.org/archive/de.we.acaldav_5.apk",
|
||||
"https://f-droid.org/repo/index.jar",
|
||||
// sites that use SNI for HTTPS
|
||||
"https://guardianproject.info/fdroid/repo/index.jar",
|
||||
"https://firstlook.org",
|
||||
};
|
||||
|
||||
private boolean receivedProgress;
|
||||
@ -42,24 +40,39 @@ public class HttpDownloaderTest {
|
||||
|
||||
@Test
|
||||
public void downloadUninterruptedTestWithProgress() throws IOException, InterruptedException {
|
||||
for (String urlString : urls) {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
String urlString = "https://f-droid.org/repo/index.jar";
|
||||
receivedProgress = false;
|
||||
System.out.println("downloadUninterruptedTestWithProgress: " + urlString);
|
||||
receivedProgress = false;
|
||||
URL url = new URL(urlString);
|
||||
File destFile = File.createTempFile("dl-", "");
|
||||
HttpDownloader httpDownloader = new HttpDownloader(url, destFile);
|
||||
final HttpDownloader httpDownloader = new HttpDownloader(url, destFile);
|
||||
httpDownloader.setListener(new Downloader.DownloaderProgressListener() {
|
||||
@Override
|
||||
public void sendProgress(URL sourceUrl, int bytesRead, int totalBytes) {
|
||||
System.out.println("DownloaderProgressListener.sendProgress " + sourceUrl + " " + bytesRead + " / " + totalBytes);
|
||||
receivedProgress = true;
|
||||
}
|
||||
});
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
httpDownloader.download();
|
||||
latch.countDown();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
latch.await(100, TimeUnit.SECONDS); // either 2 progress reports or 100 seconds
|
||||
assertTrue(destFile.exists());
|
||||
assertTrue(destFile.canRead());
|
||||
assertTrue(receivedProgress);
|
||||
destFile.deleteOnExit();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void downloadHttpBasicAuth() throws IOException, InterruptedException {
|
||||
|
Loading…
x
Reference in New Issue
Block a user