Skip to content
Snippets Groups Projects
Commit 65f93bda authored by vlorentz's avatar vlorentz
Browse files

Apply 'max_matching_nodes' restriction after 'return_types' filter

Otherwise, less results may be returned, if the non-matching nodes are
before the matching ones.
parent bc4e710a
No related branches found
No related tags found
No related merge requests found
......@@ -292,13 +292,13 @@ public class Traversal {
if (nodeMatchesConstraints) {
if (nodeBuilder != null) {
nodeObserver.onNext(nodeBuilder.build());
}
if (remainingMatches >= 0) {
remainingMatches--;
if (remainingMatches == 0) {
// We matched as many nodes as allowed
throw new StopTraversalException();
if (remainingMatches >= 0) {
remainingMatches--;
if (remainingMatches == 0) {
// We matched as many nodes as allowed
throw new StopTraversalException();
}
}
}
}
......
......@@ -127,6 +127,27 @@ def test_visit_nodes_filtered(graph_client):
assert set(actual) == set(expected)
@pytest.mark.parametrize("max_matching_nodes", [0, 1, 2, 3, 4, 5, 10, 1 << 31])
def test_visit_nodes_filtered_limit(graph_client, max_matching_nodes):
actual = list(
graph_client.visit_nodes(
"swh:1:rel:0000000000000000000000000000000000000010",
return_types="dir",
max_matching_nodes=max_matching_nodes,
)
)
expected = [
"swh:1:dir:0000000000000000000000000000000000000002",
"swh:1:dir:0000000000000000000000000000000000000008",
"swh:1:dir:0000000000000000000000000000000000000006",
]
if max_matching_nodes == 0:
assert set(actual) == set(expected)
else:
assert set(actual) <= set(expected)
assert len(actual) == min(3, max_matching_nodes)
def test_visit_nodes_filtered_star(graph_client):
actual = list(
graph_client.visit_nodes(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment