micronaut-maven-plugin icon indicating copy to clipboard operation
micronaut-maven-plugin copied to clipboard

mn:run shuts down the test resources service after compile and doesn't restart it.

Open npiguet opened this issue 9 months ago • 1 comments

Expected Behavior

When my webapp is recompiled due to a change in the code, my application and all the containers it depends on are restarted. Then my application works as expected.

Ideally, to save some time, the test containers are never shut down and not restarted either (oracle is really slow to start).

Actual Behaviour

When my webapp is recompiled due to a change in the code, it restarts. However all the containers started by Micronaut test resources are shut down and never restarted, causing the application to fail to start

Steps To Reproduce

  • I start my application in the local environment using mvn mn:run -Dmicronaut.environments=test,local
  • My application as well as all the required DB containers are started
  • I change something in my code (for example, a minor detail in a .jte file)
  • Micronaut-maven-plugin prints this in the logs:

INFO] 📝 Detected change in src/main/resources/application-test.yml. Recompiling/restarting... [INFO] [info] Shutting down Micronaut Test Resources service

  • The application is stopped.
  • All the test containers are stopped.
  • The application is restarted, but crashes because it can't resolve the url property of one of my data sources (which makes sense, since it looks like the test resources service was stopped)

I've done a but of debugging, and it looks like this is caused by mn:run calling mvn compile in a different process when it detects changes to the watched directories. When that happens the new mvn compile runs as expected, but before terminating hits TestResourcesLifecycleExtension.afterSessionEnd(), which unconditionally stops the test resources service.

As far as I can tell, nothing in either process restarts it.

I would personally love it if it DID NOT shut down the test containers at all.

Environment Information

JDK 17 Ubuntu 22.04 Micronaut 4.4.2 micronaut-maven-plugin 4.5.3

npiguet avatar May 08 '24 18:05 npiguet

this is definitely a bug and unfortunate behaviour //cc @alvarosanchez @melix

graemerocher avatar May 08 '24 18:05 graemerocher

Running mvn mn:start-testresources-service in a separate terminal before mn:run works around the problem. That mechanism works as expected

npiguet avatar May 10 '24 12:05 npiguet

I have identified the problem, hoping to have a fix soon.

alvarosanchez avatar May 10 '24 13:05 alvarosanchez