Skip to content

test: the mock language server connects the clients of several starts at once without losing one - #2226

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:test/mock-server-thread-safe-remote-proxies
Nov 25, 2026
Merged

lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:test/mock-server-thread-safe-remote-proxies

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

What

MockLanguageServer and MockTextDocumentService keep the clients of their connections in plain ArrayLists. Two starts of a mock server at the same time add to them concurrently. That threw ArrayIndexOutOfBoundsException in MockLanguageServer.addRemoteProxy and failed one of the starts with CannotStartServerException.

This is how LSPSemanticTokenDocumentationProviderTest.testPlainTextOfTwoLanguageServers lost its second server's hover on CI: #2224 started the server twice, and #2225 fixes that. With #2225 that test no longer starts a server twice, but any test that starts two connections to one mock at once could still hit the same exception.

Change

Test only.

  • Both lists are now CopyOnWriteArrayLists, so concurrent adds, and iteration through MockLanguageServer.getRemoteProxies(), are safe.
  • MockTextDocumentService.reset() clears its list instead of replacing it, under the lock that publishDiagnostics holds while it takes the first client and rotates the list.

Tests

No new test: the race needs two starts of one mock at once, which #2225 removes from the suite. The evidence is the stack trace that the investigation of #2224 found on CI.

The whole suite passes headless on IC 2024.2 and 2025.3: 2,422 tests each, 0 failures, with the 7 skipped tests that were already disabled.

… at once without losing one

MockLanguageServer and MockTextDocumentService kept the clients of their
connections in plain ArrayLists. Two starts of a mock server at the same
time added to them concurrently, which threw
ArrayIndexOutOfBoundsException in MockLanguageServer.addRemoteProxy and
failed one of the starts with CannotStartServerException. That is how
LSPSemanticTokenDocumentationProviderTest lost its second server's hover
on CI, when redhat-developer#2224 started the server twice (fixed in redhat-developer#2225).

Both lists are now CopyOnWriteArrayLists. MockTextDocumentService.reset
clears its list instead of replacing it, under the lock which
publishDiagnostics holds while it takes the first client and rotates the
list.
@lagergren lagergren added this to the 0.30.2 milestone Nov 25, 2026
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Tests
    • Improved the reliability of language server test setups when multiple client connections occur concurrently.
    • Updated mock services to retain their connection state consistently across resets.

No user-facing features or behavior changes are included in this update.

The test mock language server and text document service now store remote client proxies in CopyOnWriteArrayList instances. The text document service keeps the list final, omits constructor reassignment, and clears it during reset while synchronized on the list.

Changes: Mock client proxy lists

Layer / File(s) Summary
Proxy collection updates
src/test/java/com/redhat/devtools/lsp4ij/mock/MockLanguageServer.java, src/test/java/com/redhat/devtools/lsp4ij/mock/MockTextDocumentService.java
Both mock classes use CopyOnWriteArrayList for remote client proxies. The text document service retains the list across resets and clears it while synchronized on the list.

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Other

Suggested reviewers: angelozerr

Merge Risk: Minimal · up to e5796

This change makes test mock client lists safe for concurrent server starts. It affects only test code and carries no identified production risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the mock language server now handles several concurrent starts that add clients, without losing one. The changeset makes the mock's client lists thread-safe (CopyOnWri…
Description check Passed The description explains the problem (concurrent adds to ArrayLists in the mock server cause ArrayIndexOutOfBoundsException and CannotStartServerException), the change (CopyOnWriteArrayList for both l…
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 mock language server now handles several concurrent starts that add clients, without losing one. The changeset makes the mock's client lists thread-safe (CopyOnWriteArrayList) to fix that race. The title uses the 'test:' prefix, which fits a test-only change. It is somewhat long (96 characters) but accurate.

Full details: Description check

Explanation

The description explains the problem (concurrent adds to ArrayLists in the mock server cause ArrayIndexOutOfBoundsException and CannotStartServerException), the change (CopyOnWriteArrayList for both lists, reset() clears under lock), and the testing rationale. It directly describes 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: 5b40dfce-4240-4a70-bb52-43da3d61c1e5
Commits

Reviewing files that changed from the base of the PR and between 57bae55 and e5796d3.

Files selected for processing: 2

  • src/test/java/com/redhat/devtools/lsp4ij/mock/MockLanguageServer.java
  • src/test/java/com/redhat/devtools/lsp4ij/mock/MockTextDocumentService.java

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

@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 55.48%. Comparing base (57bae55) to head (e5796d3).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2226      +/-   ##
==========================================
- Coverage   55.52%   55.48%   -0.05%     
==========================================
  Files         843      843              
  Lines       35939    35939              
  Branches     5638     7432    +1794     
==========================================
- Hits        19955    19939      -16     
- Misses      13097    13105       +8     
- Partials     2887     2895       +8     

☔ 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
lagergren merged commit df2fa63 into redhat-developer:main Nov 25, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant