anthonyx24 opened a new issue, #4993:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4993

   ### Steps to Reproduce
   
   Hello, there is a small issue within the `addGroup()` unit test in 
`TestMeasurementGroupConfig` that seems to make it nondeterministic. 
   
   The `groups` attribute of `MeasurementGroupConfig` is implemented as a 
Hashmap 
[here](https://github.com/apache/servicecomb-java-chassis/blob/75417d88dfc02b894280bf27b4a830df6e74ae19/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/publish/MeasurementGroupConfig.java#L27).
 Then, in the unit test `addGroup` in `TestMeasurementGroupConfig`, there's an 
assertion that checks the keys added to the hashmap are "id2" and "id1" using 
hamcrest's `Matchers.contains`, which [does strict order 
checking](https://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matchers.html#contains(E...)).
 But since the `groups` Hashmap is unordered, it's not technically guaranteed 
the order of the keys will be `"id2", "id1"` and instead may be `"id1", "id2"`, 
which would cause the test to fail. 
   
   This test was flagged via the 
[NonDex](https://github.com/TestingResearchIllinois/NonDex) tool, which detects 
potentially unreliable tests due to underlying Java API assumptions. To see the 
Nondex output for this class, you can run:
   ```
   mvn -pl foundations/foundation-metrics 
edu.illinois:nondex-maven-plugin:2.1.7:nondex 
-Dtest="org.apache.servicecomb.foundation.metrics.publish.spectator.TestMeasurementGroupConfig"
   ```
   
   ### Expected Behavior
   
   The test should pass regardless of the order in which keys are iterated 
through.
   
   ### Servicecomb Version
   
   3.3.0
   
   ### Additional Context
   
   The fix is simple; I'll include a link to the PR in the comments.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to