From 496ed35e61d007dca528ec48a0e79297aae31d8a Mon Sep 17 00:00:00 2001 From: Jacek Date: Wed, 27 Jul 2022 14:03:15 +0200 Subject: [PATCH] SONAR-17088 Increase default timeout of scanner report publishing to 60 sec - Add scan property `sonar.report.publish.timeout` --- .../java/org/sonar/scanner/report/ReportPublisher.java | 3 +-- .../main/java/org/sonar/scanner/scan/ScanProperties.java | 5 +++++ .../org/sonar/scanner/report/ReportPublisherTest.java | 6 ++++-- .../java/org/sonar/scanner/scan/ScanPropertiesTest.java | 8 ++++++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java index 432cf165f42..574fdd1e2a1 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java @@ -62,7 +62,6 @@ import static org.sonar.core.util.FileUtils.humanReadableByteCountSI; import static org.sonar.scanner.scan.branch.BranchType.PULL_REQUEST; public class ReportPublisher implements Startable { - private static final int DEFAULT_WRITE_TIMEOUT = 30_000; private static final Logger LOG = Loggers.get(ReportPublisher.class); private static final String CHARACTERISTIC = "characteristic"; private static final String DASHBOARD = "dashboard"; @@ -201,7 +200,7 @@ public class ReportPublisher implements Startable { WsResponse response; try { - post.setWriteTimeOutInMs(DEFAULT_WRITE_TIMEOUT); + post.setWriteTimeOutInMs(properties.reportPublishTimeout() * 1000); response = wsClient.call(post); } catch (Exception e) { throw new IllegalStateException("Failed to upload report: " + e.getMessage(), e); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ScanProperties.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ScanProperties.java index 44a9c04c061..250d9d22482 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ScanProperties.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ScanProperties.java @@ -42,6 +42,7 @@ public class ScanProperties { public static final String SCM_REVISION = "sonar.scm.revision"; public static final String QUALITY_GATE_WAIT = "sonar.qualitygate.wait"; public static final String QUALITY_GATE_TIMEOUT_IN_SEC = "sonar.qualitygate.timeout"; + public static final String REPORT_PUBLISH_TIMEOUT_IN_SEC = "sonar.ws.report.timeout"; private final Configuration configuration; private final DefaultInputProject project; @@ -88,6 +89,10 @@ public class ScanProperties { return configuration.getInt(QUALITY_GATE_TIMEOUT_IN_SEC).orElse(300); } + public int reportPublishTimeout() { + return configuration.getInt(REPORT_PUBLISH_TIMEOUT_IN_SEC).orElse(60); + } + /** * This should be called in the beginning of the analysis to fail fast */ diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java index ae2f877d384..5be9155e320 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java @@ -103,7 +103,9 @@ public class ReportPublisherTest { } @Test - public void use_30s_write_timeout() { + public void use_write_timeout_from_properties() { + when(properties.reportPublishTimeout()).thenReturn(60); + MockWsResponse submitMockResponse = new MockWsResponse(); submitMockResponse.setContent(Ce.SubmitResponse.newBuilder().setTaskId("task-1234").build().toByteArray()); when(wsClient.call(any())).thenReturn(submitMockResponse); @@ -111,7 +113,7 @@ public class ReportPublisherTest { underTest.start(); underTest.execute(); - verify(wsClient).call(argThat(req -> (req).getWriteTimeOutInMs().orElse(0) == 30_000)); + verify(wsClient).call(argThat(req -> (req).getWriteTimeOutInMs().orElse(0) == 60_000)); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ScanPropertiesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ScanPropertiesTest.java index effa108aeae..4ccedb3bb22 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ScanPropertiesTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ScanPropertiesTest.java @@ -64,6 +64,14 @@ public class ScanPropertiesTest { assertThat(underTest.branch()).isEqualTo(Optional.of("name")); } + @Test + public void should_define_report_publish_timeout() { + assertThat(underTest.reportPublishTimeout()).isEqualTo(60); + + settings.setProperty("sonar.ws.report.timeout", "10"); + assertThat(underTest.reportPublishTimeout()).isEqualTo(10); + } + @Test public void should_define_preload_file_metadata() { settings.setProperty("sonar.preloadFileMetadata", "true"); -- 2.39.5