Skip to content

test: wait for the pending diagnostics refresh, not the stored diagnostics - #1732

Merged
angelozerr merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/diagnostics-applier-test-wait
Oct 20, 2026
Merged

angelozerr merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/diagnostics-applier-test-wait

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

LSPDiagnosticsApplierTest.testDiagnosticsPublishedBeforeThePassIsRegisteredAreShown, added by #1721, failed twice on main, both times on macOS only, with expected:<[published early]> but was:<[]>:

The test was wrong, not #1721's fix.

Problem

OpenedDocument.updateDiagnostics stores the diagnostics (diagnosticsForServer.update(...)) and only then calls LSPDiagnosticsApplier.scheduleRefresh(...), on the thread that received publishDiagnostics. The test waited until the opened document had diagnostics, which can be between the two. If it then registered the pass factory before scheduleRefresh ran, nothing was pending: the refresh came afterwards with GROUP_ID set and was applied as any other, in the background. The test dispatched the events once and asserted before that refresh had finished.

Change

  • LSPDiagnosticsApplier.hasPendingRefreshes(), package-private and @TestOnly, says whether a refresh waits for GROUP_ID.
  • The test waits for that pending refresh, instead of for the stored diagnostics, before it registers the pass factory, so it always checks the case it is about.
  • After registering, it waits until the diagnostics are shown instead of dispatching the events once: the refresh collects in a non-blocking read action and applies on the UI thread.

No production behavior changes.

Validation

To widen the window, OpenedDocument.updateDiagnostics was made to sleep for a second between storing the diagnostics and requesting their refresh (locally only, not part of this change):

Refresh delayed No delay
Test on main fails, expected:<[published early]> but was:<[]>, as on CI passes
Test with this change passes passes

With #1721's fix reverted (the early refresh dropped), the changed test still fails: "the refresh must wait for the pass". ./gradlew check: 595 tests, 0 failures, the 3 existing skips.

…stics

testDiagnosticsPublishedBeforeThePassIsRegisteredAreShown (redhat-developer#1721) failed twice on main on macOS
with "expected:<[published early]> but was:<[]>". OpenedDocument.updateDiagnostics stores the
diagnostics and only then requests their refresh. The test waited for the stored diagnostics, so
it could register the pass factory before the refresh was requested: nothing was pending, and the
refresh came afterwards as an ordinary background one, after the test's single event dispatch.

LSPDiagnosticsApplier.hasPendingRefreshes() (@testonly) says whether a refresh waits for GROUP_ID.
The test waits for it before registering the pass factory, so it always checks the case it is
about, and afterwards waits until the diagnostics are shown. No production behavior changes.

Validation, with OpenedDocument.updateDiagnostics locally made to sleep a second between storing
the diagnostics and requesting their refresh: the test on main fails as on CI, and the changed
test passes; both pass without the delay. With redhat-developer#1721's fix reverted, the changed test fails ("the
refresh must wait for the pass"). ./gradlew check: 595 tests, 0 failures, the 3 existing skips.
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9e8bb0e2-7c26-43b1-bf1f-1b7febb4d48c
📥 Commits

Reviewing files that changed from the base of the PR and between 6015d80 and f3bb966.

📒 Files selected for processing: 2
  • src/main/java/com/redhat/devtools/lsp4ij/features/diagnostics/LSPDiagnosticsApplier.java
  • src/test/java/com/redhat/devtools/lsp4ij/features/diagnostics/LSPDiagnosticsApplierTest.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.

📝 Summary

Summary by CodeRabbit

  • Tests
    • Improved diagnostics test synchronization by waiting for language servers and pending refreshes.
    • Tests now verify that expected diagnostics appear after highlighting is registered, reducing reliance on timing-sensitive polling.

The diagnostics applier adds a test-only method to report queued refreshes. The diagnostics test uses this method and event-dispatching wait logic to check that an early diagnostic becomes visible.

Changes: Diagnostics refresh test synchronization

Layer / File(s) Summary
Expose and verify pending diagnostic refreshes
src/main/java/com/redhat/devtools/lsp4ij/features/diagnostics/LSPDiagnosticsApplier.java, src/test/java/com/redhat/devtools/lsp4ij/features/diagnostics/LSPDiagnosticsApplierTest.java
The applier exposes whether refreshes are queued before initialization. The test waits for a pending refresh and then for the expected diagnostic to appear.

Priority: ⬇️ Low

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

Change: Other

Suggested reviewers: angelozerr

Merge Risk: ⚪ Minimal · up to f3bb9

The synchronization change is limited to test coordination and is ready to merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main test change: waiting for pending diagnostics refreshes instead of stored diagnostics.
Description check Passed The description directly explains the intermittent test failure, the synchronization change, and the validation results.
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.
  • Fix all pre-merge checks with AI

Comment @coderabbitai help to get the list of available commands.

@angelozerr angelozerr moved this to In Progress in Java Tooling Oct 20, 2026
@angelozerr angelozerr added the bug Something isn't working label Oct 20, 2026
@angelozerr angelozerr added this to the 0.21.1 milestone Oct 20, 2026
@angelozerr

Copy link
Copy Markdown
Contributor

LGTM, thanks @lagergren !

@angelozerr
angelozerr merged commit 6e4f9a8 into redhat-developer:main Oct 20, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Java Tooling Oct 20, 2026
@lagergren
lagergren deleted the fix/diagnostics-applier-test-wait branch October 26, 2026 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants