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
Running maven tests with NonDex tool would discover flaky tests.
NonDex is a tool for detecting wrong assumptions on undeterministic Java APIs. It could help developers fix the assumption before it becomes a problem far in the future and more difficult to fix.
Reproduce step
Root cause
EagerTest related test
Take com.hubspot.jinjava.EagerTest#itHandlesImportInDeferredIf as an example, the test fails at assertion in
ExpectedTemplateInterpreter.java
L45jinjava/src/test/java/com/hubspot/jinjava/ExpectedTemplateInterpreter.java
Lines 39 to 46 in ddd35c0
The reason why it fails is that the rendered string is determined by the order of
HashMap.entrySet()
, which is called atAliasedEagerImportingStrategy.java
L255jinjava/src/main/java/com/hubspot/jinjava/lib/tag/eager/importing/AliasedEagerImportingStrategy.java
Line 255 in ddd35c0
However, the order of
HashMap.entrySet()
is not guaranteed. It might change from time to time.NonDex would shuffle the map on each invocation of methods.
Therefore, the rendered string might change, and make the tests fail.
PyishObjectMapperTest
For PyishObjectMapperTest test, it is the similar reason.
In L25,
HashMap
has been used. However, the assertion in L29 is relied on the order ofHashMap.entrySet()
jinjava/src/test/java/com/hubspot/jinjava/objects/serialization/PyishObjectMapperTest.java
Lines 24 to 31 in ddd35c0
Code change
To fix the test flakiness, I replaced
HashMap
withLinkedHashMap
in AliasedEagerImportingStrategy.java and PyishObjectMapperTest.java, and exchange the order of string to aligned with the order of `LinkedHashMapFailed test
com.hubspot.jinjava.EagerTest#itHandlesImportInDeferredIf
com.hubspot.jinjava.EagerTest#itHandlesDoubleImportModification
com.hubspot.jinjava.EagerTest#itHandlesSameNameImportVar
com.hubspot.jinjava.EagerTest#itDoesNotOverrideImportModificationInFor
com.hubspot.jinjava.EagerTest#itRreconstructsValueUsedInDeferredImportedMacro
com.hubspot.jinjava.EagerTest#itAllowsVariableSharingAliasName
com.hubspot.jinjava.NonRevertingEagerTest#itHandlesImportInDeferredIf
com.hubspot.jinjava.NonRevertingEagerTest#itHandlesDoubleImportModification
com.hubspot.jinjava.NonRevertingEagerTest#itHandlesSameNameImportVar
com.hubspot.jinjava.NonRevertingEagerTest#itDoesNotOverrideImportModificationInFor
com.hubspot.jinjava.NonRevertingEagerTest#itRreconstructsValueUsedInDeferredImportedMacro
com.hubspot.jinjava.NonRevertingEagerTest#itAllowsVariableSharingAliasName
com.hubspot.jinjava.lib.tag.eager.EagerImportTagTest#itDefersTripleLayer
com.hubspot.jinjava.lib.tag.eager.EagerImportTagTest#itHandlesQuadLayerInDeferredIf
com.hubspot.jinjava.lib.tag.eager.EagerImportTagTest#itDoesNotSilentlyOverrideVariable
com.hubspot.jinjava.objects.serialization.PyishObjectMapperTest#itSerializesMapWithNullKeysAsEmptyString
com.hubspot.jinjava.objects.serialization.PyishObjectMapperTest#itSerializesMapEntrySet
com.hubspot.jinjava.objects.serialization.PyishObjectMapperTest#itSerializesMapEntrySetWithLimit
com.hubspot.jinjava.objects.serialization.PyishObjectMapperTest#itSerializesMapWithNullValues