GraphJet icon indicating copy to clipboard operation
GraphJet copied to clipboard

Fix for 'testSalsaWithRandomGraph' flaky test

Open Ellen99 opened this issue 1 year ago • 1 comments

Flaky Test testSalsaWithRandomGraph

The SalsaTest.testSalsaWithRandomGraph is a test that aims to generate user recommendations using the SALSA algorithm on a Bipartite graph. However, the test was found to be flaky due to the inconsistent ordering of elements in the HashSets, used to construct the graph. As HashSet does not maintain the order of elements, depending on the HashSet implementation, different Java versions result in different orderings, resulting in different bipartite graphs and making tests flaky.


FIX

To fix this issue I have changed the test to use a LinkedHashSet rather than a regular HashSet to maintain the order of elements consistently across different platforms and Java versions (lines 252, 253). LinkedHashSet, unlike HashSet, maintains the order of insertion of elements, which is essential for generating a predictable Bipartite graph. This is because the graph's structure is determined by the order of edges connecting similar users and similar followings, which in turn is determined by the order of elements in the sourceIdList and destinationIds sets.

As the test used hardcoded values to compare the expected results with the actual results, with the change to a LinkedHashSet, I needed to update these values to reflect the new ordering of elements. Therefore, I carefully analyzed the graph generated by the updated test and fixed the expected results accordingly to ensure that they matched the actual results.


The test passed successfully with nondex runs.

Ellen99 avatar Mar 17 '23 20:03 Ellen99

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Mar 17 '23 20:03 CLAassistant