Skip to content

Comments

Correct testParser_v1_AllParamsPresent to not depend on HashSet iteration order#2

Open
lawrencewang49 wants to merge 1 commit intomasterfrom
fix-testParser_v1_AllParamsPresent
Open

Correct testParser_v1_AllParamsPresent to not depend on HashSet iteration order#2
lawrencewang49 wants to merge 1 commit intomasterfrom
fix-testParser_v1_AllParamsPresent

Conversation

@lawrencewang49
Copy link
Owner

Summary

This PR updates testParser_v1_AllParamsPresent in bt-tests to use a direct comparison for peer addresses.

Previously, the test compared InetPeerAddress values by iterating over peerAddresses in order. However, MagnetUri.getPeerAddresses() returns a Collection backed by a Set, which does not guarantee iteration order. This could cause nondeterministic test failures depending on the JVM or hash distribution.

Changes made

  • Defined expectedPeers as a Collection and compared it with the result peerAddresses to remove reliance on iteration order, but still ensuring returned contents are correct.
Collection<InetPeerAddress> expectedPeers = Set.of(
    new InetPeerAddress("1.1.1.1", 10000),
    new InetPeerAddress("2.2.2.2", 10000)
);

...

assertEquals(expectedPeers, peerAddresses);
  • Ensures correctness by verifying the presence of all expected peers without depending on iteration order.

Rationale

  • Prevents false negatives in tests due to nondeterministic ordering.
  • Makes the test aligned with the API contract (order not specified).
  • Improves stability and portability of the test suite.

@lawrencewang49 lawrencewang49 force-pushed the fix-testParser_v1_AllParamsPresent branch from 38250cd to cc1e4af Compare September 24, 2025 05:45
…on order

Updates based on feedback to convert  to HashSet and be compatible with Java 8
@lawrencewang49 lawrencewang49 force-pushed the fix-testParser_v1_AllParamsPresent branch from 0e5aaf8 to 0e36daa Compare September 25, 2025 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant