aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-11-21 17:09:45 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-11-24 09:23:58 +0100
commit1765ad3888fbfc1f91b20197ddfd30324cd4c100 (patch)
tree2f9688771f25821109ae35e8dbfb84b5dcf14d6c /tests
parent5c4429e7a3e347437e2e8901d4e85a1c56dde66b (diff)
downloadsonarqube-1765ad3888fbfc1f91b20197ddfd30324cd4c100.tar.gz
sonarqube-1765ad3888fbfc1f91b20197ddfd30324cd4c100.zip
SONAR-10104 update IT to support concurrent and async webhook calls
Diffstat (limited to 'tests')
-rw-r--r--tests/src/test/java/org/sonarqube/tests/webhook/ExternalServer.java4
-rw-r--r--tests/src/test/java/org/sonarqube/tests/webhook/WebhooksTest.java18
2 files changed, 19 insertions, 3 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/webhook/ExternalServer.java b/tests/src/test/java/org/sonarqube/tests/webhook/ExternalServer.java
index 33301c85e3b..988a308b6fc 100644
--- a/tests/src/test/java/org/sonarqube/tests/webhook/ExternalServer.java
+++ b/tests/src/test/java/org/sonarqube/tests/webhook/ExternalServer.java
@@ -34,12 +34,14 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.junit.rules.ExternalResource;
+import static java.util.Collections.synchronizedList;
+
/**
* This web server listens to requests sent by webhooks
*/
class ExternalServer extends ExternalResource {
private final Server jetty;
- private final List<PayloadRequest> payloads = new ArrayList<>();
+ private final List<PayloadRequest> payloads = synchronizedList(new ArrayList<>());
ExternalServer() {
jetty = new Server(0);
diff --git a/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksTest.java b/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksTest.java
index 16d2ec83f88..003c3eba941 100644
--- a/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksTest.java
+++ b/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksTest.java
@@ -79,7 +79,7 @@ public class WebhooksTest {
}
@Test
- public void call_multiple_global_and_project_webhooks_when_analysis_is_done() {
+ public void call_multiple_global_and_project_webhooks_when_analysis_is_done() throws InterruptedException {
orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_NAME);
enableGlobalWebhooks(
new Webhook("Jenkins", externalServer.urlFor("/jenkins")),
@@ -90,6 +90,7 @@ public class WebhooksTest {
analyseProject();
// the same payload has been sent to three servers
+ waitUntilAllWebHooksCalled(3);
assertThat(externalServer.getPayloadRequests()).hasSize(3);
PayloadRequest request = externalServer.getPayloadRequests().get(0);
for (int i = 1; i < 3; i++) {
@@ -159,7 +160,7 @@ public class WebhooksTest {
* Restrict calls to ten webhooks per type (global or project)
*/
@Test
- public void do_not_become_a_denial_of_service_attacker() {
+ public void do_not_become_a_denial_of_service_attacker() throws InterruptedException {
orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_NAME);
List<Webhook> globalWebhooks = range(0, 15).mapToObj(i -> new Webhook("G" + i, externalServer.urlFor("/global"))).collect(Collectors.toList());
@@ -170,6 +171,7 @@ public class WebhooksTest {
analyseProject();
// only the first ten global webhooks and ten project webhooks are called
+ waitUntilAllWebHooksCalled(10 + 10);
assertThat(externalServer.getPayloadRequests()).hasSize(10 + 10);
assertThat(externalServer.getPayloadRequestsOnPath("/global")).hasSize(10);
assertThat(externalServer.getPayloadRequestsOnPath("/project")).hasSize(10);
@@ -287,4 +289,16 @@ public class WebhooksTest {
}
}
+ /**
+ * Wait up to 30 seconds
+ */
+ private static void waitUntilAllWebHooksCalled(int expectedNumberOfRequests) throws InterruptedException {
+ for (int i = 0; i < 60; i++) {
+ if (externalServer.getPayloadRequests().size() == expectedNumberOfRequests) {
+ break;
+ }
+ Thread.sleep(500);
+ }
+ }
+
}