Skip to content

fix: fix flaky tests in org.apache.helix.rest.metadatastore.TestZkMetadataStoreDirectory#testComputePartitionAssignment#1

Open
hofi1 wants to merge 1 commit into
masterfrom
fix/flaky-tests-org.apache.helix.rest.metadatastore.TestZkMetadataStoreDirectory
Open

fix: fix flaky tests in org.apache.helix.rest.metadatastore.TestZkMetadataStoreDirectory#testComputePartitionAssignment#1
hofi1 wants to merge 1 commit into
masterfrom
fix/flaky-tests-org.apache.helix.rest.metadatastore.TestZkMetadataStoreDirectory

Conversation

@hofi1

@hofi1 hofi1 commented Oct 1, 2023

Copy link
Copy Markdown
Owner

Issues

  • My PR addresses the following Helix issues and references them in the PR description:

Fixes apache#2645

Description

Sets return the elements in a non-deterministic order, which means that this assertion is not correct, because it checks whether the collections contain the same elements in the same order. This leads to a flack test. To fix this problem, the assertion has been rewritten to check if the collections contain the same amount of elements as well as booth collections contain all values of the other collection.

Tests that cause problems:

public void testGetAllMetadataStoreRealms() {
Set<String> realms = new HashSet<>();
realms.add(TEST_REALM_1);
realms.add(TEST_REALM_2);
for (String namespace : _routingZkAddrMap.keySet()) {
Assert.assertEquals(_metadataStoreDirectory.getAllMetadataStoreRealms(namespace), realms);
}
}

and

public void testGetAllShardingKeys() {
Set<String> allShardingKeys = new HashSet<>();
allShardingKeys.addAll(TEST_SHARDING_KEYS_1);
allShardingKeys.addAll(TEST_SHARDING_KEYS_2);
for (String namespace : _routingZkAddrMap.keySet()) {
Assert.assertEquals(_metadataStoreDirectory.getAllShardingKeys(namespace), allShardingKeys);
}
}

This problem was found by the NonDex Engine – to reproduce run

mvn -pl helix-rest edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=org.apache.helix.rest.metadatastore.TestZkMetadataStoreDirectory

Solution

Replace the assertions with a custom matcher, which checks if the sets contain the same elements without taking care of the order of the elements returned by the set.

Custom Matcher:

private void assertCollectionsContainSameElementsIgnoringOrder(Collection<String> collection1,
Collection<String> collection2) {
Assert.assertEquals(collection2.size(), collection1.size());
Assert.assertTrue(collection2.containsAll(collection1));
Assert.assertTrue(collection1.containsAll(collection2));
}

Tests

No test have been written – one existing test has been updated.

  • The following is the result of the "mvn test" command on the appropriate module:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:51 min
[INFO] Finished at: 2023-10-04T23:16:04-05:00
[INFO] ------------------------------------------------------------------------

@hofi1 hofi1 changed the title fix: fix flaky tests in org.apache.helix.rest.metadatastore.TestZkMetadataStoreDirectory fix: fix flaky tests in org.apache.helix.rest.metadatastore.TestZkMetadataStoreDirectory#testComputePartitionAssignment Oct 5, 2023
in org.apache.helix.rest.metadatastore.
TestZkMetadataStoreDirectory
@hofi1 hofi1 force-pushed the fix/flaky-tests-org.apache.helix.rest.metadatastore.TestZkMetadataStoreDirectory branch from f0b783e to 9cd4181 Compare October 5, 2023 04:21
@CaseyPan

Copy link
Copy Markdown

The fix LGTM.
One suggestion is to provide an explanation of the original data structure that was leading to non-deterministic returns.

@KiruthikaJanakiraman

Copy link
Copy Markdown

The fix looks good! In the description, you could add a link to the NonDex tool. You could also add links pointing to the line of code that causes the flakiness.

@zzjas

zzjas commented Oct 17, 2023

Copy link
Copy Markdown

You can consider if it makes sense to combine some of your PRs for helix into a larger one.

You can proceed to open a real PR. Once you open a real PR, please mark this tentative PR as Opened in your tentative_pr.csv file and also raise a PR to IDoFT marking this as Opened. Thanks!

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.

flaky test assertions in org.apache.helix.rest.metadatastore.TestZkMetadataStoreDirectory

4 participants