twitter / GraphJet

GraphJet is a real-time graph processing library.
Apache License 2.0
716 stars 111 forks source link

Fix flaky #137

Closed Ellen99 closed 1 year ago

Ellen99 commented 1 year ago

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

CLAassistant commented 1 year ago

CLA assistant check
All committers have signed the CLA.