-
Notifications
You must be signed in to change notification settings - Fork 0
fix flaky tests in the file EntityToSchemaMapperTest.java #1
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
base: master
Are you sure you want to change the base?
Conversation
Probably you want to remove the text |
@@ -30,10 +33,11 @@ class EntityToSchemaMapperTest { | |||
|
|||
@Test | |||
void testLink() throws Exception { | |||
Yaml yaml = new Yaml(new Constructor(Map.class)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can all the Yaml yaml = new Yaml(new Constructor(Map.class));
be extracted out and shared?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
final Schema<?> schema = mapper.mapEntity(Link.class, ClassMappingMode.DATA_ITEM, RequestType.RESPONSE); | ||
String json = SchemaUtils.writeValueAsString(false, schema); | ||
Map<String, Object> json = yaml.load(SchemaUtils.writeValueAsString(false, schema)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's weird to name it json
when it's yaml. Does SchemaUtils.writeValueAsString(false, schema)
return a YAML string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
I have added the hyperlink for all the failing test |
|
||
class EntityToSchemaMapperTest { | ||
|
||
private static final ScanResult emptyScanResult = new ScanResult(emptyMap(), emptySet(), emptySet(), emptySet()); | ||
|
||
private final TaskProperties taskProperties = new TaskProperties().setAddXLinkedEntity(true); | ||
|
||
private final Yaml yaml = new Yaml(new Constructor(Map.class)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra indentation?
} | ||
|
||
@Test | ||
void testMapAsDataItem() throws Exception { | ||
final Schema<?> schema = mapper.mapEntity(TestEntity.class, ClassMappingMode.DATA_ITEM, RequestType.RESPONSE); | ||
String json = SchemaUtils.writeValueAsString(false, schema); | ||
Map<String, Object> json = yaml.load(SchemaUtils.writeValueAsString(false, schema)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you change above to be yamlMap
, you want to change all occurrence to keep consistent.
} | ||
|
||
@Test | ||
void testUriTemplate() throws Exception { | ||
void testUriTemplate() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra indentation?
4b7d320
to
9d98022
Compare
This PR aims to fix the following 5 flaky test cases:
io.github.vlsergey.springdatarestutils.EntityToSchemaMapperTest.testLink
io.github.vlsergey.springdatarestutils.EntityToSchemaMapperTest.testMapAsDataItem
io.github.vlsergey.springdatarestutils.EntityToSchemaMapperTest.testMapAsExposed
io.github.vlsergey.springdatarestutils.EntityToSchemaMapperTest.testMapAsLinks
io.github.vlsergey.springdatarestutils.EntityToSchemaMapperTest.testUriTemplate
I found and confirmed the flaky behavior using an open-source research tool NonDex, which shuffles implementations of nondeterminism operations.
Problem:
The writeValueAsString() function is nondeterministic and when it tries to convert a YAML object to a string, it does not account for the ordering of elements of the YAML object.
spring-data-rest-utils/src/main/java/io/github/vlsergey/springdatarestutils/SchemaUtils.java
Line 33 in 8cd30df
Hence, all the tests mentioned above when they try to call the SchemaUtils.writeValueAsString() function, are prone to flakiness.
Solution:
Since we do not have access to the internal library, I have added a check, that converts the YAML string to YAML objects and then compares the objects.
Steps to reproduce
Integrate NonDex:
Add the following snippet to the top of the build.gradle in $PROJ_DIR:
Append to build.gradle in $PROJ_DIR:
Execute Test with Gradle:
Run NonDex:
Test Environment:
Please let me know if you have any concerns or questions.