xuxiaowei-com-cn opened a new pull request, #8175:
URL: https://github.com/apache/incubator-seata/pull/8175
onProcessEvent() submits onChangeEvent async to a thread pool by default.
The test asserted changeEventCalled immediately, racing the executor thread.
Use CountDownLatch with 5s timeout to wait for the async callback before
asserting.
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Please make sure you have read and understood the contributing
guidelines -->
- [ ] I have read the
[CONTRIBUTING.md](https://github.com/apache/incubator-seata/blob/2.x/CONTRIBUTING.md)
guidelines.
- [ ] I have registered the PR
[changes](https://github.com/apache/incubator-seata/tree/2.x/changes).
### Ⅰ. Describe what this PR did
Fix flaky
`ConfigurationChangeListenerTest.testCachedConfigurationChangeListener()`.
**Problem:** The default implementation of
`ConfigurationChangeListener.onProcessEvent()` submits the `onChangeEvent()`
callback to a thread pool via `ExecutorService.submit()`, returning
immediately. The original test asserted `changeEventCalled == true` **right
after** calling `onProcessEvent()`, creating a race condition with the pool
worker thread. Under CI load this fails intermittently:
```
[ERROR]
ConfigurationChangeListenerTest.testCachedConfigurationChangeListener:234
expected: <true> but was: <false>
```
**Fix:** Introduce a `CountDownLatch` synchronization mechanism:
- Call `latch.countDown()` inside the anonymous
`CachedConfigurationChangeListener.onChangeEvent()` callback.
- Call `latch.await(5, TimeUnit.SECONDS)` to wait for async callback
completion with a 5-second timeout.
- Add `throws InterruptedException` to the test method signature.
### Ⅱ. Does this pull request fix one issue?
<!-- If that, add "fixes #xxx" below in the next line, for example, fixes
#97. -->
fixes https://github.com/apache/incubator-seata/issues/8174
### Ⅲ. Why don't you add test cases (unit test/integration test)?
This change is the test fix itself — no additional test cases are needed.
The updated test uses `CountDownLatch` to ensure the async callback completes
before asserting, eliminating the race condition.
### Ⅳ. Describe how to verify it
```bash
# Single run
mvn test -pl config/seata-config-core
-Dtest=ConfigurationChangeListenerTest#testCachedConfigurationChangeListener
# Stress test (loop to ensure stability)
for i in $(seq 1 50); do
mvn test -pl config/seata-config-core
-Dtest=ConfigurationChangeListenerTest#testCachedConfigurationChangeListener -q
echo "Run $i: $?"
done
```
Before the fix, failures occur intermittently. After the fix, the test
should pass 100% of the time.
### Ⅴ. Special notes for reviews
- Test-only change — no production code is touched.
- `CountDownLatch` is the lightest-weight "wait for async completion"
mechanism in the Java concurrency standard library with zero external
dependencies.
- The 5-second timeout is sufficient for normal execution while preventing
the test from hanging indefinitely in extreme scenarios.
--
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]