From ab1dfd49845796224ab389e02fda5c0127216310 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 30 Aug 2016 14:20:41 +0200 Subject: [PATCH] Fix HTTP timeouts in 2 integration tests Default timeouts of okhttp3 are 10 seconds but usually we use 30 seconds. That will prevent some infrequent false-positives --- .../src/test/java/it/analysis/ReportDumpTest.java | 8 +++++++- it/it-tests/src/test/java/it/http/HttpHeadersTest.java | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/it/it-tests/src/test/java/it/analysis/ReportDumpTest.java b/it/it-tests/src/test/java/it/analysis/ReportDumpTest.java index 9adc6c620ed..e8343ba971b 100644 --- a/it/it-tests/src/test/java/it/analysis/ReportDumpTest.java +++ b/it/it-tests/src/test/java/it/analysis/ReportDumpTest.java @@ -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(); } diff --git a/it/it-tests/src/test/java/it/http/HttpHeadersTest.java b/it/it-tests/src/test/java/it/http/HttpHeadersTest.java index 3c7864a6815..bf06af57216 100644 --- a/it/it-tests/src/test/java/it/http/HttpHeadersTest.java +++ b/it/it-tests/src/test/java/it/http/HttpHeadersTest.java @@ -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); } -- 2.39.5