spdx / tools

SPDX Tools
Apache License 2.0
123 stars 68 forks source link

Fix flaky test by LinkedHashSet #312

Closed Jinzhengxu closed 1 year ago

Jinzhengxu commented 1 year ago

Description

A test named org.spdx.compare.TestPackageSheet#testDeclaredLicenseCol, can fail nondeterministically when been run in different JVMs. The issue can be found by running following command under root directory after installation:

 mvn -pl . edu.illinois:nondex-maven-plugin:1.1.2:nondex -Dtest=org.spdx.compare.TestPackageSheet#testDeclaredLicenseCol

Reason for Flakiness

In lines 192 and 193 in the test function, toString() is called. In the implementation of AnyLicenseInfo's toString(), the function calls a HashSet iterator, which does not guarantee a deterministic order. As a result, lines192 and 193 in org.spdx.compare.TestPackageSheet#testDeclaredLicenseCol can raise an assertion error due to permutation of the string-represented equations.

Sample Failure

Failed tests:   testDeclaredLicenseCol(org.spdx.compare.TestPackageSheet): 
expected:<(L[icenseRef-3 AND LGPL-2.0])> 
but was:<(L[GPL-2.0 AND LicenseRef-3])>

Fixes

Change 'newHashSet()' to 'newLinkedHashSet()' in 'LicenseSet.java', then it can be resovled.

goneall commented 1 year ago

Thanks @Jinzhengxu

Just a note - there is a newer version of this utility - tool-java