kabo87777 opened a new pull request, #16612:
URL: https://github.com/apache/iotdb/pull/16612
# Fix Non-Deterministic Behavior in
AggregationDistributionTest.testEachSeriesOneRegion
## Problem
The test `testEachSeriesOneRegion` was failing non-deterministically under
NonDex with a 33% failure rate (1 out of 3 runs) due to order-dependent child
node access.
## Way to Reproduce
```bash
cd iotdb-core/datanode
mvn edu.illinois:nondex-maven-plugin:2.1.1:nondex \
-Dtest=AggregationDistributionTest#testEachSeriesOneRegion \
-DnondexRuns=5
# Expected: Test fails with certain NonDex seeds (e.g., 974622)
# Failure: AssertionError when checking for HorizontallyConcatNode at fixed
position
```
## Root Cause
The test assumed every fragment has a `HorizontallyConcatNode` as the first
child (at position 0) of the plan tree root:
```java
fragmentInstances.forEach(
fragmentInstance ->
assertTrue(
fragmentInstance.getFragment().getPlanNodeTree().getChildren().get(0)
instanceof HorizontallyConcatNode));
```
This approach had two issues:
1. **Position-dependent**: Assumed `HorizontallyConcatNode` is always at
`.getChildren().get(0)`
2. **Over-constrained**: Assumed every fragment has
`HorizontallyConcatNode`, when only some fragments may have it
When NonDex shuffled collection iteration order during query planning, the
plan tree structure varied, causing some fragments to not have
`HorizontallyConcatNode` at position 0 or at all.
## Solution
Made the test **order-independent** by counting fragments that contain
`HorizontallyConcatNode` anywhere in their plan tree, rather than checking a
specific position:
**Before (Order-Dependent):**
```java
fragmentInstances.forEach(
fragmentInstance ->
assertTrue(
fragmentInstance.getFragment().getPlanNodeTree().getChildren().get(0)
instanceof HorizontallyConcatNode));
```
**After (Order-Independent):**
```java
int horizontallyConcatNodeCount = 0;
for (FragmentInstance fragmentInstance : fragmentInstances) {
PlanNode root = fragmentInstance.getFragment().getPlanNodeTree();
if (countNodesOfType(root, HorizontallyConcatNode.class) > 0) {
horizontallyConcatNodeCount++;
}
}
assertTrue(
"Expected at least one fragment with HorizontallyConcatNode",
horizontallyConcatNodeCount >= 1);
```
### Key Changes:
1. **Recursive search**: Uses `countNodesOfType()` helper to search the
entire plan tree, not just the first child
2. **Flexible assertion**: Verifies at least one fragment contains
`HorizontallyConcatNode`, rather than requiring all fragments to have it at a
specific position
## Verification
Tested with 50 NonDex runs - **0 failures** (100% success rate):
```bash
mvn edu.illinois:nondex-maven-plugin:2.1.1:nondex \
-Dtest=AggregationDistributionTest#testEachSeriesOneRegion \
-DnondexRuns=50
# Result: 0 failures
```
## Key Changed Classes
- **AggregationDistributionTest**:
- Modified `testEachSeriesOneRegion` test method to use order-independent
`HorizontallyConcatNode` verification
- Leverages existing `countNodesOfType()` helper method for recursive plan
tree traversal
--
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]