]> source.dussan.org Git - sonarqube.git/commitdiff
Fix HTTP timeouts in 2 integration tests
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 30 Aug 2016 12:20:41 +0000 (14:20 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 30 Aug 2016 12:21:33 +0000 (14:21 +0200)
 Default timeouts of okhttp3 are 10 seconds
 but usually we use 30 seconds. That will
 prevent some infrequent false-positives

it/it-tests/src/test/java/it/analysis/ReportDumpTest.java
it/it-tests/src/test/java/it/http/HttpHeadersTest.java

index 9adc6c620ed0ca5ce7786fe65ad07f95b45b738f..e8343ba971bc55891342ab093a40eb89f8e07b49 100644 (file)
@@ -27,6 +27,7 @@ import java.io.IOException;
 import java.io.StringReader;
 import java.nio.charset.StandardCharsets;
 import java.util.Properties;
+import java.util.concurrent.TimeUnit;
 import okhttp3.HttpUrl;
 import okhttp3.OkHttpClient;
 import okhttp3.Request;
@@ -71,7 +72,12 @@ public class ReportDumpTest {
       .url(httpUrl)
       .get()
       .build();
-    Response response = new OkHttpClient().newCall(request).execute();
+    Response response = new OkHttpClient.Builder()
+      .connectTimeout(30, TimeUnit.SECONDS)
+      .readTimeout(30, TimeUnit.SECONDS)
+      .build()
+      .newCall(request)
+      .execute();
     assertThat(response.isSuccessful()).as(httpUrl.toString()).isTrue();
     assertThat(response.body().string()).as(httpUrl.toString()).isNotEmpty();
   }
index 3c7864a6815fdf6f40317a473b04c915ce8f008b..bf06af57216c116d48f5d43503de28d79692e592 100644 (file)
@@ -24,6 +24,7 @@ import com.google.common.base.Throwables;
 import com.sonar.orchestrator.Orchestrator;
 import it.Category4Suite;
 import java.io.IOException;
+import java.util.concurrent.TimeUnit;
 import okhttp3.CacheControl;
 import okhttp3.OkHttpClient;
 import okhttp3.Request;
@@ -93,7 +94,13 @@ public class HttpHeadersTest {
   private static Response call(String url) {
     Request request = new Request.Builder().get().url(url).build();
     try {
-      return new OkHttpClient().newCall(request).execute();
+      // SonarQube ws-client cannot be used as it does not
+      // expose HTTP headers
+      return new OkHttpClient.Builder()
+        .connectTimeout(30, TimeUnit.SECONDS)
+        .readTimeout(30, TimeUnit.SECONDS)
+        .build()
+        .newCall(request).execute();
     } catch (IOException e) {
       throw Throwables.propagate(e);
     }