Skip to content

Commit 952d434

Browse files
committed
ci(ordering): shard the project ordering leg and cache the tier guard's workflow parse (#2254)
Problem: the `Plain unittest ordering (project)` run step reached a p90 of 11.8 of its 20 minutes and was on course to hit the cap in about a week; `project-tests` runs the same leg on a docs-only diff under a 15-minute cap; and tests.test_tier_guard's WorkflowAgreementTests reran the same two tier selectors in a fresh interpreter seven times, about 7 s each. Fix: - B: util/run_unittest_leg.py takes --half 1|2, cut at the one name SHARD_BOUNDARIES holds for tests/project (test_q); the unittest-ordering matrix runs `project (half 1)` and `project (half 2)`, and project-tests runs its docs-only unittest step as two steps, one per half, in the same job. --before/--from cut at any other name by hand. - C: the tier guard's python stub replays a `-c` selector's output from a per-class cache once it has run it for real; a doctored step that asks something else, or a failing run, is not served from it. - Consolidation: no clear duplicate found; nothing removed. Tests: test_unittest_ordering_shards checks the cells and the project-tests steps cut at one boundary and cover the leg once; test_project_pins_once_1954 and test_unit_tests_queue read the new cells and steps; a new PythonStubTests case pins the cache. Workflow readers, tier guard and docstring contract: 1043 passed. actionlint clean.
1 parent 31142a8 commit 952d434

8 files changed

Lines changed: 327 additions & 56 deletions

File tree

‎.github/workflows/unit-tests.yml‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,15 @@ jobs:
11321132
# by a root-level module survives. The modules directly in tests/protocols
11331133
# stay in the rest cell, as moving them would split more pairs than it joins.
11341134
#
1135+
# #2254: the project cell's run step ran near its step cap, so tests/project,
1136+
# which has no subdirectories, is cut at a module name: `--half 1` and
1137+
# `--half 2`, at the one boundary SHARD_BOUNDARIES in util/run_unittest_leg.py
1138+
# holds, which `project-tests` cuts at too, so every module, a new one
1139+
# included, runs in exactly one half. The boundary is chosen so the halves
1140+
# take about the same CI time; both also run the root-level modules. Move
1141+
# SHARD_BOUNDARIES to rebalance. The same cost as #1029's: a pair split
1142+
# between the two cells does not share a process.
1143+
#
11351144
# Every tests/ subdirectory is a leg except those below, and
11361145
# tests/project/test_unittest_ordering_shards.py fails on a new one left out:
11371146
#
@@ -1140,7 +1149,7 @@ jobs:
11401149
# files, so the leg would run the root-level modules alone -- green,
11411150
# while covering none of it.
11421151
#
1143-
# The `project` cell keeps the project pins (#1954): whether a module passes
1152+
# The `project` cells keep the project pins (#1954): whether a module passes
11441153
# in one interpreter, in file order, with no xdist, is a question about the
11451154
# module, so a pin can fail it as readily as any other.
11461155
#
@@ -1170,7 +1179,6 @@ jobs:
11701179
- dumpkit
11711180
- foundation
11721181
- interface
1173-
- project
11741182
- protocols/internet
11751183
- toolkit
11761184
- utilities
@@ -1180,6 +1188,13 @@ jobs:
11801188
- leg: protocols
11811189
exclude: --exclude protocols/internet
11821190
label: protocols (rest)
1191+
# tests/project, cut at one module name -- see the #2254 note above.
1192+
- leg: project
1193+
shard: --half 1
1194+
label: project (half 1)
1195+
- leg: project
1196+
shard: --half 2
1197+
label: project (half 2)
11831198

11841199
steps:
11851200
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -1213,7 +1228,7 @@ jobs:
12131228
# under the job's, so a hang reports as this step timing out.
12141229
- name: Run tests/${{ matrix.leg }} and the root-level modules under plain unittest
12151230
timeout-minutes: 20
1216-
run: python util/cap_file_size.py python util/run_unittest_leg.py ${{ matrix.leg }} ${{ matrix.exclude }} --verbose
1231+
run: python util/cap_file_size.py python util/run_unittest_leg.py ${{ matrix.leg }} ${{ matrix.exclude }} ${{ matrix.shard }} --verbose
12171232

12181233
# ``CHANGELOG.md`` is generated from the newest entry under
12191234
# ``docs/source/changelog/`` by ``util/changelog_md.py``, and ``Create
@@ -1355,13 +1370,22 @@ jobs:
13551370
--durations=30 --durations-min=1.0 --junitxml="$RUNNER_TEMP/junit.xml" "${pins[@]}"
13561371

13571372
# #2164: the script's default stall dump sits under `unittest-ordering`'s
1358-
# 20-minute step cap, so this step passes its own, a minute under its
1373+
# 20-minute step cap, so these steps pass their own, a minute under their
13591374
# 15. tests/project/test_run_unittest_leg_stall_dump.py pins every step
13601375
# running the script to a dump inside its cap.
1361-
- name: Run tests/project and the root-level modules under plain unittest
1376+
#
1377+
# #2254: the whole leg ran near this cap, so it runs as
1378+
# `unittest-ordering`'s two `project` halves do, one step each, at the
1379+
# same boundary.
1380+
- name: Run the first half of tests/project and the root-level modules under plain unittest
1381+
if: ${{ needs.changes.outputs.code == 'false' }}
1382+
timeout-minutes: 15
1383+
run: python util/cap_file_size.py python util/run_unittest_leg.py project --half 1 --verbose --stall-dump 840
1384+
1385+
- name: Run the second half of tests/project and the root-level modules under plain unittest
13621386
if: ${{ needs.changes.outputs.code == 'false' }}
13631387
timeout-minutes: 15
1364-
run: python util/cap_file_size.py python util/run_unittest_leg.py project --verbose --stall-dump 840
1388+
run: python util/cap_file_size.py python util/run_unittest_leg.py project --half 2 --verbose --stall-dump 840
13651389

