Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky tests #1213

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ public SonarLintRpcServerImpl(InputStream in, OutputStream out) {
rootLogger.addAppender(rpcAppender);

this.clientListener = launcher.startListening();

LOG.info("SonarLint backend started, instance={}", this);
}

private static PrintWriter getMessageTracer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void test_connection_added_should_suggest_binding_with_no_matches(SonarLintTestH
var fakeClient = harness.newFakeClient().build();
var backend = harness.newBackend()
.withUnboundConfigScope(CONFIG_SCOPE_ID, "My Project 1")
.build(fakeClient);
.start(fakeClient);
await().untilAsserted(() -> assertThat(fakeClient.getLogMessages()).contains("No connections configured, skipping binding suggestions."));

backend.getConnectionService()
Expand All @@ -101,7 +101,7 @@ void test_connection_added_should_suggest_binding_with_matches(SonarLintTestHarn
var fakeClient = harness.newFakeClient().build();
var backend = harness.newBackend()
.withUnboundConfigScope(CONFIG_SCOPE_ID, "sonarlint-core")
.build(fakeClient);
.start(fakeClient);
await().untilAsserted(() -> assertThat(fakeClient.getLogMessages()).contains("No connections configured, skipping binding suggestions."));

sonarqubeMock.stubFor(get("/api/components/search.protobuf?qualifiers=TRK&ps=500&p=1")
Expand Down Expand Up @@ -131,7 +131,7 @@ void test_project_added_should_suggest_binding_with_matches(SonarLintTestHarness
var fakeClient = harness.newFakeClient().build();
var backend = harness.newBackend()
.withSonarQubeConnection(MYSONAR, sonarqubeMock.baseUrl())
.build(fakeClient);
.start(fakeClient);

sonarqubeMock.stubFor(get("/api/components/search.protobuf?qualifiers=TRK&ps=500&p=1")
.willReturn(aResponse().withResponseBody(protobufBody(Components.SearchWsResponse.newBuilder()
Expand Down Expand Up @@ -170,7 +170,7 @@ void test_uses_binding_clues_when_initializing_fs(SonarLintTestHarness harness,
var backend = harness.newBackend()
.withSonarQubeConnection(MYSONAR, sonarqubeMock.baseUrl())
.withSonarQubeConnection("another")
.build(fakeClient);
.start(fakeClient);

sonarqubeMock.stubFor(get("/api/components/show.protobuf?component=org.sonarsource.sonarlint%3Asonarlint-core-parent")
.willReturn(aResponse().withResponseBody(protobufBody(Components.ShowWsResponse.newBuilder()
Expand Down Expand Up @@ -204,7 +204,7 @@ void test_uses_binding_clues_when_updating_fs(SonarLintTestHarness harness, @Tem
var backend = harness.newBackend()
.withSonarQubeConnection(MYSONAR, sonarqubeMock.baseUrl())
.withSonarQubeConnection("another")
.build(fakeClient);
.start(fakeClient);

sonarqubeMock.stubFor(get("/api/components/show.protobuf?component=org.sonarsource.sonarlint%3Asonarlint-core-parent")
.willReturn(aResponse().withResponseBody(protobufBody(Components.ShowWsResponse.newBuilder()
Expand Down Expand Up @@ -249,7 +249,7 @@ void test_binding_suggestion_via_service(SonarLintTestHarness harness) throws Ex
var fakeClient = harness.newFakeClient().build();
var backend = harness.newBackend()
.withSonarQubeConnection(MYSONAR, sonarqubeMock.baseUrl())
.build(fakeClient);
.start(fakeClient);

sonarqubeMock.stubFor(get("/api/components/search.protobuf?qualifiers=TRK&ps=500&p=1")
.willReturn(aResponse().withResponseBody(protobufBody(Components.SearchWsResponse.newBuilder()
Expand Down Expand Up @@ -285,7 +285,7 @@ void test_uses_binding_clues_from_shared_configuration_when_updating_fs(SonarLin
var backend = harness.newBackend()
.withSonarQubeConnection(MYSONAR, sonarqubeMock.baseUrl())
.withSonarQubeConnection("another")
.build(fakeClient);
.start(fakeClient);

sonarqubeMock.stubFor(get("/api/components/show.protobuf?component=org.sonarsource.sonarlint%3Asonarlint-core-parent")
.willReturn(aResponse().withResponseBody(protobufBody(Components.ShowWsResponse.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void should_locally_detect_hotspots_when_connected_to_sonarqube(SonarLintTestHar
.withSonarQubeConnection(CONNECTION_ID, server)
.withBoundConfigScope(CONFIG_SCOPE_ID, CONNECTION_ID, projectKey)
.withExtraEnabledLanguagesInConnectedMode(JAVA)
.build(client);
.start(client);
client.waitForSynchronization();

var analysisId = UUID.randomUUID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static void prepare(@TempDir Path baseDir) {
.withActiveRule("java:S1481", "BLOCKER"))))
.withBoundConfigScope(JAVA_MODULE_KEY, CONNECTION_ID, JAVA_MODULE_KEY)
.withEnabledLanguageInStandaloneMode(Language.JAVA)
.build(client);
.start(client);
}

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void simpleJavaBound(SonarLintTestHarness harness, @TempDir Path baseDir) {
.withSonarQubeConnection(CONNECTION_ID, server)
.withBoundConfigScope(CONFIG_SCOPE_ID, CONNECTION_ID, projectKey)
.withExtraEnabledLanguagesInConnectedMode(JAVA)
.build(client);
.start(client);
client.waitForSynchronization();

var analysisId = UUID.randomUUID();
Expand Down Expand Up @@ -137,7 +137,7 @@ void emptyQPJava(SonarLintTestHarness harness, @TempDir Path baseDir) {
.withSonarQubeConnection(CONNECTION_ID, server)
.withBoundConfigScope(CONFIG_SCOPE_ID, CONNECTION_ID, projectKey)
.withExtraEnabledLanguagesInConnectedMode(JAVA)
.build(client);
.start(client);
client.waitForSynchronization();

var analysisId = UUID.randomUUID();
Expand Down Expand Up @@ -181,7 +181,7 @@ void it_should_get_hotspot_details(SonarLintTestHarness harness, @TempDir Path b
project -> project.withRuleSet("java", ruleSet -> ruleSet.withActiveRule("java:S2068", "BLOCKER"))))
.withBoundConfigScope(CONFIG_SCOPE_ID, connectionId, projectKey)
.withConnectedEmbeddedPluginAndEnabledLanguage(TestPlugin.JAVA)
.build(client);
.start(client);
await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> Assertions.assertThat(client.getSynchronizedConfigScopeIds()).contains(CONFIG_SCOPE_ID));

var analysisId = UUID.randomUUID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void corrupted_plugin_should_not_prevent_startup(SonarLintTestHarness harness, @
ruleSet -> ruleSet.withActiveRule("java:S106", "BLOCKER"))))
.withBoundConfigScope(CONFIG_SCOPE_ID, CONNECTION_ID, CONFIG_SCOPE_ID)
.withEnabledLanguageInStandaloneMode(org.sonarsource.sonarlint.core.rpc.protocol.common.Language.JAVA)
.withEnabledLanguageInStandaloneMode(org.sonarsource.sonarlint.core.rpc.protocol.common.Language.JS).build(client);
.withEnabledLanguageInStandaloneMode(org.sonarsource.sonarlint.core.rpc.protocol.common.Language.JS).start(client);

backend.getAnalysisService().analyzeFilesAndTrack(new AnalyzeFilesAndTrackParams(CONFIG_SCOPE_ID, UUID.randomUUID(),
List.of(inputFile.toUri()), Map.of(), false, Instant.now().toEpochMilli())).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void it_should_open_the_sonarlint_auth_url_for_sonarcloud(SonarLintTestHarness h
ServerFixture.Server scServer = harness.newFakeSonarCloudServer()
.start();

var backend = harness.newBackend().withEmbeddedServer().withClientName("ClientName").withSonarCloudConnection("connectionId").build(fakeClient);
var backend = harness.newBackend().withEmbeddedServer().withClientName("ClientName").withSonarCloudConnection("connectionId").start(fakeClient);

var futureResponse = backend.getConnectionService().helpGenerateUserToken(new HelpGenerateUserTokenParams(scServer.baseUrl()));

Expand All @@ -76,7 +76,7 @@ void it_should_open_the_sonarlint_auth_url_for_sonarcloud(SonarLintTestHarness h
void it_should_open_the_sonarlint_auth_url_for_sonarqube_9_7_plus(SonarLintTestHarness harness) throws IOException, InterruptedException {
var fakeClient = harness.newFakeClient().build();
var server = harness.newFakeSonarQubeServer("9.9").start();
var backend = harness.newBackend().withEmbeddedServer().withClientName("ClientName").withSonarQubeConnection("connectionId", server).build(fakeClient);
var backend = harness.newBackend().withEmbeddedServer().withClientName("ClientName").withSonarQubeConnection("connectionId", server).start(fakeClient);

var futureResponse = backend.getConnectionService().helpGenerateUserToken(new HelpGenerateUserTokenParams(server.baseUrl()));

Expand All @@ -100,7 +100,7 @@ void it_should_open_the_sonarlint_auth_url_for_sonarqube_9_7_plus(SonarLintTestH
void it_should_reject_tokens_from_missing_origin(SonarLintTestHarness harness) throws IOException, InterruptedException {
var fakeClient = harness.newFakeClient().build();
var server = harness.newFakeSonarQubeServer("9.9").start();
var backend = harness.newBackend().withEmbeddedServer().withClientName("ClientName").withSonarQubeConnection("connectionId", server).build(fakeClient);
var backend = harness.newBackend().withEmbeddedServer().withClientName("ClientName").withSonarQubeConnection("connectionId", server).start(fakeClient);

backend.getConnectionService().helpGenerateUserToken(new HelpGenerateUserTokenParams(server.baseUrl()));

Expand All @@ -118,7 +118,7 @@ void it_should_reject_tokens_from_missing_origin(SonarLintTestHarness harness) t
void it_should_reject_tokens_from_unexpected_origin(SonarLintTestHarness harness) throws IOException, InterruptedException {
var fakeClient = harness.newFakeClient().build();
var server = harness.newFakeSonarQubeServer("9.9").start();
var backend = harness.newBackend().withEmbeddedServer().withClientName("ClientName").withSonarQubeConnection("connectionId", server).build(fakeClient);
var backend = harness.newBackend().withEmbeddedServer().withClientName("ClientName").withSonarQubeConnection("connectionId", server).start(fakeClient);

backend.getConnectionService().helpGenerateUserToken(new HelpGenerateUserTokenParams(server.baseUrl()));

Expand All @@ -136,7 +136,7 @@ void it_should_reject_tokens_from_unexpected_origin(SonarLintTestHarness harness
@SonarLintTest
void it_should_open_the_sonarlint_auth_url_without_port_for_sonarqube_9_7_plus_when_server_is_not_started(SonarLintTestHarness harness) throws MalformedURLException {
var fakeClient = harness.newFakeClient().build();
var backend = harness.newBackend().withClientName("ClientName").build(fakeClient);
var backend = harness.newBackend().withClientName("ClientName").start(fakeClient);
var server = harness.newFakeSonarQubeServer("9.9").start();

var futureResponse = backend.getConnectionService().helpGenerateUserToken(new HelpGenerateUserTokenParams(server.baseUrl()));
Expand All @@ -151,7 +151,7 @@ void it_should_open_the_sonarlint_auth_url_without_port_for_sonarqube_9_7_plus_w
@SonarLintTest
void it_should_reject_incoming_user_token_with_wrong_http_method(SonarLintTestHarness harness) throws IOException, InterruptedException {
var fakeClient = harness.newFakeClient().build();
var backend = harness.newBackend().withEmbeddedServer().build(fakeClient);
var backend = harness.newBackend().withEmbeddedServer().start(fakeClient);

var request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost:" + backend.getEmbeddedServerPort() + "/sonarlint/api/token"))
Expand All @@ -164,7 +164,7 @@ void it_should_reject_incoming_user_token_with_wrong_http_method(SonarLintTestHa
@SonarLintTest
void it_should_reject_incoming_user_token_with_wrong_body(SonarLintTestHarness harness) throws IOException, InterruptedException {
var fakeClient = harness.newFakeClient().build();
var backend = harness.newBackend().withEmbeddedServer().build(fakeClient);
var backend = harness.newBackend().withEmbeddedServer().start(fakeClient);

var request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost:" + backend.getEmbeddedServerPort() + "/sonarlint/api/token"))
Expand All @@ -178,7 +178,7 @@ void it_should_reject_incoming_user_token_with_wrong_body(SonarLintTestHarness h
@SonarLintTest
void it_should_fail_to_validate_connection_if_host_not_found(SonarLintTestHarness harness) throws InterruptedException, ExecutionException {
var fakeClient = harness.newFakeClient().build();
var backend = harness.newBackend().build(fakeClient);
var backend = harness.newBackend().start(fakeClient);

var connectionResponse = backend.getConnectionService()
.validateConnection(new ValidateConnectionParams(new TransientSonarQubeConnectionDto("http://notexists", Either.forRight(new UsernamePasswordDto("foo", "bar"))))).get();
Expand All @@ -190,7 +190,7 @@ void it_should_fail_to_validate_connection_if_host_not_found(SonarLintTestHarnes
@SonarLintTest
void it_should_support_notifications_if_sonarcloud(SonarLintTestHarness harness) throws ExecutionException, InterruptedException {
var fakeClient = harness.newFakeClient().build();
var backend = harness.newBackend().build(fakeClient);
var backend = harness.newBackend().start(fakeClient);

var connectionResponse = backend.getConnectionService()
.checkSmartNotificationsSupported(new CheckSmartNotificationsSupportedParams(
Expand All @@ -204,7 +204,7 @@ void it_should_support_notifications_if_sonarcloud(SonarLintTestHarness harness)
void it_should_support_notifications_if_sonarqube_supports(SonarLintTestHarness harness) throws ExecutionException, InterruptedException {
var fakeClient = harness.newFakeClient().build();
var server = harness.newFakeSonarQubeServer().withSmartNotificationsSupported(true).start();
var backend = harness.newBackend().withEmbeddedServer().withSonarQubeConnection("connectionId", server).build(fakeClient);
var backend = harness.newBackend().withEmbeddedServer().withSonarQubeConnection("connectionId", server).start(fakeClient);

var connectionResponse = backend.getConnectionService()
.checkSmartNotificationsSupported(new CheckSmartNotificationsSupportedParams(
Expand All @@ -218,7 +218,7 @@ void it_should_support_notifications_if_sonarqube_supports(SonarLintTestHarness
void it_should_not_support_notifications_if_sonarqube_does_not_support(SonarLintTestHarness harness) throws ExecutionException, InterruptedException {
var fakeClient = harness.newFakeClient().build();
var server = harness.newFakeSonarQubeServer().withSmartNotificationsSupported(false).start();
var backend = harness.newBackend().withEmbeddedServer().withSonarQubeConnection("connectionId", server).build(fakeClient);
var backend = harness.newBackend().withEmbeddedServer().withSonarQubeConnection("connectionId", server).start(fakeClient);

var connectionResponse = backend.getConnectionService()
.checkSmartNotificationsSupported(new CheckSmartNotificationsSupportedParams(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void should_suggest_sonarqube_connection_when_initializing_fs(SonarLintTestHarne
.build();

var backend = harness.newBackend()
.build(fakeClient);
.start(fakeClient);

backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(fileDto), Collections.emptyList(), Collections.emptyList()));

Expand Down Expand Up @@ -109,7 +109,7 @@ void should_not_suggest_connection_for_empty_values(String projectKey, String se
.withInitialFs(CONFIG_SCOPE_ID, List.of(fileDto))
.build();

var backend = harness.newBackend().build(fakeClient);
var backend = harness.newBackend().start(fakeClient);

backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(fileDto), Collections.emptyList(), Collections.emptyList()));

Expand All @@ -134,7 +134,7 @@ void should_suggest_connection_for_non_empty_values(String projectKey, String se
List.of(fileDto))
.build();

var backend = harness.newBackend().build(fakeClient);
var backend = harness.newBackend().start(fakeClient);

backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(fileDto), Collections.emptyList(), Collections.emptyList()));

Expand All @@ -154,7 +154,7 @@ void should_suggest_sonarcloud_connection_when_initializing_fs(SonarLintTestHarn
.build();

var backend = harness.newBackend()
.build(fakeClient);
.start(fakeClient);

backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(fileDto), Collections.emptyList(), Collections.emptyList()));

Expand Down Expand Up @@ -187,7 +187,7 @@ void should_suggest_connection_when_initializing_fs_for_csharp_project(SonarLint
.build();

var backend = harness.newBackend()
.build(fakeClient);
.start(fakeClient);

backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(fileDto), Collections.emptyList(), Collections.emptyList()));

Expand All @@ -214,7 +214,7 @@ void should_suggest_connection_when_initializing_fs_with_scanner_file(SonarLintT
.build();

var backend = harness.newBackend()
.build(fakeClient);
.start(fakeClient);

backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(fileDto), Collections.emptyList(), Collections.emptyList()));

Expand All @@ -241,7 +241,7 @@ void should_suggest_sonarcloud_connection_when_initializing_fs_with_scanner_file
.build();

var backend = harness.newBackend()
.build(fakeClient);
.start(fakeClient);

backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(fileDto), Collections.emptyList(), Collections.emptyList()));

Expand Down Expand Up @@ -270,7 +270,7 @@ void should_suggest_connection_when_config_scope_added(SonarLintTestHarness harn
.build();

var backend = harness.newBackend()
.build(fakeClient);
.start(fakeClient);

backend.getConfigurationService()
.didAddConfigurationScopes(
Expand Down Expand Up @@ -306,7 +306,7 @@ void should_suggest_connection_with_multiple_bindings_when_config_scope_added(So
.build();

var backend = harness.newBackend()
.build(fakeClient);
.start(fakeClient);

backend.getConfigurationService()
.didAddConfigurationScopes(
Expand Down Expand Up @@ -348,7 +348,7 @@ void should_suggest_sonarlint_configuration_in_priority(SonarLintTestHarness har
.build();

var backend = harness.newBackend()
.build(fakeClient);
.start(fakeClient);

backend.getConfigurationService()
.didAddConfigurationScopes(
Expand Down Expand Up @@ -381,7 +381,7 @@ void should_suggest_sonarqube_connection_when_pascal_case(SonarLintTestHarness h
.build();

var backend = harness.newBackend()
.build(fakeClient);
.start(fakeClient);

backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(fileDto), Collections.emptyList(), Collections.emptyList()));

Expand Down Expand Up @@ -410,7 +410,7 @@ void should_suggest_sonarcloud_connection_when_pascal_case(SonarLintTestHarness
.build();

var backend = harness.newBackend()
.build(fakeClient);
.start(fakeClient);

backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(fileDto), Collections.emptyList(), Collections.emptyList()));

Expand Down
Loading