Remove non-determinism from MySqlCreateDatabaseTest.test_3 #6240
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 Description:
For the test MySqlCreateDatabaseTest.test_3,
The function SQLASTOutputVisitor.visit() (Line:10474) method iterates a Set<Map.Entry<String, SQLName>> in a for loop, but the iteration is non-deterministic (as mentioned in javadocs) thus causing different outputs. Therefore, this test is non-determinstic since following assertions fail unexpectedly.
Error observed:
[INFO] Running com.alibaba.druid.bvt.sql.mysql.create.MySqlCreateDatabaseTest
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.414 s <<< FAILURE! - in com.alibaba.druid.bvt.sql.mysql.create.MySqlCreateDatabaseTest
[ERROR] com.alibaba.druid.bvt.sql.mysql.create.MySqlCreateDatabaseTest.test_3 Time elapsed: 0.403 s <<< FAILURE!
org.junit.ComparisonFailure:
expected:<...RED BY 'OTS'
WITH ([column_mapping = 'pk:pk,a:col1,b:col2', serializer = 'default]')> but was:<...RED BY 'OTS'
WITH ([serializer = 'default', column_mapping = 'pk:pk,a:col1,b:col2]')>
at org.junit.Assert.assertEquals(Assert.java:117)
at org.junit.Assert.assertEquals(Assert.java:146)
at com.alibaba.druid.bvt.sql.mysql.create.MySqlCreateDatabaseTest.test_3(MySqlCreateDatabaseTest.java:64)
Reproduce the failure:
One can check it using the Nondex:
Solution:
One solution that I thought of was to sort the set and then iterate to make the order deterministic.
Please let me know if you have any questions or need any additional justification/changes from my side.