13661390
- name: Run the other tests that read docs/ or Markdown
13671391
if: ${{ needs.changes.outputs.code == 'false' }}

‎docs/source/contributing/conventions/test-coverage.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ Running the Tests
153153

154154
python util/run_unittest_leg.py protocols/internet
155155
python util/run_unittest_leg.py protocols --exclude protocols/internet
156+
python util/run_unittest_leg.py project --half 1
157+
python util/run_unittest_leg.py project --half 2
156158

157159
The leg list lives in the workflow, not the script. Every :file:`tests/`
158160
subdirectory is a leg except :file:`tests/integration/`, which holds no unit-tier

‎docs/source/contributing/workflows.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ Every ``test``, ``test-ktlo`` and ``experimental`` leg passes each pin as an
14151415
selection, so no workflow lists the pins, and :file:`tests/test_tier_guard.py` runs
14161416
the steps to check what each does with the answer. Under ``gate-only``, ``gate``'s
14171417
full suite runs the pins with everything else. ``unittest-ordering``'s ``project``
1418-
cell keeps them, as it asks how a module runs in one interpreter, in file order and
1418+
cells keep them, as they ask how a module runs in one interpreter, in file order and
14191419
without xdist, which is a question about the module rather than the Python version.
14201420

14211421
A pin's skip where ``tomllib`` is missing, before 3.11, runs on no leg: the scripts

‎tests/project/test_project_pins_once_1954.py‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
``pcapkit`` stay on every leg. :func:`tests._tiers.is_project_pin` decides which,
88
and :file:`tests/test_tier_guard.py` checks that rule and runs the steps that use
99
it. This module pins the rest: the job runs on every diff, on ``latest``, and
10-
blocks; the release gate and the ``unittest-ordering`` cell keep every pin; the
10+
blocks; the release gate and the ``unittest-ordering`` ``project`` cells keep every pin; the
1111
workflows page says so.
1212

1313
"""
@@ -67,15 +67,24 @@ def test_it_runs_under_the_caps(self) -> None:
6767

6868

6969
class TestEveryPinStillRunsWhereTheMatrixDoesNot(unittest.TestCase):
70-
"""The release gate's full suite and ``unittest-ordering``'s ``project`` cell keep every pin."""
70+
"""The release gate's full suite and ``unittest-ordering``'s ``project`` cells keep every pin."""
7171

7272
def test_the_gate_runs_the_whole_suite(self) -> None:
7373
self.assertEqual(step(('unit-tests.yml', 'gate'), 'Run full test suite')['run'],
7474
'python util/cap_file_size.py python -m pytest -q -n auto --dist load')
7575

7676
def test_the_ordering_cell_runs_every_pin(self) -> None:
77-
self.assertIn('project', job('unit-tests.yml', 'unittest-ordering')['strategy']['matrix']['leg'])
78-
modules = set(run_unittest_leg.leg_modules('project'))
77+
"""#2254: the ``project`` cells between them, as they cut ``tests/project`` in two."""
78+
matrix = job('unit-tests.yml', 'unittest-ordering')['strategy']['matrix']
79+
cells = [{'leg': name} for name in matrix['leg']] + list(matrix.get('include') or [])
80+
modules = set()
81+
for cell in cells:
82+
if cell['leg'] == 'project':
83+
words = str(cell.get('shard', '')).split()
84+
flags = dict(zip(words[::2], words[1::2]))
85+
cut = run_unittest_leg.half_bounds('project', int(flags['--half'])) if '--half' in flags else {}
86+
modules.update(run_unittest_leg.leg_modules('project', **cut))
87+
self.assertTrue(modules, 'no unittest-ordering cell runs tests/project')
7988
pins = {pin[:-len('.py')].replace('/', '.') for pin in _tiers.project_pin_paths()}
8089
self.assertTrue(pins)
8190
self.assertEqual(pins - modules, set())

‎tests/project/test_unit_tests_queue.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@ def test_project_tests_runs_on_every_diff_and_never_duplicates_test(self) -> Non
304304
self.assertIn('if: ${{ inputs.gate-only != true }}', head)
305305
self.assertNotIn('needs.changes.outputs.code', head)
306306
for name, condition in (('Run the project pins', "needs.changes.outputs.code != 'false'"),
307-
('Run tests/project and the root-level modules under plain unittest',
307+
('Run the first half of tests/project and the root-level modules under plain unittest',
308+
"needs.changes.outputs.code == 'false'"),
309+
('Run the second half of tests/project and the root-level modules under plain unittest',
308310
"needs.changes.outputs.code == 'false'"),
309311
('Run the other tests that read docs/ or Markdown',
310312
"needs.changes.outputs.code == 'false'")):

0 commit comments

Comments
 (0)