Skip to content

Adapt legacyui tests to TRUNK-6558 (JobRunr scheduler) and AddressSupport singleton - #260

Open
wikumChamith wants to merge 3 commits into
openmrs:masterfrom
wikumChamith:fix-TRUNK-6558
Open

Adapt legacyui tests to TRUNK-6558 (JobRunr scheduler) and AddressSupport singleton#260
wikumChamith wants to merge 3 commits into
openmrs:masterfrom
wikumChamith:fix-TRUNK-6558

Conversation

@wikumChamith

@wikumChamith wikumChamith commented Apr 27, 2026

Copy link
Copy Markdown
Member

Two openmrs-core 3.0.0-SNAPSHOT changes broke the legacyui suite:

  • TRUNK-6558 swapped the timer-based SchedulerService for JobRunr. TaskDefinition.taskInstance is no longer populated, so anything reading
    task.getTaskInstance().isExecuting() is broken. Live state is now on SchedulerService.getTask(uuid).getState().
  • LUI-199 moved address-template reads behind the AddressSupport singleton, which caches per-JVM and inherits dirty state from earlier tests in the
    run.

Changes

  • SchedulerFormController — fix the "don't reschedule a running task" guard (was always true under JobRunr, so the controller silently rescheduled
    in-flight jobs). Now uses getTask(uuid).getState() != PROCESSING.
  • ShortPatientFormValidatorTest / ShortPatientFormControllerTest — @BeforeEach resets the AddressSupport singleton: writes a clean
    layout.address.format GP and calls AddressSupport.getInstance().globalPropertyChanged(...) directly (the listener can be registered against a stale
    Spring context on CI).
  • TaskHelper.waitUntilTaskIsExecuting — polls SchedulerService.getTask(uuid).getState() instead of taskInstance. Wait budget bumped 2s→60s to match
    JobRunr's poll cadence.
  • TaskHelperTest.xml — repeat_interval 3600→0 so the scheduled job is a one-off and observable via getTask(task.uuid).
  • TaskHelperTest — both wait tests re-enabled.
  • SchedulerFormControllerTest — the two reschedule tests stay @Disabled. Verifying them needs JobRunr to actually persist + run jobs across a test
    transaction, which BaseModuleWebContextSensitiveTest's rollback-per-test base doesn't support. Equivalent coverage lives in core's
    SchedulerServiceIT.

@wikumChamith
wikumChamith requested a review from dkayiwa April 27, 2026 11:12
@wikumChamith wikumChamith assigned ibacher and unassigned ibacher Apr 27, 2026
…port singleton

  1. Reset AddressSupport singleton state in ShortPatientFormValidatorTest

  PersonAddressValidator was changed in core (openmrs/openmrs-core#5839) to read the address template via the AddressSupport
  singleton instead of LocationService.getAddressTemplate(). The singleton caches the template across tests — when AddressSupportTest loads
  personAddressValidatorTestDataset.xml (which sets <requiredElements><string>address1</string></requiredElements>) into the global property, every
  subsequent test in the same JVM inherits address1 as a required field, even though the DB-level GP is rolled back at end-of-test.

  Fix: a @beforeeach in ShortPatientFormValidatorTest now sets layout.address.format via AdministrationService.setGlobalProperty(...) to a template
  with empty <requiredElements/>. This goes through the AdminService listener chain and refreshes the cached singleton state to a known-good baseline
   before each test.

  2. Disable scheduler tests broken by JobRunr migration

  openmrs/openmrs-core#5893 replaced TimerSchedulerServiceImpl with JobRunrSchedulerService. The new
  scheduleTask(TaskDefinition) returns null and never populates TaskDefinition.taskInstance — the legacy in-memory pointer that the disabled tests
  rely on. TaskDefinition/Task are now @deprecated; "is currently executing" is observable only through the new
  SchedulerService.getTask(uuid).getState() == TaskState.PROCESSING API.

  Four tests are marked @disabled with comments pointing at TRUNK-6558:
  - SchedulerFormControllerTest.onSubmit_shouldRescheduleACurrentlyScheduledTask
  - SchedulerFormControllerTest.onSubmit_shouldNotRescheduleAnExecutingTask
  - TaskHelperTest.waitUntilTaskIsExecuting_shouldWaitUntilTaskIsExecuting
  - TaskHelperTest.waitUntilTaskIsExecuting_shouldRaiseATimeoutExceptionWhenTheTimeoutIsExceeded

(cherry picked from commit d0d3232)
@dkayiwa

dkayiwa commented Apr 27, 2026

Copy link
Copy Markdown
Member

Did you get a chance to look at the failing builds?

@wikumChamith

Copy link
Copy Markdown
Member Author

Did you get a chance to look at the failing builds?

Yeah I am looking at them. I am only seeing them on GHA

…port singleton

  ▎ Fix: a @beforeeach in ShortPatientFormValidatorTest and ShortPatientFormControllerTest sets layout.address.format to a template with empty
  ▎ <requiredElements/> and directly invokes AddressSupport.getInstance().globalPropertyChanged(...). The direct call is needed because in CI the
  ▎ singleton's listener can be registered against a stale Spring context, in which case setGlobalProperty notifies a different listener list and the
  ▎  cached template stays polluted.
@wikumChamith
wikumChamith requested review from ibacher April 27, 2026 14:01
@wikumChamith

wikumChamith commented Apr 27, 2026

Copy link
Copy Markdown
Member Author

Did you get a chance to look at the failing builds?

Fixed it :)

