perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.63k stars 1.56k forks source link

Fix a flaky test testQueryParams #1285

Open dserfe opened 9 months ago

dserfe commented 9 months ago

This PR is to fix a flaky test spark.RequestTest#testQueryParams, we found it when using the latest version of spark:

  1. To reproduce test failures:
    • Run the following cmds:
      mvn edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=spark.RequestTest#testQueryParams -DnondexRuns=10
    • And then we'll get the following failures:
      RequestTest.testQueryParams:479 Should return the query parameter names: arrays first differed at element [0]; expected:<[items]> but was:<[sort]>
  2. Why it fails: Line 471 Map<String, String[]> params = new HashMap<>(); ofsrc/test/java/spark/RequestTest.java defines a HashMap, which makes no guarantee about the iteration order. The specification about HashMap says that "This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time".
  3. Fix it: By changing HashMap into LinkedHashMap.