Skip to content
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 flaky test DataStoreConvertersTest.testCheckSameKey() #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mihirgune
Copy link
Owner

@mihirgune mihirgune commented Sep 10, 2024

Code Change

Fixed flaxy test - https://github.com/GoogleCloudPlatform/DataflowTemplates/blob/main/v1/src/test/java/com/google/cloud/teleport/templates/common/DatastoreConvertersTest.java#L174

Error

This test is flaky because while verifying if the errorTag matches the expectedErrors, the code does a direct string comparison, in which both strings are JSON objects in string format. As the ordering of the keys inside JSON objects is non-deterministic, this string comparison is throwing an error.

This error was found by executing the NonDex tool with the following command -

mvn -pl v1 edu.illinois:nondex-maven-plugin:2.1.7:nondex -Dtest=com.google.cloud.teleport.templates.common.DatastoreConvertersTest#testCheckSameKey

Expected: iterable with items ["{\"message\":\"Duplicate Datastore Key\",\"stacktrace\":null,\"data\":\"{\\\"key\\\":{\\\"partitionId\\\":{\\\"projectId\\\":\\\"my-project\\\",\\\"namespaceId\\\":\\\"some-namespace\\\"},\\\"path\\\":[{\\\"kind\\\":\\\"monkey\\\",\\\"id\\\":\\\"1234\\\"}]},\\\"properties\\\":{\\\"someString\\\":{\\\"stringValue\\\":\\\"someValue\\\"}}}\"}", "{\"message\":\"Duplicate Datastore Key\",\"data\":\"{\\\"key\\\":{\\\"partitionId\\\":{\\\"projectId\\\":\\\"my-project\\\",\\\"namespaceId\\\":\\\"some-namespace\\\"},\\\"path\\\":[{\\\"kind\\\":\\\"monkey\\\",\\\"id\\\":\\\"1234\\\"}]},\\\"properties\\\":{\\\"SomeBSProp\\\":{\\\"stringValue\\\":\\\"Some BS Value\\\"}}}\",\"stacktrace\":null}"] in any order
     but: not matched: "{\"data\":\"{\\\"key\\\":{\\\"partitionId\\\":{\\\"projectId\\\":\\\"my-project\\\",\\\"namespaceId\\\":\\\"some-namespace\\\"},\\\"path\\\":[{\\\"kind\\\":\\\"monkey\\\",\\\"id\\\":\\\"1234\\\"}]},\\\"properties\\\":{\\\"someString\\\":{\\\"stringValue\\\":\\\"someValue\\\"}}}\",\"message\":\"Duplicate Datastore Key\",\"stacktrace\":null}

Fix

Discarded Probable Fixes

Proposed Fix

Instead of comparing two jsons, I am comparing the hashcodes for those JSONs. The google.gson JsonObject which I am using uses a LinkedTreeMap to store its members, which will automatically handle sorting, thus making the hashcode reliable.

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.

1 participant