Heavy tests and application lifecycle

Hello!

Some of my heavy tests trigger the loading of some application services. Their dispose() method is never called, neither after the test suite or at the end of the test process. Is this expected?

Overall, can we have more control over the application-level services lifecycle for heavy and light tests? I would like to have some influence over when they are started/disposed to test different things.

Thanks!

Yes, that’s expected.
In the current test framework, application-level services belong to the shared test application, not to an individual heavy or light test. HeavyPlatformTestCase and LightPlatformTestCase both run against the same TestApplicationManager, and normal per-test teardown cleans project state, not the application container. So for a real application service, dispose() is not expected to run after each test.

More generally, heavy vs light tests do not give separate control over the application-service lifecycle. They mainly differ in project setup. Application services usually live until the test application is shut down at the end of the suite/process.

If you need per-test control, the usual approach is:

  • use getServiceIfCreated() if you want to check whether a lazy service was already instantiated,
  • replace/register the application service with a test instance scoped to your own disposable,
  • or move the logic you want to test into a separate disposable object and test that directly.

So the short answer is: yes, this behavior is expected, and there is no standard per-test start/stop lifecycle for real application services in heavy/light tests.

Got it, thanks for the answer. The only thing that still puzzles me is that dispose() is not called on my application service even when the test process/application shuts down at the very end of tests. Is this expected too?

Not exactly.

If the framework really disposes the test application, then an instantiated application service should normally be disposed too. That goes through disposeTestApplication() / disposeApplicationAndCheckForLeaks() and eventually ApplicationImpl.disposeContainer().

So if you never see dispose(), even at the very end, the likely issue is that this run never reached the final application-shutdown path. That can happen in local runs if the final suite hook is skipped or the process ends right after the tests finish.

In short:

  • not disposed after each heavy/light test: expected
  • not disposed on real framework shutdown: usually not expected
  • not disposed because shutdown never ran: possible, especially in local or non-suite runs