Skip to content

Conversation

@Stranger3333
Copy link
Owner

@Stranger3333 Stranger3333 commented Sep 1, 2022

The problem occurs at the method TestAzureLogAnalyticsProvenanceReportingTask.testAddField2, which compares two Jsonobject after calling toString() method. One Jsonobject is expectedJson, which is generated by a hardcoded String expectedjsonString with a fixed sequence of JSON fields. Another Jsonobject is actualJson, which by passing HashMap as a parameter to the method AzureLogAnalyticsProvenanceReportingTask.addField. This method will add entries of the map to the JsonObjectBuilder builder, then actualJson is generated by calling builder.build().

The flaky test exists since the HashMap is non-deterministic or unordered, so the sequence of adding entries to builder is non-deterministic. Thus, assertEquals(expectedJson.toString(), actualJson.toString()); could result some tests fail.
The solution is changing HashMap to LinkedHashMap, an ordered map, and then adding entries by order.

This PR uses LinkedHashMap to make the testAddField2 deterministic.

The reason that it may be accepted by open-source developers is that I only changed a couple of lines in the test method, without changing any main code. The functioning of the whole project will work as before. Also, I only imported the LinkedHashMap from java.util package, which will not affect the security of the codebase from my view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants