Skip to content

Stabilize flaky HibernateAdministrationDAOTest OutboxEvent metadata lookup#6326

Open
dkayiwa wants to merge 1 commit into
openmrs:2.9.xfrom
dkayiwa:fix-hibernateadmindao-outbox-flaky-test-2.9.x
Open

Stabilize flaky HibernateAdministrationDAOTest OutboxEvent metadata lookup#6326
dkayiwa wants to merge 1 commit into
openmrs:2.9.xfrom
dkayiwa:fix-hibernateadmindao-outbox-flaky-test-2.9.x

Conversation

@dkayiwa

@dkayiwa dkayiwa commented Jul 15, 2026

Copy link
Copy Markdown
Member

Problem

HibernateAdministrationDAOTest.getMaximumPropertyLength_* fails intermittently in CI with:

org.openmrs.api.APIException: Couldn't find a class in the hibernate configuration named: org.openmrs.event.outbox.OutboxEvent
	at org.openmrs.api.db.hibernate.HibernateAdministrationDAO.getMaximumPropertyLength(HibernateAdministrationDAO.java:232)

Root cause

HibernateAdministrationDAO captures the boot-time Hibernate Metadata once, in setApplicationContext, from HibernateSessionFactoryBean.getMetadata(). OutboxEvent is a @Entity with no hbm.xml, so it is registered only via the packagesToScan = org.openmrs annotation scan. When an earlier test in the same fork rebuilds the shared Spring context, the DAO can end up holding a Metadata that omits OutboxEvent, and metadata.getEntityBinding(...) returns null. The class passes in isolation and only fails in some full-suite orderings, i.e. order-dependent context pollution, not a code regression.

Fix

Force a fresh context for this test class with @DirtiesContext(classMode = BEFORE_CLASS), so the DAO's Metadata is rebuilt from a full org.openmrs scan that includes OutboxEvent.

Verification and caveat

The class passes in isolation (6/6) both before and after the change, confirming a fresh context has OutboxEvent and that the annotation is honored (the base test's @TestExecutionListeners use MERGE_WITH_DEFAULTS, so the DirtiesContext listeners are registered). I could not reproduce the order-dependent failure locally to prove elimination against a live repro, so this is a mechanism-sound, verified-non-breaking mitigation rather than a repro-verified one.

Scope

Only the 2.9.x line has these getMaximumPropertyLength/OutboxEvent tests, so this targets 2.9.x directly. master has the DAO method but not these tests; 2.8.x has no OutboxEvent. This is the first use of @DirtiesContext in the repo.

…ookup

getMaximumPropertyLength(OutboxEvent.class, ...) intermittently failed with
"Couldn't find a class in the hibernate configuration named:
org.openmrs.event.outbox.OutboxEvent". HibernateAdministrationDAO captures the
boot-time Hibernate Metadata once at context creation; when an earlier test in
the same fork rebuilds the shared Spring context, the DAO can end up holding a
Metadata that omits the annotation-scanned OutboxEvent entity, so the lookup
throws. The class passes in isolation and only fails in some full-suite
orderings.

Force a fresh context for this test class (@DirtiesContext BEFORE_CLASS) so the
DAO's Metadata is rebuilt from a full org.openmrs package scan that includes
OutboxEvent.

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

Copy link
Copy Markdown

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