This is an automated email from the ASF dual-hosted git repository.

borinquenkid pushed a commit to branch fix/optimistic-locking-spec-join-assert
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit cd0502f3bc84a3d62a50b0035b7be33867c36fe7
Author: Walter Duque de Estrada <[email protected]>
AuthorDate: Thu Jul 30 16:58:47 2026 -0500

    fix(neo4j): assert background thread completion in OptimisticLockingSpec
    
    Follow-up to #16070. Copilot's review flagged that the second test's
    Thread.start { ... }.join(2000) can return on timeout without the
    background thread having actually finished, so the "same headroom
    rationale" comment added in #16070 was inaccurate there: the sleep
    could still be masking a race with thread completion, unlike the
    first test where the unbounded join() guarantees it. Capture the
    thread and assert !isAlive() after the bounded join so a slow runner
    fails loudly instead of silently racing the assertions that follow.
    
    Co-Authored-By: Claude Sonnet 5 <[email protected]>
---
 .../grails/gorm/tests/OptimisticLockingSpec.groovy  | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git 
a/grails-data-neo4j/grails-datastore-gorm-neo4j/src/test/groovy/grails/gorm/tests/OptimisticLockingSpec.groovy
 
b/grails-data-neo4j/grails-datastore-gorm-neo4j/src/test/groovy/grails/gorm/tests/OptimisticLockingSpec.groovy
index 318bc0eb6f..e0160d0efa 100644
--- 
a/grails-data-neo4j/grails-datastore-gorm-neo4j/src/test/groovy/grails/gorm/tests/OptimisticLockingSpec.groovy
+++ 
b/grails-data-neo4j/grails-datastore-gorm-neo4j/src/test/groovy/grails/gorm/tests/OptimisticLockingSpec.groovy
@@ -130,17 +130,18 @@ class OptimisticLockingSpec extends GormDatastoreSpec {
         when:
         o = OptLockNotVersioned.get(o.id)
 
-        try {
-            Thread.start {
-                OptLockNotVersioned.withNewSession { s ->
-                    def reloaded = OptLockNotVersioned.get(o.id)
-                    reloaded.name += ' in new session'
-                    reloaded.save(flush: true)
-                }
-            }.join(2000)
-        } catch (InterruptedException e) {
-            // ignore
+        def backgroundUpdate = Thread.start {
+            OptLockNotVersioned.withNewSession { s ->
+                def reloaded = OptLockNotVersioned.get(o.id)
+                reloaded.name += ' in new session'
+                reloaded.save(flush: true)
+            }
         }
+        // Unlike the unbounded join() above, join(timeout) can return before 
the thread
+        // finishes; assert completion explicitly so a slow runner fails 
loudly instead of
+        // silently racing the assertions below.
+        backgroundUpdate.join(5000)
+        assert !backgroundUpdate.isAlive()
         // Same headroom rationale as "Test optimistic locking" above.
         sleep 5000
 

Reply via email to