Improve test reliability by resolving nondeterministic of HashMap #316
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.
Problem
I detected the unstable For the test :
[INFO] org.apache.tez.dag.api.TestDAG#testRecreateDAG
[INFO] org.apache.tez.dag.api.TestDAGPlan#userVertexOrderingIsMaintained
(they both use verify and createDag function and will be affected by the order of the vertex map)
[INFO] org.apache.tez.dag.app.dag.impl.TestVertexImpl#testVertexInit
All these tests assume the order of the Map (but java provided one with ordered specification called LinkedHashMap). which was not true, and will trigger hidden bug when the test environment changes.
Solution
we used the order-specified one which is LinkedHashMap because the order does matter for the tests (and potential future tests especially because the serialization)
Do no worry too much about the performance because these tests was detected mainly because they will be used by iteration (and the order is un defined), the iteration have better performance for LinkedHashMap: https://stackoverflow.com/questions/12998568/hashmap-vs-linkedhashmap-performance-in-iteration-over-values
Reproduce
This error can be reproduced with the NondexTool with the following command (you can try that without modifying the pom, but feel free to use the plugin to protect your project and make it safer 😊 ), and this kind problem is widely documented in International Dataset of Flaky Tests (IDoFT)