alibaba / alibaba/fastjson2

[BUG] Identified some flaky test in core

Open
#2,168 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

### 问题描述
*简要描述您碰到的问题。*
With respect to issue https://github.com/alibaba/fastjson2/issues/2055
I have found that test com.alibaba.fastjson2.issues.Issue507.test is still flaky

Logs attached at the end.

### 环境信息
*请填写以下信息:*

- OS信息: [MacOs Sonoma 18GB]
- JDK信息: [JAVA 11.0.21-amzn]
- 版本信息:[Fastjson2 2.0.42]

### 重现步骤
*如何操作可以重现该问题:*

1. Run `mvn -pl core edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=com.alibaba.fastjson2.issues.Issue586#test -DnondexMode=ONE`.
2. The assertion between expectedStr and str fail non deterministically
3. The assertion between key 1L and keySet().values().next() fail undeterministically as well

### 期待的正确结果
*对您期望发生的结果进行清晰简洁的描述。*
1. For the mentioned test, it could fail because of comparing json objects with static JSON string, it is necessary to modify the assertion to validate not only the contents of the JSON elements but also their order.
2. The keySet().values().next() can have random order of the json elements, if we need to determine whether 1L exists in the keySet() we can simply assert with .containsKey() and use assertTrue to provide deterministic result.

### 相关日志输出
*请复制并粘贴任何相关的日志输出。*
```
[INFO] Running com.alibaba.fastjson2.issues.Issue507
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.118 s <<< FAILURE! -- in com.alibaba.fastjson2.issues.Issue507
[ERROR] com.alibaba.fastjson2.issues.Issue507.test -- Time elapsed: 0.101 s <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: <{"@type":"java.util.HashMap",1L:"张三",2L:"张四"}> but was: <{"@type":"java.util.HashMap",2L:"张四",1L:"张三"}>
at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:177)
at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1145)
at com.alibaba.fastjson2.issues.Issue507.test(Issue507.java:24)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)

[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] Issue507.test:24 expected: <{"@type":"java.util.HashMap",1L:"张三",2L:"张四"}> but was: <{"@type":"java.util.HashMap",2L:"张四",1L:"张三"}>
[INFO]
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.110 s <<< FAILURE! -- in
```
```
com.alibaba.fastjson2.issues.Issue507
[ERROR] com.alibaba.fastjson2.issues.Issue507.test -- Time elapsed: 0.099 s <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: <1> but was: <@type>
at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:177)
at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1145)
at com.alibaba.fastjson2.issues.Issue507.test(Issue507.java:27)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)

[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] Issue507.test:27 expected: <1> but was: <@type>
[INFO]
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

```
#### 附加信息
*如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。*

Contributor guide

Open the contributing guide

Research direction

Start with com.alibaba.fastjson2.issues.Issue507.test and run the provided Maven NonDex command, noting that the command names Issue586 while the logs identify Issue507. Update the assertions so JSON comparison and key lookup do not depend on iteration order, then rerun the test until the reported nondeterministic failures are gone.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.