forked from aristanetworks/anta
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add prepare_tests and get_coroutines benchmarks (aristanetworks#860)
* ci: add prepare_tests and get_coroutines benchmarks * fix: clear indexes * test: fix finventory fixture parametrization * chore: update vscode settings * test: fix test_runner assertion * test: refactor benchmarks * Update tests/benchmark/conftest.py --------- Co-authored-by: Guillaume Mulocher <[email protected]>
- Loading branch information
Showing
5 changed files
with
87 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
{ | ||
"ruff.enable": true, | ||
"ruff.configuration": "pyproject.toml", | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestEnabled": true, | ||
"python.testing.pytestArgs": [ | ||
"tests" | ||
], | ||
"python.languageServer": "Pylance", | ||
"githubIssues.issueBranchTitle": "issues/${issueNumber}-${issueTitle}", | ||
"editor.formatOnPaste": true, | ||
"files.trimTrailingWhitespace": true, | ||
"workbench.remoteIndicator.showExtensionRecommendations": true, | ||
"pylint.importStrategy": "fromEnvironment", | ||
"pylint.args": [ | ||
"--rcfile=pyproject.toml" | ||
], | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright (c) 2023-2024 Arista Networks, Inc. | ||
# Use of this source code is governed by the Apache License 2.0 | ||
# that can be found in the LICENSE file. | ||
"""Benchmark tests for anta.runner.""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from anta.result_manager import ResultManager | ||
from anta.runner import get_coroutines, prepare_tests | ||
|
||
if TYPE_CHECKING: | ||
from collections import defaultdict | ||
|
||
from pytest_codspeed import BenchmarkFixture | ||
|
||
from anta.catalog import AntaCatalog, AntaTestDefinition | ||
from anta.device import AntaDevice | ||
from anta.inventory import AntaInventory | ||
|
||
|
||
def test_prepare_tests(benchmark: BenchmarkFixture, catalog: AntaCatalog, inventory: AntaInventory) -> None: | ||
"""Benchmark `anta.runner.prepare_tests`.""" | ||
|
||
def _() -> defaultdict[AntaDevice, set[AntaTestDefinition]] | None: | ||
catalog.clear_indexes() | ||
return prepare_tests(inventory=inventory, catalog=catalog, tests=None, tags=None) | ||
|
||
selected_tests = benchmark(_) | ||
|
||
assert selected_tests is not None | ||
assert len(selected_tests) == len(inventory) | ||
assert sum(len(tests) for tests in selected_tests.values()) == len(inventory) * len(catalog.tests) | ||
|
||
|
||
def test_get_coroutines(benchmark: BenchmarkFixture, catalog: AntaCatalog, inventory: AntaInventory) -> None: | ||
"""Benchmark `anta.runner.get_coroutines`.""" | ||
selected_tests = prepare_tests(inventory=inventory, catalog=catalog, tests=None, tags=None) | ||
|
||
assert selected_tests is not None | ||
|
||
coroutines = benchmark(lambda: get_coroutines(selected_tests=selected_tests, manager=ResultManager())) | ||
for coros in coroutines: | ||
coros.close() | ||
|
||
count = sum(len(tests) for tests in selected_tests.values()) | ||
assert count == len(coroutines) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters