Croway commented on PR #31116:
URL: https://github.com/apache/camel/pull/31116#issuecomment-7274356823

   This follows up on the point in davsclaus's review about launcher 
executions. I reproduced it on 0eadda079fbf and checked the suggested guard.
   
   **Reproduction.** Three top-level test classes in `camel-test-infra-common` 
share one static `SingletonService`, as the factory holders do. 
`registerShutdownHook()` is overridden to count the hooks.
   
   | Run | Counts in the JVM |
   |---|---|
   | `-Dcamel.surefire.forkCount=1` | 1 initialization, 1 hook |
   | `-Dcamel.surefire.forkCount=2` | the fork that ran B, then C: 
`initializations=2 shutdownHooks=2` |
   | `forkCount=1`, a class that fails once, 
`-Dsurefire.rerunFailingTestsCount=2` | after the rerun: `initializations=2 
shutdownHooks=2` |
   
   **The suggested guard.** With an `AtomicBoolean shutdownHookRegistered` and 
`compareAndSet(false, true)` around `registerShutdownHook()`, both cases 
register 1 hook per JVM, and the 27 tests of the module pass. `initialize()` 
still runs once per launcher execution, as it already does on `main`.
   
   **Test.** `SingletonServiceTest` cannot see this case, because its nested 
classes run in one launcher execution. The test is in the same package, so a 
test can call `doInitializeService(...)` twice on a new `SingletonService`, 
which is what two launcher executions do, and expect one hook. That test fails 
on this head with `expected: <1> but was: <2>`, and passes with the guard.
   
   `camel infra run` is not affected either way. `InfraRun` creates the 
`@InfraService` implementation itself, never a `SingletonService`. It registers 
its own hook after `initialize()` and calls `shutdown()` at most once 
(`closed.compareAndSet`). So dropping the Event Hubs guard changes nothing 
there.
   
   _Claude Code on behalf of Croway_
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to