Anshul-creator opened a new pull request, #15744:
URL: https://github.com/apache/dubbo/pull/15744
## What is the purpose of the change?
This PR fixes **order-dependent flakiness (OD-Vic)** in
`ExtensionLoaderTest.testInjectExtension`
This test intermittently fails under randomized test execution orders due to
multiple DemoImpl instances being registered in the shared ScopeBeanFactory of
ApplicationModel.
## Root Cause
`testInjectExtension` and related tests (`testGetOrDefaultExtension`) both
interacted with the same shared `ScopeBeanFactory`.
Because bean registration was not idempotent, repeated or parallel test
execution sometimes resulted in duplicate `DemoImpl` entries, leading to
inconsistent injection results or assertion failures.
## What's Changed
- Added defensive logic to check existing DemoImpl beans before registering
a new one.
- Made registration idempotent by registering only one instance
(demo-test-singleton) if none exists.
- Ensured subsequent tests reuse the same canonical bean reference.
- Updated testGetOrDefaultExtension to follow the same consistent setup.
These changes eliminate shared-state interference and make the test
deterministic under any order or random seed.
## Verification
You can try running the loop below on pre-fix and post-fix code:
```bash
fail=0; total=0
for s in 7138 7351 7892 11170 15857 15869 17721 20421 21699 22631 24059
29905; do
echo "SEED=$s"
total=$((total+1))
SEED=$s ./mvnw -pl dubbo-common -DfailIfNoTests=true -DforkCount=1
-DreuseForks=false \
-Dsurefire.runOrder=random \
-Djunit.jupiter.testclass.order.default=org.junit.jupiter.api.ClassOrderer\$Random
\
-Djunit.jupiter.testmethod.order.default=org.junit.jupiter.api.MethodOrderer\$Random
\
-Djunit.jupiter.testclass.order.random.seed="$s" \
-Djunit.jupiter.testmethod.order.random.seed="$s" \
-Dtest=org.apache.dubbo.common.extension.ExtensionLoaderTest test \
>/dev/null || { echo "** FAILED on SEED=$s **"; fail=$((fail+1)); }
done
echo
echo "===== SUMMARY ====="
echo "Total seeds: $total"
echo "Failed: $fail"
echo "Passed: $((total - fail))"
echo "==================="
```
The seeds were found by using a script I developed locally. Sometimes not
all seeds fail on execution, but some will always fail on pre-fix code.
However, on post-fix code none of the seeds fail.
## Checklist
- [x] Make sure there is a
[GitHub_issue](https://github.com/apache/dubbo/issues) field for the change.
- [x] Write a pull request description that is detailed enough to understand
what the pull request does, how, and why.
- [x] Write necessary unit-test to verify your logic correction. If the new
feature or significant change is committed, please remember to add sample in
[dubbo samples](https://github.com/apache/dubbo-samples) project.
- [x] Make sure gitHub actions can pass. [Why the workflow is failing and
how to fix it?](../CONTRIBUTING.md)
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]