[tor-commits] [collector/master] Tweak URL-based unit tests.

karsten at torproject.org karsten at torproject.org
Fri Sep 27 10:25:45 UTC 2019


commit 834ef7c5e76778e31f9ca8569e69423b32700acf
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Fri Sep 27 12:23:19 2019 +0200

    Tweak URL-based unit tests.
    
    Turns out that one of the tests that we disabled earlier was only
    slow, because creating a URL instance to https://something.dummy.org/
    triggered an actual DNS resolve. There's absolutely no need to do
    this, so we can as well use localhost in all our test URLs.
---
 .../org/torproject/metrics/collector/conf/ConfigurationTest.java  | 5 ++---
 .../torproject/metrics/collector/downloader/DownloaderTest.java   | 8 ++++----
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/test/java/org/torproject/metrics/collector/conf/ConfigurationTest.java b/src/test/java/org/torproject/metrics/collector/conf/ConfigurationTest.java
index 67a9082..7845909 100644
--- a/src/test/java/org/torproject/metrics/collector/conf/ConfigurationTest.java
+++ b/src/test/java/org/torproject/metrics/collector/conf/ConfigurationTest.java
@@ -128,13 +128,12 @@ public class ConfigurationTest {
     }
   }
 
-  @Ignore("This test takes 40 seconds, which is too long.")
   @Test()
   public void testUrlArrayValues() throws Exception {
     URL[] array = new URL[randomSource.nextInt(30) + 1];
     for (int i = 0; i < array.length; i++) {
-      array[i] = new URL("https://"
-          + Integer.toBinaryString(randomSource.nextInt(100)) + ".dummy.org");
+      array[i] = new URL("http://localhost/"
+          + Integer.toBinaryString(randomSource.nextInt(100)));
     }
     String input =
         Arrays.toString(array).replace("[", "").replace("]", "")
diff --git a/src/test/java/org/torproject/metrics/collector/downloader/DownloaderTest.java b/src/test/java/org/torproject/metrics/collector/downloader/DownloaderTest.java
index 19db782..0617940 100644
--- a/src/test/java/org/torproject/metrics/collector/downloader/DownloaderTest.java
+++ b/src/test/java/org/torproject/metrics/collector/downloader/DownloaderTest.java
@@ -85,7 +85,7 @@ public class DownloaderTest {
 
   @Test
   public void testExistingResource() throws Exception {
-    URL requestedUrl = new URL("http://example.org/exists");
+    URL requestedUrl = new URL("http://localhost/exists");
     byte[] expectedDownloadedBytes = "content".getBytes();
     HttpURLConnection urlConnection = mock(HttpURLConnection.class);
     httpUrlStreamHandler.addConnection(requestedUrl, urlConnection);
@@ -98,7 +98,7 @@ public class DownloaderTest {
 
   @Test
   public void testNonExistingResource() throws Exception {
-    URL requestedUrl = new URL("http://example.org/notfound");
+    URL requestedUrl = new URL("http://localhost/notfound");
     HttpURLConnection urlConnection = mock(HttpURLConnection.class);
     httpUrlStreamHandler.addConnection(requestedUrl, urlConnection);
     given(urlConnection.getResponseCode()).willReturn(404);
@@ -108,7 +108,7 @@ public class DownloaderTest {
 
   @Test
   public void testEmptyResource() throws Exception {
-    URL requestedUrl = new URL("http://example.org/empty");
+    URL requestedUrl = new URL("http://localhost/empty");
     byte[] expectedDownloadedBytes = new byte[0];
     HttpURLConnection urlConnection = mock(HttpURLConnection.class);
     httpUrlStreamHandler.addConnection(requestedUrl, urlConnection);
@@ -121,7 +121,7 @@ public class DownloaderTest {
 
   @Test(expected = SocketTimeoutException.class)
   public void testTimeout() throws Exception {
-    URL requestedUrl = new URL("http://example.org/timeout");
+    URL requestedUrl = new URL("http://localhost/timeout");
     SocketTimeoutException expectedException = new SocketTimeoutException();
     HttpURLConnection urlConnection = mock(HttpURLConnection.class);
     httpUrlStreamHandler.addConnection(requestedUrl, urlConnection);



More information about the tor-commits mailing list