This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
Add auto type support to remove dependency among tests #4458
+6
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The test
com.alibaba.fastjson.serializer.TestParse.testParse
fails when run standalone or if it is run beforecom.alibaba.json.bvt.support.spring.FastJsonRedisSerializerTest.test_6
. This PR removes such a dependency.Steps to reproduce
CustomTestSuite.java
and changepom.xml
to just run this usingmvn test
. Changes can be pulled from the following branch test-setup.mvn install -pl .
mvn test
mvn test
againmvn test -Dtest=com.alibaba.fastjson.serializer.TestParse#testParse
Issue and root cause
The following are the logs when
TestParse
is run beforeFastJsonRedisSerializerTest
However when the order of test classes are reversed, it passes:
This happens because a
TestBean
class object is created and serialized producing an automatic type as indicated in the logsparsing json string:{"@type":"com.alibaba.fastjson.serializer.TestBean","data":{"@type":"com.alibaba.fastjson.JSONObject","key":"value"},"name":"tester"}
during the run ofTestParse
. This string is attempted to be deserialized at TestParse. Due to security reasons, deserialization of auto type is set as a configurable flag, and if it is not enabled, the above seen error occurs ParserConfig. The FastJsonRedisSerializerTest sets this property on the global instance. The same global instance gets used whenTestParse
is run after it because it does not pass any config while callingJSON.parse()
. This is the reason the test passes.Fix:
To remove this dependency and not create any more dependencies, the flag is set on a local config object created for this test. This
ParseConfig
object is explicitly passed for deserialization.Verification of fix:
Test passes when run standalone. (
mvn test -Dtest=com.alibaba.fastjson.serializer.TestParse#testParse
)