…port singleton

  Two openmrs-core 3.0.0-SNAPSHOT changes broke the legacyui suite:

  - TRUNK-6558 swapped the timer-based SchedulerService for JobRunr. TaskDefinition.taskInstance is no longer populated, so anything reading
  task.getTaskInstance().isExecuting() is broken. Live state is now on SchedulerService.getTask(uuid).getState().
  - LUI-199 moved address-template reads behind the AddressSupport singleton, which caches per-JVM and inherits dirty state from earlier tests in the
   run.

  Changes

  - SchedulerFormController — fix the "don't reschedule a running task" guard (was always true under JobRunr, so the controller silently rescheduled
  in-flight jobs). Now uses getTask(uuid).getState() != PROCESSING.
  - ShortPatientFormValidatorTest / ShortPatientFormControllerTest — @beforeeach resets the AddressSupport singleton: writes a clean
  layout.address.format GP and calls AddressSupport.getInstance().globalPropertyChanged(...) directly (the listener can be registered against a stale
   Spring context on CI).
  - TaskHelper.waitUntilTaskIsExecuting — polls SchedulerService.getTask(uuid).getState() instead of taskInstance. Wait budget bumped 2s→60s to match
   JobRunr's poll cadence.
  - TaskHelperTest.xml — repeat_interval 3600→0 so the scheduled job is a one-off and observable via getTask(task.uuid).
  - TaskHelperTest — both wait tests re-enabled.
  - SchedulerFormControllerTest — the two reschedule tests stay @disabled. Verifying them needs JobRunr to actually persist + run jobs across a test
  transaction, which BaseModuleWebContextSensitiveTest's rollback-per-test base doesn't support. Equivalent coverage lives in core's
  SchedulerServiceIT.
@dkayiwa

dkayiwa commented May 4, 2026

Copy link
Copy Markdown
Member

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented May 4, 2026

Copy link
Copy Markdown
✅ Actions performed

Full review triggered.

@coderabbitai

coderabbitai Bot commented May 4, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@dkayiwa has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 36 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f6ad2b8e-90f0-4547-bc14-40e1dc791714

📥 Commits

Reviewing files that changed from the base of the PR and between 8f2096b and 0614f98.

📒 Files selected for processing (7)
  • omod/src/main/java/org/openmrs/scheduler/web/controller/SchedulerFormController.java
  • omod/src/test/java/org/openmrs/scheduler/web/controller/SchedulerFormControllerTest.java
  • omod/src/test/java/org/openmrs/scheduler/web/controller/TaskHelper.java
  • omod/src/test/java/org/openmrs/scheduler/web/controller/TaskHelperTest.java
  • omod/src/test/java/org/openmrs/web/controller/patient/ShortPatientFormControllerTest.java
  • omod/src/test/java/org/openmrs/web/controller/patient/ShortPatientFormValidatorTest.java
  • omod/src/test/resources/org/openmrs/web/include/TaskHelperTest.xml
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 5 minutes and 36 seconds.

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

@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.

3 participants