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

Enhance the robustness of tests #248

Open
FarmersWrap opened this issue Dec 4, 2023 · 0 comments
Open

Enhance the robustness of tests #248

FarmersWrap opened this issue Dec 4, 2023 · 0 comments

Comments

@FarmersWrap
Copy link

FarmersWrap commented Dec 4, 2023

json-io version

4.19.1

Java version

openjdk version "11.0.20.1"

Used tools

Apache Maven 3.6.3
Ubuntu 20.04.6 LTS
Linux version: 5.4.0-163-generic

Description

There are 9 tests within json-io has been reported as flaky when run with the NonDextool.

  • Since hashmap in Java is unordered, we simulate the randomness of the hashmap by shuffling it to test the correctness of the tests in json-io. There may be more than one json string when hashmap is used.
    For example: com.cedarsoftware.util.io.AtomicLongTest,testAssignAtomicLong

  • Tests should not rely on the getDeclaredFields() function because according to Class.getDeclaredFields() "The elements in the returned array are not sorted and are not in any particular order.". The test answers can differ.
    For example: com.cedarsoftware.util.io.MapsTest,testMap

Hash, class, test
f8958ef52bbdc94f8aed7d98c96d2775200ec7e7, com.cedarsoftware.util.io.AtomicLongTest, testAssignAtomicLong
f8958ef52bbdc94f8aed7d98c96d2775200ec7e7, com.cedarsoftware.util.io.AtomicBooleanTest, testAssignAtomicBoolean
f8958ef52bbdc94f8aed7d98c96d2775200ec7e7, com.cedarsoftware.util.io.MapsTest, testMap
f8958ef52bbdc94f8aed7d98c96d2775200ec7e7, com.cedarsoftware.util.io.MapsTest, testReconstituteMap
f8958ef52bbdc94f8aed7d98c96d2775200ec7e7, com.cedarsoftware.util.io.NoTypeTest, testNoType
f8958ef52bbdc94f8aed7d98c96d2775200ec7e7, com.cedarsoftware.util.io.PrettyPrintTest, testPrettyPrint
f8958ef52bbdc94f8aed7d98c96d2775200ec7e7, com.cedarsoftware.util.io.AtomicIntegerTest, testAssignAtomicInteger
f8958ef52bbdc94f8aed7d98c96d2775200ec7e7, com.cedarsoftware.util.io.EnumTests,testEnumWithPrivateMembersAsField_withPrivatesOn
f8958ef52bbdc94f8aed7d98c96d2775200ec7e7, com.cedarsoftware.util.io.CollectionTests, testEnumsInsideOfACollection_whenWritingAsObject_withPrivateMembersIncluded

Expected behavior

Test should pass even if the order in json string differs.

Actual behavior

The tests assume there will only one json string produced by TestUtil.toJson function. But after shuffling, they failed.

Reproduction steps

  1. read instructions here NonDex
  2. Execute following commands
#!/bin/bash
log_dir="jsonio-logs1"
# Create logs directory if it doesn't exist
mkdir -p ../$log_dir
# Perform Maven install, skip tests, and log the output in ../logs directory
mvn install -pl "." -am -DskipTests |& tee "../$log_dir/mvn-install-$(date +%s).nondex_log"
# Run Maven tests and log the output in ../logs directory
mvn -pl "." test |& tee "../$log_dir/mvn-test-$(date +%s).nondex_log"
# Execute NonDex Maven plugin
mvn -pl "." edu.illinois:nondex-maven-plugin:2.1.1:nondex -fn -DnondexRuns=10 |& tee "../$log_dir/mvn-nondex-$(date +%s).nondex_log"

Full description of Nondex please refer to its doc on github.

Thanks

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

No branches or pull requests

1 participant