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

[Bug]: Detected flaky test com.google.cloud.teleport.templates.TextToBigQueryStreamingTest.wrapBigQueryInsertErrorReturnsValidJSON in v1 module. #1175

Closed
Suraj-Vashista-BK opened this issue Nov 16, 2023 · 2 comments
Labels
bug Something isn't working needs triage p2 stale

Comments

@Suraj-Vashista-BK
Copy link
Contributor

Suraj-Vashista-BK commented Nov 16, 2023

Related Template(s)

TextToBigQueryStreamingTest

What happened?

Detected flaky test wrapBigQueryInsertErrorReturnsValidJSON in com.google.cloud.teleport.templates.TextToBigQueryStreamingTest

The following command was used to detect flakiness using nondex:

mvn  -pl v1  edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=com.google.cloud.teleport.templates.TextToBigQueryStreamingTest#wrapBigQueryInsertErrorReturnsValidJSON

nonDex detects flakiness in the lines

assertThat(actualOriginalPayload).isEqualTo(expected);
assertThat(actualPayload).isEqualTo(expected);

With the error message

expected: {"age":20,"name":"Jane"}
but was : {"name":"Jane","age":20}

Explanation

The expected string is being calculated in the line

Here using GSON.toJson(testPerson), testPerson which is an object of type TestPerson is converted to a Json String. GSON internally serializes and this can lead to change in the order of the elements which causes non-determinism in the output string.

Proposed Fix
It is very tricky to compare strings when the order can be changed, hence In my fix, we use JsonParser.parseString() as shown below.

assertThat(JsonParser.parseString(actualOriginalPayload)).isEqualTo(JsonParser.parseString(expected)); 
assertThat(JsonParser.parseString(actualPayload)).isEqualTo(JsonParser.parseString(expected));

Here, the JsonParser returns a JsonObject of gson library itself, whose equals implementation is not order-sensitive.

Test Environment:

openjdk version "11.0.20.1"
Apache Maven 3.6.3
Ubuntu 20.04.6 LTS
Linux version 5.4.0-156-generic

Beam Version

Newer than 2.46.0

Relevant log output

Failures: 
TextToBigQueryStreamingTest.wrapBigQueryInsertErrorReturnsValidJSON:70 expected: {"age":20,"name":"Jane"}
but was : {"name":"Jane","age":20}
Copy link

Stale issue message

@github-actions github-actions bot added the stale label May 16, 2024
Copy link

This issue has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage p2 stale
Projects
None yet
Development

No branches or pull requests

1 participant