Skip to content

[BUG] - Nondeterminism in TestMeasurementGroupConfig due to strict order checking of keys in an unordered HashMap #4993

@anthonyx24

Description

@anthonyx24

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. 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. 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 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions