-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Description
Describe the bug
The tests testNewMetadataSelector
and testNewMetadataSelector2
in the client
module at com.alibaba.nacos.client.naming.selector.NamingSelectorFactoryTest
are flaky because they rely on non-deterministic collections (like HashMap), which do not guarantee consistent iteration order. This randomness causes intermittent test failures, leading to false negatives in automated testing.
Expected behavior
The tests should consistently pass with reliable results, regardless of the underlying collection order.
Actually behavior
The tests fail intermittently due to non-deterministic collection ordering, leading to inconsistent results. This flakiness was detected using NonDex, a testing tool that identifies flaky tests caused by non-deterministic behaviors, such as random or unordered execution.
How to Reproduce
Steps to reproduce the behavior:
- Navigate to the
nacos
directory - Run the the above mentioned tests (with nondex) using the following commands
mvn -pl client edu.illinois:nondex-maven-plugin:2.1.7:nondex -Dtest=com.alibaba.nacos.client.naming.selector.NamingSelectorFactoryTest#testNewMetadataSelector
and
mvn -pl client edu.illinois:nondex-maven-plugin:2.1.7:nondex -Dtest=com.alibaba.nacos.client.naming.selector.NamingSelectorFactoryTest#testNewMetadataSelector2
3. See assertion error in the NonDex log
[ERROR] NamingSelectorFactoryTest.testNewMetadataSelector:114 expected: com.alibaba.nacos.api.naming.pojo.Instance@5a9d6f02<Instance{instanceId='null', ip='null', port=0, weight=1.0, healthy=true, enabled=true, ephemeral=true, clusterName='null', serviceName='null', metadata={b=2, a=1}}> but was: com.alibaba.nacos.api.naming.pojo.Instance@5a9d6f02<Instance{instanceId='null', ip='null', port=0, weight=1.0, healthy=true, enabled=true, ephemeral=true, clusterName='null', serviceName='null', metadata={b=2, a=1}}>
[INFO]
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
Desktop:
- OS: Linux
- Version: 2.4.3
- Module: client
- SDK: original