Skip to content

test: open no editor in the socket stop test, whose connect could start the language server again after the stop - #2064

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:test/open-no-editor-in-the-socket-stop-test
Nov 21, 2026
Merged

lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:test/open-no-editor-in-the-socket-stop-test

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

SocketLanguageServerTest.testAStopSendsTheExitNotificationBeforeItClosesTheConnection failed once on the macOS runner of main, at 221e8bf (run):

errors of the stop expected:<[]> but was:<[com.redhat.devtools.lsp4ij.server.CannotStartProcessException: Nothing listens on 127.0.0.1:49321 (Connection refused): ...]>

The language server started again during the stop. The test opened main.sock in an editor (configureByText), and the editor connects its file to its language servers once indexing is done (ConnectDocumentToLanguageServerSetupParticipant.selectionChanged), unless the file is connected already. On a slow machine, that connection can come after the stop has disconnected the file: it then starts the language server again, on a port on which nothing listens anymore, and the test sees the failed start as an error of the stop. testALanguageServerOverASocketAnswersRequestsAndStopsWhenItClosesTheConnection already notes that the editor can start the language server again, and doesn't check for errors.

The test now creates the file without an editor (addFileToProject), so nothing connects it after the stop. It doesn't need an editor: it asks for the language servers of the file itself.

Test: with a delay of 300ms before the connection of the editor, and a wait of 500ms before the check of the errors, the test fails as on the runner with an editor, and passes without one. The server tests pass (111 tests, 4 Windows-only tests skipped).

…rt the language server again after the stop

The editor of a file connects it to its language servers once indexing is done. On a slow machine, as a macOS runner,
that can be after the stop of the test, which then sees the language server start again, on a port on which nothing
listens anymore, as an error of the stop.
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Tests
    • Updated coverage for language server stop notifications to use a project file without opening an editor. This keeps the test focused on the stop-notification behavior and avoids editor activity that could affect the server’s state.

The stop-notification test now adds main.sock to the project without opening an editor. Comments describe how a delayed editor connection after indexing could restart the server after it stops.

Changes: Socket server stop test

Layer / File(s) Summary
Stop-notification test setup
src/test/java/com/redhat/devtools/lsp4ij/server/SocketLanguageServerTest.java
The test adds main.sock to the project without opening an editor. Comments describe a possible delayed editor connection that could restart the server after it stops.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Other

Suggested reviewers: d-biehl

Merge Risk: Minimal · up to 761fb

This only changes how a test sets up its file, so it should remove an intermittent connection-refused failure without touching production behavior. No remaining merge risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the socket stop test no longer opens an editor, because an editor connection after the stop could restart the language server. It is specific and matches the single-fi…
Description check Passed The description explains the failing test, the cause (an editor connection after the stop restarts the language server), the fix (creating the file with addFileToProject instead of configureByText), a…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the socket stop test no longer opens an editor, because an editor connection after the stop could restart the language server. It is specific and matches the single-file test change in the summary and objectives. Its 112-character length is long, but it stays a clear single sentence.

Full details: Description check

Explanation

The description explains the failing test, the cause (an editor connection after the stop restarts the language server), the fix (creating the file with addFileToProject instead of configureByText), and the verification steps. It matches the changeset.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3aa45d84-741f-41be-a6e4-428ffef15a0f
Commits

Reviewing files that changed from the base of the PR and between bba340e and 761fb8e.

Files selected for processing: 1

  • src/test/java/com/redhat/devtools/lsp4ij/server/SocketLanguageServerTest.java

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@codecov

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.88%. Comparing base (30adef2) to head (761fb8e).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2064      +/-   ##
==========================================
+ Coverage   49.49%   49.88%   +0.39%     
==========================================
  Files         813      813              
  Lines       33345    33396      +51     
  Branches     6854     5207    -1647     
