[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

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



commit 834ef7c5e76778e31f9ca8569e69423b32700acf
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
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);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits