test(backend): share the integration timeout budget between shards
This commit is contained in:
1 parent
d8abaae85b
commit
d6f960f8ae
4 files changed
+26
-3
No files matched your search
@@ -10,6 +10,17 @@ import subprocess
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
|
||||
# Time budget of the whole suite. CI runs it in two shards of ten minutes, so a
|
||||
# shard gets its share of the budget and never less than ten minutes, and an
|
||||
# unsharded local run gets the whole budget.
|
||||
SUITE_TIMEOUT_MINUTES = 20
|
||||
SHARD_TIMEOUT_FLOOR_MINUTES = 10
|
||||
|
||||
|
||||
def go_timeout(total):
|
||||
share = -(-SUITE_TIMEOUT_MINUTES // total)
|
||||
return f"{max(SHARD_TIMEOUT_FLOOR_MINUTES, share)}m"
|
||||
|
||||
|
||||
def shard_settings():
|
||||
index = os.environ.get("TEST_SHARD_INDEX")
|
||||
@@ -73,7 +84,7 @@ def run():
|
||||
# Go splits -run at slashes. Anchoring only the parent keeps all its subtests.
|
||||
pattern = "^(" + "|".join(re.escape(name) for name in names) + ")$"
|
||||
subprocess.run([
|
||||
*go, "test", "-tags=integration", "-count=1", "-timeout=10m",
|
||||
*go, "test", "-tags=integration", "-count=1", "-timeout=" + go_timeout(total),
|
||||
"-run=" + pattern, package,
|
||||
], check=True)
|
||||
|
||||
|
||||
@@ -114,6 +114,18 @@ class IntegrationSuiteTests(unittest.TestCase):
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(len(self.selected(calls)), 5)
|
||||
|
||||
def test_timeout_shares_the_suite_budget_between_shards(self):
|
||||
cases = [(None, "20m"), ("1", "20m"), ("2", "10m"), ("3", "10m")]
|
||||
for total, expected in cases:
|
||||
with self.subTest(total=total):
|
||||
settings = None if total is None else {"TEST_SHARD_INDEX": "1", "TEST_SHARD_TOTAL": total}
|
||||
result, calls = self.run_suite(settings)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
runs = [args for args in calls if any(arg.startswith("-run=") for arg in args)]
|
||||
self.assertTrue(runs)
|
||||
for args in runs:
|
||||
self.assertIn("-timeout=" + expected, args)
|
||||
|
||||
def test_discovery_order_does_not_change_selection(self):
|
||||
settings = {"TEST_SHARD_INDEX": "1", "TEST_SHARD_TOTAL": "2"}
|
||||
result, calls = self.run_suite(settings)
|
||||
|
||||
Reference in new issue
Block a user