apache / linkis

Apache Linkis builds a computation middleware layer to facilitate connection, governance and orchestration between the upper applications and the underlying data engines.
https://linkis.apache.org/
Apache License 2.0
3.27k stars 1.15k forks source link

Fix flaky test in ExceptionManagerTest.java #5005

Closed yijut2 closed 7 months ago

yijut2 commented 7 months ago

What is the purpose of the change

Fix the flaky test detected under the ExceptionManagerTest.java under links-commons module.

Related issues/PRs

Related issues: #5004 Related pr: N/A

Brief change log

There was a map added at the end of the errorException message. Since the HashMap is an unordered data structure, the key-value pair may not stay in the same order every time. That's why sometimes the expected value does not match the actual value. I slightly modified the code to change the HashMap to TreeMap to solve this issue.

The failed log looks like:

[ERROR] Failures: 
[ERROR]   ExceptionManagerTest.testGenerateException:55 expected: <LinkisException{errCode=10000, desc='The map
cannot be parsed normally, the map is empty or the LEVEL value is missing:(map不能被正常的解析,map为空或者缺少LEVEL值: ){desc=test, ip=null, errCode=1, serviceKind=null, port=0, level=null}', ip='null', port=0, serviceKind='null'}> but was:
<LinkisException{errCode=10000, desc='The map cannot be parsed normally, the map is empty or the LEVEL value is
missing:(map不能被正常的解析,map为空或者缺少LEVEL值: ){port=0, desc=test, level=null, ip=null, errCode=1,
serviceKind=null}', ip='null', port=0, serviceKind='null'}>
[INFO] 
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

After the fix, the failure no longer exists:

[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.053 s - in
org.apache.linkis.common.exception.ExceptionManagerTest
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

Checklist