Skip to content

test(neo4j): give OptimisticLockingSpec's cross-thread heisenbug more headroom - #16070

Merged
borinquenkid merged 1 commit into
feat/gorm-registry-core-implfrom
test/neo4j-optimistic-locking-spec-flake
Jul 30, 2026
Merged

test(neo4j): give OptimisticLockingSpec's cross-thread heisenbug more headroom#16070
borinquenkid merged 1 commit into
feat/gorm-registry-core-implfrom
test/neo4j-optimistic-locking-spec-flake

Conversation

@borinquenkid

Copy link
Copy Markdown
Member

Summary

CI on #15972 (Neo4j GormRegistry migration) hit a failure in OptimisticLockingSpec > Test optimistic locking on a loaded macos-latest runner, consistently across all 3 matrix legs of that run.

Investigation (see discussion on #15972) traced this to the test's own pre-existing timing sensitivity, not a regression from the GormRegistry/Neo4jGormApiFactory wiring:

  • The unmodified test passes locally, deterministically, against the exact commit that failed in CI — including correct OptimisticLockingException detection through the new registry-based API resolution.
  • The background thread's write is already synchronized with the main thread via .join() before the sleep runs, so the sleep isn't providing thread-completion synchronization — it's headroom for the embedded Neo4j 3.5.x test harness's own write durability.
  • The test's own code comment (// heisenbug) already flags this as a known flaky spot.

A loaded CI runner can apparently push that durability window past the existing 2-second sleep. This PR bumps it to 5 seconds in both affected examples (Test optimistic locking and Test optimistic locking disabled with 'version false') and documents why, rather than leaving the bare // heisenbug comment.

Test plan

🤖 Generated with Claude Code

… headroom

CI on PR #15972 (Neo4j GormRegistry migration) hit a reproducible-looking
failure in "Test optimistic locking" on a loaded macos-latest runner.
Investigation traced it to this test's own pre-existing timing sensitivity
(flagged by its own "heisenbug" comment), not a regression from the
GormRegistry wiring: the unmodified test passes locally against the exact
failing commit, and the background thread's write is already synchronized
via join() before the sleep runs. The sleep is headroom for the embedded
Neo4j 3.5.x harness's own write durability, which a noisy CI runner can
push past 2 seconds. Bumped to 5 seconds in both affected examples.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to reduce CI flakiness in the Neo4j GORM test suite by giving the known timing-sensitive OptimisticLockingSpec tests more durability headroom on loaded runners, and documenting the rationale for the wait.

Changes:

  • Increased the post-join sleep in two optimistic-locking-related tests from 2s to 5s.
  • Replaced the vague // heisenbug note with a clearer explanation of what the delay is intended to cover.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 140 to +144
}.join(2000)
} catch (InterruptedException e) {
// ignore
}
sleep 2000 // heisenbug
// Same headroom rationale as "Test optimistic locking" above.
@bito-code-review

Copy link
Copy Markdown

The suggestion to replace sleep with a bounded join() is technically sound and improves test reliability. Using thread.join(timeout) combined with an assertion that the thread has actually finished (e.g., assert thread.isAlive() == false) ensures the test waits for the thread to complete rather than relying on an arbitrary sleep duration, which is prone to race conditions in loaded environments.

grails-data-neo4j/grails-datastore-gorm-neo4j/src/test/groovy/grails/gorm/tests/OptimisticLockingSpec.groovy

def t = Thread.start { ... }
        t.join(5000)
        assert !t.isAlive()

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52.1558%. Comparing base (e049502) to head (184020c).
⚠️ Report is 1 commits behind head on feat/gorm-registry-core-impl.

Additional details and impacted files

Impacted file tree graph

@@                          Coverage Diff                           @@
##             feat/gorm-registry-core-impl     #16070        +/-   ##
======================================================================
- Coverage                         52.1714%   52.1558%   -0.0155%     
+ Complexity                          18415      18408         -7     
======================================================================
  Files                                2054       2054                
  Lines                               96622      96622                
  Branches                            16846      16846                
======================================================================
- Hits                                50409      50394        -15     
- Misses                              38823      38835        +12     
- Partials                             7390       7393         +3     

see 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@borinquenkid
borinquenkid merged commit 184020c into feat/gorm-registry-core-impl Jul 30, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants