fix testEachSeriesOneRegion
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
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:
fragmentInstances.forEach(
fragmentInstance ->
assertTrue(
fragmentInstance.getFragment().getPlanNodeTree().getChildren().get(0)
instanceof HorizontallyConcatNode));
This approach had two issues:
-
Position-dependent: Assumed
HorizontallyConcatNodeis always at.getChildren().get(0) -
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):
fragmentInstances.forEach(
fragmentInstance ->
assertTrue(
fragmentInstance.getFragment().getPlanNodeTree().getChildren().get(0)
instanceof HorizontallyConcatNode));
After (Order-Independent):
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:
-
Recursive search: Uses
countNodesOfType()helper to search the entire plan tree, not just the first child -
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):
mvn edu.illinois:nondex-maven-plugin:2.1.1:nondex \
-Dtest=AggregationDistributionTest#testEachSeriesOneRegion \
-DnondexRuns=50
# Result: 0 failures
Key Changed Classes
-
AggregationDistributionTest:
- Modified
testEachSeriesOneRegiontest method to use order-independentHorizontallyConcatNodeverification - Leverages existing
countNodesOfType()helper method for recursive plan tree traversal
- Modified