From cd0502f3bc84a3d62a50b0035b7be33867c36fe7 Mon Sep 17 00:00:00 2001 From: Walter Duque de Estrada Date: Thu, 30 Jul 2026 16:58:47 -0500 Subject: [PATCH] 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 --- .../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 318bc0eb6f2..e0160d0efa3 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