Skip to content

test: DAPExecutionEpochTest counts a thread as waiting for the epoch only when it is blocked on the lock which the test's other thread holds - #2222

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:test/dap-epoch-refusal-blocked-on-the-lock
Nov 25, 2026

Conversation

@lagergren

@lagergren lagergren commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

What

DAPExecutionEpochTest.aRefusalDoesNotWaitWhileARequestOfAnEpochIsWritten (#2201) failed twice, on the Linux 2025.3 CI jobs of #2221 and #2220:

org.opentest4j.AssertionFailedError: the refusal waits for the request ==> expected: <TERMINATED> but was: <BLOCKED>

resumeRefused takes no lock that the test holds: it synchronizes only on its own set, which no other thread of the test holds. But waitUntilBlockedOrEnded returned as soon as the thread was BLOCKED. A thread is also blocked for a moment on other locks of the JVM, such as a lock of the coverage agent, or of a class that another thread of the test's application loads. ./gradlew check runs the whole suite in one JVM with the IDE's threads, which is why it fails on CI and not when the class runs alone. The same helper could also let aResumeWaitsUntilTheRequestOfTheEpochIsWritten see BLOCKED too early.

Change

Test only. The helper is now waitUntilBlockedByOrEnded(thread, owner). It counts a thread as blocked only when the lock it waits for is held by the owner (ThreadInfo.getLockOwnerId). The owner is the thread that writes its request with the epoch's lock held. A lock of the JVM held by another thread no longer counts, and no timing is involved.

Tests

  • Red: with resumeRefused changed to synchronize on the epoch's lock, the test fails (BLOCKED), so it still guards that the reader thread never waits on the lock.
  • Green: with the real code, DAPExecutionEpochTest (13 tests) passes headless on IC 2024.2, 2025.3 and IU 2026.3. The dap.* tests pass on 2025.3, headless: 545 tests, 0 failures.

@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 concurrency test checks to confirm waiting threads are blocked on a lock held by the request-writing thread. Terminated threads still return immediately, and checks retain their existing timeout.

The concurrency tests now report a thread as blocked only when JVM thread-management data identifies the expected lock owner. The helper still returns for terminated threads and polls until its existing timeout.

Changes: DAP concurrency tests

Layer / File(s) Summary
Lock ownership checks
src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPExecutionEpochTest.java
The helper checks whether the expected thread owns the lock blocking the waiting thread. The resume-wait and refusal-wait tests pass the expected owner thread.

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

Change: Other

Merge Risk: Minimal · up to 57ffa

This change only makes a concurrency test helper more precise and affects no production behavior. No merge-blocking risk is identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the change: DAPExecutionEpochTest now counts a thread as waiting only when it is blocked on a lock held by the test's other thread. The change matches the raw summary and objectives. T…
Description check Passed The description explains the failing test, the root cause (BLOCKED on unrelated JVM locks), the change to waitUntilBlockedByOrEnded using ThreadInfo.getLockOwnerId, and the red/green validation. It ma…
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 change: DAPExecutionEpochTest now counts a thread as waiting only when it is blocked on a lock held by the test's other thread. The change matches the raw summary and objectives. The title is long (140 characters) but specific.

Full details: Description check

Explanation

The description explains the failing test, the root cause (BLOCKED on unrelated JVM locks), the change to waitUntilBlockedByOrEnded using ThreadInfo.getLockOwnerId, and the red/green validation. 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: 34d6227d-65a6-4e7a-ae47-28a2bfdd9879
Commits

Reviewing files that changed from the base of the PR and between 06998da and 57ffa13.

Files selected for processing: 1

  • src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPExecutionEpochTest.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.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 25, 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.

@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.50%. Comparing base (5321d6b) to head (57ffa13).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2222      +/-   ##
==========================================
+ Coverage   55.41%   55.50%   +0.08%     
==========================================
  Files         843      843              
  Lines       35906    35939      +33     
  Branches     5631     7432    +1801     
==========================================
+ Hits        19897    19947      +50     
+ Misses      13117    13102      -15     
+ Partials     2892     2890       -2     

☔ 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.

…only when it is blocked on the lock which the test's other thread holds

waitUntilBlockedOrEnded returned as soon as a thread was BLOCKED. A thread
is also blocked for a moment on other locks of the JVM, such as a lock of
the coverage agent, or of a class which another thread of the test's
application loads. ./gradlew check runs the whole suite in one JVM with
the IDE's threads, so aRefusalDoesNotWaitWhileARequestOfAnEpochIsWritten
failed on the Linux 2025.3 CI jobs of redhat-developer#2221 and redhat-developer#2220 with "expected:
<TERMINATED> but was: <BLOCKED>", although the refusal took no lock that
the test held.

waitUntilBlockedByOrEnded now counts a thread as blocked only when the
lock it waits for is held by the given owner: the thread that writes its
request with the epoch's lock held (ThreadInfo.getLockOwnerId).
@lagergren
lagergren force-pushed the test/dap-epoch-refusal-blocked-on-the-lock branch from 06998da to 57ffa13 Compare November 25, 2026 02:59
@lagergren lagergren changed the title test: DAPExecutionEpochTest counts a thread as waiting for a lock only when it stays blocked, not when the JVM blocks it for a moment test: DAPExecutionEpochTest counts a thread as waiting for the epoch only when it is blocked on the lock which the test's other thread holds Nov 25, 2026
@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 25, 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 25, 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 252b908 into redhat-developer:main Nov 25, 2026
10 checks passed
lagergren added a commit that referenced this pull request Nov 25, 2026
…nly for the open files of each project, not once more in every other open project (#2225)

Fixes #2224

## What

With several projects open, adding a language server definition started the server in every open project, for the open files of all open projects. When a definition is added, every project's `LanguageServiceAccessor` hears it. Its `checkCurrentlyOpenFiles` went through the open files of every open project (`ProjectManager.getOpenProjects()`), but connected them through its own project. So each file got one instance of the server per open project, and all but one of them had another project's root and workspace folders.

It also made `LSPSemanticTokenDocumentationProviderTest.testPlainTextOfTwoLanguageServers` fail now and then on Linux CI: 3 of about 520 jobs since 2026-11-23, including #2198 (#2207) and #2222.
- In the CI JVM, the light tests' shared project stays open, so `addSecondServer` started the second server twice.
- Both starts connected to the definition's one `MockLanguageServer`, whose `addRemoteProxy` adds to plain `ArrayList`s. Two concurrent adds threw `ArrayIndexOutOfBoundsException`, and one start failed with `CannotStartServerException`.
- When that was the test project's own start, the hover had only the first server's text.

#2208 fixed a different cause of the same symptom: the hover cache across language-server changes.

## Change

- **`checkCurrentlyOpenFiles`** starts the added definitions only for the open files of the accessor's own project. Each open project's accessor does the same for its own files, as `handleChanged` and `handleRemoved` already only touch their own project's servers.
- **Disposed and default projects** are skipped.

A project whose accessor doesn't exist yet doesn't connect its open files when a definition is added. Before, another project connected them, to a server of that other project. They connect as usual once a feature or an editor of the project uses LSP4IJ.

## Tests

New `ServerAddedWithSeveralOpenProjectsTest` (2 tests). It opens a second project and adds a server while a file is open in one of the two projects. Then it checks two things:
- The file gets its own project's server, with a bounded wait.
- Once the async tasks are done, the other project started none.

Red-green: without the fix, both tests fail every run, with the wrapper that the other project started (`expected:<[]> but was:<[LanguageServerWrapper@…]>`). With the fix, both pass.

Reproduction of the CI failure, with the light project opened first:

| Condition | Runs | Failures | A duplicate server started |
|---|---|---|---|
| Before the fix | 1,000 | 1, the exact CI message | every run |
| After the fix | 1,000 | 0 | never |
| A CI-like Linux suite (the 238 classes that precede it on CI), before the fix | 800 | 0 | 800 of 800 |
| The same, after the fix | 800 | 0 | 0 |

The new class, `features.documentation.*`, `features.semanticTokens.*` and `*Hover*` pass headless on IC 2024.2, 2025.3 and IU 2026.3: 60 tests each. The full suite passes on 2024.2: 2,416 tests, 0 failures, with the 7 skipped tests that were already disabled. Rebased on main at 57bae55, the new class and the hover class pass headless on all three platforms.

Not in this PR: `MockLanguageServer` and `MockTextDocumentService.addRemoteProxy` still aren't thread-safe. A test that starts two connections to one mock at once could still hit the same exception.

## Behaviour change

| Before | After |
|---|---|
| A language server added while several projects are open starts in each open project for the open files of all of them, so each file gets one instance per open project, most of them with another project's root | It starts in each project for that project's own open files only: one instance per file, of the file's own project |
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