katharsis-project / katharsis-framework

Katharsis adds powerful layer for RESTful endpoints providing implementenation of JSON:API standard
http://katharsis.io
Apache License 2.0
135 stars 65 forks source link

fixed flaky test in testIncludeRelationsMultipleSame Test #462

Open njain2208 opened 12 months ago

njain2208 commented 12 months ago

PR Overview:


This PR fixes the flaky/non-deterministic behavior of the following test because it assumes the ordering.

io.katharsis.legacy.queryParams.DefaultQueryParamsConverterTest#testIncludeRelationsMultipleSame

Test Overview:


In the above test, the addParams method utilizes a non-deterministic HashMap to store parameters. This lack of determinism results in a change in the order of 'project' and 'projects' within the includedRelations array, consequently causing the test to fail.

This flakiness was identified by the nondex tool created by the researchers of UIUC.

[ERROR]   DefaultQueryParamsConverterTest.testIncludeRelationsMultipleSame:367->transitivityCheckTask:442 transitivity check expected:<QuerySpec{resourceClass=class io.katharsis.resource.mock.models.Task, limit=null, offset=0, filters=[], sort=[], includedFields=[], includedRelations=[project, projects], relatedSpecs={}}> but was:<QuerySpec{resourceClass=class io.katharsis.resource.mock.models.Task, limit=null, offset=0, filters=[], sort=[], includedFields=[], includedRelations=[projects, project], relatedSpecs={}}>

You can reproduce the issue by running the following commands:

mvn install -pl katharsis-core -am -DskipTests
mvn test -pl katharsis-core  -Dtest=io.katharsis.legacy.queryParams.DefaultQueryParamsConverterTest#testIncludeRelationsMultipleSame
mvn -pl katharsis-core edu.illinois:index-maven-plugin:2.1.1:nondex -Dtest=io.katharsis.legacy.queryParams.DefaultQueryParamsConverterTest#testIncludeRelationsMultipleSame

Fix:


To fix the issue I decided to store all of the parameters in a LinkedHashSet so it returns the element in which it is stored.

https://github.com/njain2208/katharsis-framework/blob/36c7411dcf9ae6515c539ec7f38976749939614b/katharsis-core/src/test/java/io/katharsis/legacy/queryParams/AbstractQueryParamsTest.java#L49-L60