Fixed Test Order Dependency Flakiness in ExecutableStepsTest.testBoundInputEvent #1462
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.
Fixes #1461
Motivation
ExecutableStepsTest.testBoundInputEventfails when executed on it's own because it is an Order-Dependent test that requiresRunEnvironmentSensitiveTest.testRunEnvironmentAllSensitiveto initialize shared static state beforehand. Specifically,testRunEnvironmentAllSensitiveloads a Spring context that initializes theEncryptionProvider's staticAtomicReference<Encryption>cache, whichtestBoundInputEventdepends on. As a result, the test can fail due to external factors not setting up it's state correctly, despite the test and the code that it is testing remaining unchanged. Order dependent flaky tests can lead to unreliable results from CI and can erode developer trust in the test suite.Modifications
SlangEntitiesSpringConfig.classwas added to the ExecutableStepsTest class' ContextConfiguration, thus providing an Application state context bean to allow the ExecutableStepsTest test suite to run independently ofRunEnvironmentSensitiveTest. However, after making this change,ExecutableStepsTest.testBoundInputEventnow pollutedRunEnvironmentSensitiveTest.testRunEnvironmentAllSensitivebecause theEncryptionPRoviderclass uses a staticAtomicReference<Encryption>cache that persists across test classes. WhenExecutableStepsTestruns first, it caches its own Encryption bean implementation in this static field, which then gets reused byRunEnvironmentSensitiveTest, causing that test to fail with the wrong encryption behavior.To solve this order dependency issue, a helper method
clearEncryptionProviderCachewas introduced which uses reflection to access the private staticencryptorfield inEncryptionProviderand clears the cachedEncryptioninstance. This method is called before and after each test so thatExecutableStepsTestboth starts with a clean state and does not pollute the state for subsequent tests in other test classes.As a result, these tests are no longer order dependent of one another, as each test class properly initializes and cleans up the shared static encryption provider cache.
Affected Tests
This change affects the existing tests:
(After adding
SlangEntitiesSpringConfig.classto ExecutableStepsTest class' ContextConfiguration,testBoundInputEventstarted polluting it's state and causing it to fail. Additional modifications were incorporated to fix this problem)Tools Used
iDFlakies was utilized to identify the order dependent polluter(s), victim(s), and cleaner(s) in the test suite(s). The tool functions by repeatedly running a project's JUnit tests under many different deterministic test orders to detect flaky tests which pass and fail inconsistently, and then re-executes the failing orders to classify each flaky test as either order-dependent or non-order-dependent. iFixFlakies was executed on the output to further diagnose the source of the problems and additionally generate test helper patches from existing cleaners that were found. With the combination of these tools, I was able to more easily diagnose the source(s) of the problem(s) and create effective solution(s) for them.