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 {
|
public class HttpDownloaderTest {
|
||||||
|
|
||||||
String[] urls = {
|
String[] urls = {
|
||||||
"https://www.google.com",
|
|
||||||
"https://en.wikipedia.org/wiki/Index.html",
|
"https://en.wikipedia.org/wiki/Index.html",
|
||||||
"https://mirrors.kernel.org/debian/dists/stable/Release",
|
"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
|
// sites that use SNI for HTTPS
|
||||||
"https://guardianproject.info/fdroid/repo/index.jar",
|
"https://guardianproject.info/fdroid/repo/index.jar",
|
||||||
"https://firstlook.org",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private boolean receivedProgress;
|
private boolean receivedProgress;
|
||||||
@ -42,23 +40,38 @@ public class HttpDownloaderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void downloadUninterruptedTestWithProgress() throws IOException, InterruptedException {
|
public void downloadUninterruptedTestWithProgress() throws IOException, InterruptedException {
|
||||||
for (String urlString : urls) {
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
receivedProgress = false;
|
String urlString = "https://f-droid.org/repo/index.jar";
|
||||||
URL url = new URL(urlString);
|
receivedProgress = false;
|
||||||
File destFile = File.createTempFile("dl-", "");
|
System.out.println("downloadUninterruptedTestWithProgress: " + urlString);
|
||||||
HttpDownloader httpDownloader = new HttpDownloader(url, destFile);
|
receivedProgress = false;
|
||||||
httpDownloader.setListener(new Downloader.DownloaderProgressListener() {
|
URL url = new URL(urlString);
|
||||||
@Override
|
File destFile = File.createTempFile("dl-", "");
|
||||||
public void sendProgress(URL sourceUrl, int bytesRead, int totalBytes) {
|
final HttpDownloader httpDownloader = new HttpDownloader(url, destFile);
|
||||||
receivedProgress = true;
|
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();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
httpDownloader.download();
|
}.start();
|
||||||
assertTrue(destFile.exists());
|
latch.await(100, TimeUnit.SECONDS); // either 2 progress reports or 100 seconds
|
||||||
assertTrue(destFile.canRead());
|
assertTrue(destFile.exists());
|
||||||
assertTrue(receivedProgress);
|
assertTrue(destFile.canRead());
|
||||||
destFile.deleteOnExit();
|
assertTrue(receivedProgress);
|
||||||
}
|
destFile.deleteOnExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user