Skip to content

Commit

Permalink
test: print top 50 slowest testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
actionless committed Aug 18, 2024
1 parent a438f18 commit 14279b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 9 additions & 1 deletion maintenance_scripts/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -x
MODE="${1:---local}"
shift
if [[ "$MODE" == "--help" ]] ; then
echo "Usage: $0 SUBMIT_COVERAGE WRITE_DB"
echo "Usage: $0 [SUBMIT_COVERAGE=--local] [WRITE_DB=--write-db] [TESTSUITE=all]"
exit 0
fi

Expand All @@ -26,6 +26,7 @@ shift
# exit 1
#}

echo > pikaur_test_times.txt
if [[ "$TESTSUITE" = "all" ]] ; then
coverage run --source=pikaur -m unittest -v
else
Expand All @@ -38,3 +39,10 @@ else
coverage report
coverage html
fi

echo
echo
echo
echo
echo " :: Top 50 of the slowest testcases:"
sort -rn pikaur_test_times.txt | head -n 50
10 changes: 8 additions & 2 deletions pikaur_test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pycman.config import PacmanConfig

from pikaur.args import CachedArgs, parse_args
from pikaur.core import InteractiveSpawn
from pikaur.core import DEFAULT_INPUT_ENCODING, InteractiveSpawn
from pikaur.core import spawn as core_spawn
from pikaur.main import main
from pikaur.makepkg_config import MakePkgCommand
Expand Down Expand Up @@ -276,13 +276,19 @@ def pkg_is_installed(pkg_name: str) -> bool:
class PikaurTestCase(TestCase):
# pylint: disable=invalid-name

test_times_path = "./pikaur_test_times.txt"

separator = color_line(f"\n{'-' * get_term_width()}", 12, force=True)

def run(self, result: "TestResult | None" = None) -> "TestResult | None":
time_started = time()
log_stderr(self.separator)
result = super().run(result)
log_stderr(f":: Took {(time() - time_started):.2f} seconds")
# print(result and result.collectedDurations)
time_spent = time() - time_started
log_stderr(f":: Took {(time_spent):.2f} seconds")
with Path(self.test_times_path).open("a", encoding=DEFAULT_INPUT_ENCODING) as fobj:
fobj.write(f"{(time_spent):.2f} {self}\n")
return result

def setUp(self) -> None:
Expand Down

0 comments on commit 14279b6

Please sign in to comment.