Fix Non-Deterministic Behavior in AlignedByDeviceTest #16688
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix Non-Deterministic Behavior in AlignedByDeviceTest
Problem
Nine tests in
AlignedByDeviceTestwere failing non-deterministically under NonDex (50-100% failure rates) due to order-dependent fragment assertions:testAggregation2Device2RegiontestAggregation2Device2RegionOrderByTimetestAggregation2Device2RegionWithValueFiltertestAggregation2Device2RegionWithValueFilterOrderByTimetestAggregation2Device3RegionWithValueFiltertestAggregation2Device3RegionWithValueFilterOrderByTimetestDiffFunction2Device2RegiontestDiffFunction2Device3RegiontestDiffFunctionWithOrderByTime2Device3RegionWay to Reproduce
Root Cause
Tests used fixed-index access to fragments (
plan.getInstances().get(0)) assuming deterministic order:Fragment order is non-deterministic due to HashMap iteration during distributed query planning. When NonDex shuffled collection order, fragments appeared at different positions, causing assertions to fail even though the query plan was semantically correct.
Solution
Made assertions order-independent by counting node types across all fragments instead of assuming fixed positions.
Added Helper Methods
Transformed Assertions
Before (Order-Dependent):
After (Order-Independent):
Key Improvements
>= Ninstead of exact position checks)Key Changed Classes