Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -236,23 +236,31 @@ def test_out_acceptance(collection, test_case: OutTestCase):
populate_collection(collection, test_case)
target = target_name(collection, test_case)
out_stage = test_case.build_out_stage(collection)
execute_command(
out_result = execute_command(
collection,
{"aggregate": collection.name, "pipeline": [out_stage], "cursor": {}},
)
result = execute_command(
collection,
{"listCollections": 1, "filter": {"name": target}},
)
raw_doc = cast(dict, result)["cursor"]["firstBatch"][0]
expected_info: dict[str, Any] = {
"name": target,
"type": test_case.expected_type,
"options": test_case.expected_options,
"info": raw_doc["info"],
}
if "idIndex" in raw_doc:
expected_info["idIndex"] = raw_doc["idIndex"]
result: Any
expected_info: Any
if isinstance(out_result, Exception):
# The $out command itself failed; surface that error through the
# assertion rather than crashing on an empty listCollections batch.
result = out_result
expected_info = []
else:
result = execute_command(
collection,
{"listCollections": 1, "filter": {"name": target}},
)
raw_doc = cast(dict, result)["cursor"]["firstBatch"][0]
expected_info = {
"name": target,
"type": test_case.expected_type,
"options": test_case.expected_options,
"info": raw_doc["info"],
}
if "idIndex" in raw_doc:
expected_info["idIndex"] = raw_doc["idIndex"]
assertSuccess(result, [expected_info], msg=test_case.msg)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,23 +373,31 @@ def test_out_timeseries(collection, test_case: OutTestCase):
"""Test $out writes results and creates the correct collection type."""
populate_collection(collection, test_case)
out_stage = test_case.build_out_stage(collection)
execute_command(
out_result = execute_command(
collection,
{"aggregate": collection.name, "pipeline": [out_stage], "cursor": {}},
)
result = execute_command(
collection,
{"listCollections": 1, "filter": {"name": target_name(collection, test_case)}},
)
raw_doc = cast(dict, result)["cursor"]["firstBatch"][0]
expected_info: dict[str, Any] = {
"name": target_name(collection, test_case),
"type": test_case.expected_type,
"options": test_case.expected_options,
"info": raw_doc["info"],
}
if "idIndex" in raw_doc:
expected_info["idIndex"] = raw_doc["idIndex"]
result: Any
expected_info: Any
if isinstance(out_result, Exception):
# The $out command itself failed; surface that error through the
# assertion rather than crashing on an empty listCollections batch.
result = out_result
expected_info = []
else:
result = execute_command(
collection,
{"listCollections": 1, "filter": {"name": target_name(collection, test_case)}},
)
raw_doc = cast(dict, result)["cursor"]["firstBatch"][0]
expected_info = {
"name": target_name(collection, test_case),
"type": test_case.expected_type,
"options": test_case.expected_options,
"info": raw_doc["info"],
}
if "idIndex" in raw_doc:
expected_info["idIndex"] = raw_doc["idIndex"]
assertSuccess(result, [expected_info], msg=test_case.msg)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_cross_command_filter(
node = node.get("inputStage")

assertProperties(
{"indexFilterSet": qp["indexFilterSet"], "winningIndex": winning_index},
{"indexFilterSet": qp.get("indexFilterSet"), "winningIndex": winning_index},
{"indexFilterSet": Eq(True), "winningIndex": Eq(expected_index)},
msg=f"filter should force {expected_index}",
raw_res=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_filter_forces_index(collection, filter_indexes, expected_index):
node = node.get("inputStage")

assertProperties(
{"indexFilterSet": qp["indexFilterSet"], "winningIndex": winning_index},
{"indexFilterSet": qp.get("indexFilterSet"), "winningIndex": winning_index},
{"indexFilterSet": Eq(True), "winningIndex": Eq(expected_index)},
msg=f"filter should force {expected_index} for query {{a: 1}}",
raw_res=True,
Expand Down Expand Up @@ -98,7 +98,7 @@ def test_multiple_allowed_indexes(collection):
allowed = ["a_1", "c_1"]
assertProperties(
{
"indexFilterSet": qp["indexFilterSet"],
"indexFilterSet": qp.get("indexFilterSet"),
"inAllowedSet": winning_index in allowed if winning_index else False,
},
{"indexFilterSet": Eq(True), "inAllowedSet": Eq(True)},
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_hint_overridden_by_filter(collection, filter_indexes, hint, expected_in
node = node.get("inputStage")

assertProperties(
{"indexFilterSet": qp["indexFilterSet"], "winningIndex": winning_index},
{"indexFilterSet": qp.get("indexFilterSet"), "winningIndex": winning_index},
{"indexFilterSet": Eq(True), "winningIndex": Eq(expected_index)},
msg=f"filter should override hint and force {expected_index}",
raw_res=True,
Expand Down Expand Up @@ -190,7 +190,7 @@ def test_collscan_fallback(collection):
qp = result["queryPlanner"]
assertProperties(
{
"indexFilterSet": qp["indexFilterSet"],
"indexFilterSet": qp.get("indexFilterSet"),
"topStage": qp["winningPlan"].get("stage", ""),
},
{"indexFilterSet": Eq(True), "topStage": Eq("COLLSCAN")},
Expand Down Expand Up @@ -231,7 +231,7 @@ def test_filter_scoped_to_exact_shape(collection, query, expected_filter_set):
},
)
assertProperties(
{"indexFilterSet": result["queryPlanner"]["indexFilterSet"]},
{"indexFilterSet": result["queryPlanner"].get("indexFilterSet")},
{"indexFilterSet": Eq(expected_filter_set)},
msg=f"indexFilterSet should be {expected_filter_set} for query {query}",
raw_res=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_partial_index_qualifying(collection):
node = node.get("inputStage")

assertProperties(
{"indexFilterSet": qp["indexFilterSet"], "winningIndex": winning_index},
{"indexFilterSet": qp.get("indexFilterSet"), "winningIndex": winning_index},
{"indexFilterSet": Eq(True), "winningIndex": Eq("a_partial")},
msg="qualifying query should use the partial index",
raw_res=True,
Expand Down Expand Up @@ -95,7 +95,7 @@ def test_partial_index_non_qualifying(collection):
qp = result["queryPlanner"]
assertProperties(
{
"indexFilterSet": qp["indexFilterSet"],
"indexFilterSet": qp.get("indexFilterSet"),
"topStage": qp["winningPlan"].get("stage", ""),
},
{"indexFilterSet": Eq(True), "topStage": Eq("COLLSCAN")},
Expand Down Expand Up @@ -143,7 +143,7 @@ def test_sparse_index_qualifying(collection):
node = node.get("inputStage")

assertProperties(
{"indexFilterSet": qp["indexFilterSet"], "winningIndex": winning_index},
{"indexFilterSet": qp.get("indexFilterSet"), "winningIndex": winning_index},
{"indexFilterSet": Eq(True), "winningIndex": Eq("a_sparse")},
msg="$exists:true should use the sparse index",
raw_res=True,
Expand Down Expand Up @@ -182,7 +182,7 @@ def test_sparse_index_non_qualifying(collection):
qp = result["queryPlanner"]
assertProperties(
{
"indexFilterSet": qp["indexFilterSet"],
"indexFilterSet": qp.get("indexFilterSet"),
"topStage": qp["winningPlan"].get("stage", ""),
},
{"indexFilterSet": Eq(True), "topStage": Eq("COLLSCAN")},
Expand Down
Loading