==========================================
+ Hits        16503    16660     +157     
+ Misses      14266    14148     -118     
- Partials     2576     2588      +12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren
lagergren merged commit 2da25ca into redhat-developer:main Nov 21, 2026
9 checks passed
@lagergren lagergren added this to the 0.30.2 milestone Nov 21, 2026
@lagergren lagergren added bug Something isn't working junit-test labels Nov 22, 2026
lagergren added a commit that referenced this pull request Nov 22, 2026
…ahead of its shutdown (#2099)

## What

`SelectedEditorConnectionTest.testATabThatClosesWhileItsSelectionWaitsForTheServerLeavesTheFileDisconnected` fails now and then with "the closed file must end disconnected":
- on 2025.3 on 2026-11-19;
- on macOS in [run 45039702394](https://github.com/redhat-developer/lsp4ij/actions/runs/45039702394) of #2096 on 2026-11-22.

The server reads the file's didOpen and never its didClose, even after 10 s. #2019 had replaced a 2 s wait with 10 s waits, but the test kept failing, as no wait fixes it: it's a race in the stop of a language server, older than #2076 and #2096.

## Cause

The file is the only document of its language server:
1. When its tab's connection is released, the file is disconnected, and its didClose is queued on the dispatcher.
2. The disconnection then stops the server: at once in tests, after `lastDocumentDisconnectedTimeout` otherwise.
3. The stop sent `shutdown` and `exit` from a pooled thread without waiting for the dispatcher, then closed the connection.

When the dispatcher was a few milliseconds late, the didClose went out after the shutdown, which LSP forbids, and after the connection had closed, so the server never read it. A trace of a failing run under load showed it: shutdown sent, shutdown and exit read, connection closed, and only then the didClose dispatched.

## Change

Before it sends `shutdown`, the stop of `LanguageServerWrapper` now waits until the dispatcher has handed the notifications queued before the stop to the message writer. So a server is told of the close of its last document before it is told to shut down.
- It waits for a second at most, as it already does for the message writer before it closes the connection. After that, the stop goes on as before.
- It doesn't wait when the project closes, which stops the server at once, as before.
- A stop cancels the initialization of its server, so notifications held back until the server is initialized don't keep it waiting.

The failure message of the test now lists the didOpen and didClose notifications of the file that the server read.

## Test

- `testTheServerReadsTheDidCloseOfItsLastFileBeforeItStops` holds the dispatcher while the last tab of the server closes, and frees it 200 ms later. It fails without the change and passes with it.
- Before the change, the flaky test failed once in 451 runs under CPU load. After it, the flaky test and the new test passed 400 times each under load, 100 of them on 2025.3, with no failure.
- 22 related test classes, such as the document move, the stop and the notification order tests, passed 5 times (1,100 tests).
- The full suite passed: 1,845 tests, 0 failures, 7 skipped.
- It also fixes `LanguageServerInstancesTest.testAMovedFileWhoseEditorClosesAsItIsAskedForAgainIsNotConnected`, which failed on `main` at 30cb393 (2026-11-18, 2026.3) and on a fork run of #2082 (2026-11-22, 2025.3), each after its full 10 s wait. It's the same race: the test's disconnection of the last document queues the `didClose` and stops the server, whose `shutdown` went out first. With the dispatcher held 200 ms before the `didClose`, that test fails 5 of 5 times without this change, and passes 5 of 5 times with it.

## Not changed

`SocketLanguageServerTest.testAStopSendsTheExitNotificationBeforeItClosesTheConnection` also failed on macOS 3 times, all before #2064. It's a different cause, and not a lost `exit`: in each failure `exit` arrived, and then the editor that the test opened connected again after the stop and started the server again. #2064 fixed the test, and it hasn't failed in the 51 runs since.
lagergren added a commit that referenced this pull request Nov 24, 2026
…rflowed, and retry a refused download for a minute (#2175)

## What

Main's last CI run, for 436b029, failed on Windows before any test ran:

```
Could not GET 'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugins-bom/2.3.21/kotlin-gradle-plugins-bom-2.3.21.pom'.
> Received status code 429 from server: Too Many Requests
```

The job had no cache to start from: setup-gradle said "Gradle User Home cache not found. Will initialize empty.", so it
downloaded every dependency again.

**Why there was no cache:** the repository's Actions cache holds 12.2 GB, over GitHub's 10 GB per repository. Every
entry in it was saved in the 20 minutes before this PR, all on main. The biggest are `gradle-transforms` entries of 3.9,
3.3 and 0.9 GB. They are the IDEs that the IntelliJ Platform Gradle plugin extracts as Gradle artifact transforms, one
per job and platform version. Each push to main saves them again for the 5 test jobs, the plugin build and the
verifier. GitHub then evicts the oldest entries, the other jobs' downloads among them, and the next run of those jobs
fetches everything from Maven Central and JetBrains again.

## Change

- **The cache:** every `setup-gradle` step leaves `caches/transforms-4` and `caches/*/transforms` out of the Actions
  cache, with `gradle-home-cache-excludes`. setup-gradle deletes them before it saves. These are ci.yml, buildZip.yml,
  IJ.yml, IJ-latest.yml (3 steps), nightly.yml and release.yml.
  - The downloads themselves stay cached (`gradle-dependencies`, now 1.3 to 2 GB an entry), so the entries fit in
    10 GB, and Gradle extracts an IDE again from its cached download without a network access.
  - Locally the IDEs are in `caches/9.9.2/transforms/*/transformed/extracted`.
- **Retries:** Gradle 9.9.2 already retries a download refused with a server error or a 429
  (`NetworkingIssueVerifier`), but only 3 times, 1 and 2 seconds apart. `gradle.properties` raises that to 6 times, 2,
  4, 8, 16 and 32 seconds apart, with `systemProp.org.gradle.internal.network.retry.max.attempts` and `.initial.backOff`,
  which `NetworkOperationBackOffAndRetry` reads. A local build prints them back as 6 and 2000 from an init script.

## The other CI failures this week

I went through the 22 failed "Java CI with Gradle" runs since 2026-11-17:
- **6 were a real break**, fixed by #2138: `InstallerTaskRegistryInitializeTest` failed on every job after #2102.
- **Most of the rest were flaky tests, since fixed:**
  - `LanguageServerManagerInstancesTest` by #2120;
  - `CancelRequestAfterShutdownTest` by #2162;
  - `SocketLanguageServerTest` by #2064;
  - `SelectedEditorConnectionTest` and `FileDocumentMoveTest` by the fixes of #2099 and #2095.
- **Seen once and not fixed:** `WatchedFilesTest` (Windows, 2026-11-22) and `LanguageServerInstancesTest` (2026.3,
  2026-11-18).
- **Since 2026-11-23 14:00 UTC:** 36 runs passed, and the only failure was this 429.

## Check

A pull request reads the cache but doesn't write it, so this PR's own CI can't show the saving. After the merge, the
next run on main should leave the repository's cache under 10 GB, and the run after it should restore each job's entry.
I'll check both.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working junit-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant