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

fix flaky EnumTest #2522

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

219sansim
Copy link

@219sansim 219sansim commented Nov 3, 2023

Purpose

The test testClassWithEnumFieldSerialization in EnumTest is detected flaky because the gson.toJson() gives a non-deterministic output.
Related issue: #2520

Description

After modifying the tests to check if the gson.toJson() output to is one of the possible json string values, the test passes, instead of checking against only 1 string.

Reason:
The gson.toJson() internally calls com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields which makes a call to getDeclaredFields


And according to this stackoverlow discussion, getDeclaredFields in Java 8 does not return elements in a consistent order.

Reproduction of error

The test runs fail on 4/5 runs of the NonDex tool

Command to reproduce the failure:

mvn -pl gson edu.illinois:nondex-maven-plugin:2.1.1:debug -Dtest=com.google.gson.functional.EnumTest#testClassWithEnumFieldSerialization

Error Message:

Running com.google.gson.functional.EnumTest
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.171 s <<< FAILURE! -- in com.google.gson.functional.EnumTest
[ERROR] com.google.gson.functional.EnumTest.testClassWithEnumFieldSerialization -- Time elapsed: 0.163 s <<< FAILURE!
value of: toJson(...)
expected: {"value1":"VALUE1","value2":"VALUE2"}
but was : {"value2":"VALUE2","value1":"VALUE1"}
        at com.google.gson.functional.EnumTest.testClassWithEnumFieldSerialization(EnumTest.java:96)

Copy link

google-cla bot commented Nov 3, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@219sansim 219sansim marked this pull request as draft November 7, 2023 20:51
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.

None yet

1 participant