-
-
Notifications
You must be signed in to change notification settings - Fork 429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed a few non deterministic tests in the repository #4475
base: main
Are you sure you want to change the base?
Conversation
50cd6ef
to
889c64c
Compare
Signed-off-by: Yug Vajani <[email protected]>
If you like fixing flaky tests, we have a few more. 😉 See: https://github.com/openhab/openhab-core/issues?q=is%3Aopen+is%3Aissue+label%3Atest |
Certainly, I'll take a look at these. In the meantime, could you review my changes and let me know if they're ready to merge? |
@wborn could you provide the steps to reproduce the failed tests? |
@wborn Do I need an account to access Jules logs? The Jenkins link provided in the issue appears to be invalid, and I am unable to reproduce the flaky tests locally. |
The builds get removed after a while to clean up space so that's why the links stop working. Most of the unstable tests are probably due to timing issues. It's sometimes easier to reproduce when you put a lot of CPU load on your computer while running the tests. During the CI builds there is also a lot of CPU load because it runs as a parallel Maven build ( The timing is also influenced by OS specific JVM implementation details. |
Did you use any Jenkins plugin for detecting flaky tests, such as the Flaky Test Handler Plugin, or could you recommend one which I could use? |
I would recommend not to add any plugin to our supply chain which has such a small developer community. As Wouter mentioned before, you can just |
I just create an issue everytime a test fails that normally succeeds. That makes it easier to figure out when another build also fails if it is due to a flaky test. Then when I'm in a "flaky test fixing mood" I try to fix them. 😉 |
Fix a few non deterministic tests in the repository
This pull request resolves several non-deterministic tests in the repository, addressing some of the tests mentioned in the issue openhab-core issue #4474.
There were a number of flaky tests in the repository which were detected using the NonDex tool. More details about the steps to reproduce it and the details for the tools are mentioned in openhab-core issue #4474.
Description
This PR fixes the following tests mentioned below and the steps to reproduce the issue is already mentioned in openhab-core issue #4474:
For the tests:
The reason for flakiness is that since JSON-like structure is being compared using assertEquals, order dependency could cause the test to fail. JSON properties may not always maintain the same order, depending on the implementation of the object creation or serialization.
A JSON parser was utilized to process the objects before comparison. This ensures the content is evaluated irrespective of property order, resolving the order dependency issue.
For the test:
The test org.openhab.core.cache.ExpiringCacheMapTest.testValues failed due to non-deterministic ordering in the subject.values() function, causing assertEquals to fail.
The values were converted to a LinkedHashSet before comparison. This guarantees a consistent, deterministic order.
For the tests:
The flakiness in the tests are caused by non-deterministic ordering of the ConfigValidationMessage objects in the exception. The params map's entries are iterated in a non-deterministic order when processed by the configDescriptionValidator.validate method. This can result in the order of ConfigValidationMessage objects in the exception being inconsistent across different test runs.
To fix the test, I made use of the containsInAnyOrder matcher which ensures the comparison focuses on the content of the messages without depending on their order.
For the tests:
The reason for flakiness is that YAML is a human-readable data serialization format, but it does not guarantee a deterministic order for keys in mappings. If the YamlModelRepositoryImpl modifies the content or serializes the added element in a different key order than expected, the string comparison (is(expectedFileContent)) will fail, even if the data structures are logically equivalent.
The fix involves making use of YAML parser to load the file contents as structured objects ensuring order independence.