aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/test/java/org
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2024-04-12 18:52:43 +0200
committersonartech <sonartech@sonarsource.com>2024-04-15 20:02:44 +0000
commitbc04c220c0c81f240149e2ee6c5af7fff6fb6f54 (patch)
tree88ee6a45049231894463ba7df877264e1cf2ec2a /sonar-scanner-engine/src/test/java/org
parent94d11b4e7035ba66617247ebe027943eb37f914d (diff)
downloadsonarqube-bc04c220c0c81f240149e2ee6c5af7fff6fb6f54.tar.gz
sonarqube-bc04c220c0c81f240149e2ee6c5af7fff6fb6f54.zip
SONAR-22039 Support new timeout properties
Diffstat (limited to 'sonar-scanner-engine/src/test/java/org')
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerWsClientProviderTest.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerWsClientProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerWsClientProviderTest.java
index 141a3af7670..2e63d4c0139 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerWsClientProviderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerWsClientProviderTest.java
@@ -126,6 +126,46 @@ class ScannerWsClientProviderTest {
}
@Test
+ void it_should_timeout_on_long_response() {
+ scannerProps.put("sonar.host.url", sonarqubeMock.baseUrl());
+ scannerProps.put("sonar.scanner.responseTimeout", "PT0.2S");
+
+ DefaultScannerWsClient client = underTest.provide(new ScannerProperties(scannerProps), env, GLOBAL_ANALYSIS_MODE, system2, ANALYSIS_WARNINGS);
+
+ sonarqubeMock.stubFor(get("/api/plugins/installed")
+ .willReturn(aResponse().withStatus(200)
+ .withFixedDelay(2000)
+ .withBody("Success")));
+
+ HttpConnector httpConnector = (HttpConnector) client.wsConnector();
+
+ var getRequest = new GetRequest("api/plugins/installed");
+ var thrown = assertThrows(IllegalStateException.class, () -> httpConnector.call(getRequest));
+
+ assertThat(thrown).hasStackTraceContaining("timeout");
+ }
+
+ @Test
+ void it_should_timeout_on_slow_response() {
+ scannerProps.put("sonar.host.url", sonarqubeMock.baseUrl());
+ scannerProps.put("sonar.scanner.socketTimeout", "PT0.2S");
+
+ DefaultScannerWsClient client = underTest.provide(new ScannerProperties(scannerProps), env, GLOBAL_ANALYSIS_MODE, system2, ANALYSIS_WARNINGS);
+
+ sonarqubeMock.stubFor(get("/api/plugins/installed")
+ .willReturn(aResponse().withStatus(200)
+ .withChunkedDribbleDelay(2, 2000)
+ .withBody("Success")));
+
+ HttpConnector httpConnector = (HttpConnector) client.wsConnector();
+
+ var getRequest = new GetRequest("api/plugins/installed");
+ var thrown = assertThrows(IllegalStateException.class, () -> httpConnector.call(getRequest));
+
+ assertThat(thrown).hasStackTraceContaining("timeout");
+ }
+
+ @Test
void it_should_honor_scanner_proxy_settings() {
scannerProps.put("sonar.host.url", sonarqubeMock.baseUrl());
scannerProps.put("sonar.scanner.proxyHost", "localhost");