mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-13 14:16:46 +00:00
Add plugins/lookup/playwright_workers.py computing a conservative parallel-worker count (CPU/RAM-derived, app-under-test concurrency-capped, reduced on CI) and wire test_e2e_playwright_workers + test_e2e_playwright_fully_parallel + test_e2e_playwright_test_timeout into playwright.config.js (read from env) and 02_run_one.yml (passed via -e). fullyParallel stays false so parallelism is file-level only and intra-file ordering assumptions stay safe. Raise run_timeout to 3600 for addon-heavy roles (nextcloud ~50 specs). Split the role's variables by Ansible precedence and intent: derived/fixed constants live in vars/main.yml (UPPERCASE, high precedence, not operator-tuned), operator-tunable knobs live in defaults/main.yml (lowercase, overridable). VARIANT_INDEX stays UPPERCASE with a single definition. Update references across tasks/templates/inventory/docs accordingly. Includes a unit test for playwright_workers and an autoformat pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
import unittest
|
|
|
|
from plugins.lookup.playwright_workers import LookupModule, compute_workers
|
|
|
|
|
|
class TestComputeWorkers(unittest.TestCase):
|
|
def test_local_20c_64g(self):
|
|
# cpu 20//4=5, ram (64*0.5)//1.5=21, cap 6 -> 5
|
|
self.assertEqual(compute_workers(20, 64.0, False), 5)
|
|
|
|
def test_local_12c_31g(self):
|
|
# cpu 12//4=3, ram 10, cap 6 -> 3
|
|
self.assertEqual(compute_workers(12, 31.0, False), 3)
|
|
|
|
def test_hard_cap_binds(self):
|
|
# cpu 64//4=16, ram huge -> capped at 6
|
|
self.assertEqual(compute_workers(64, 256.0, False), 6)
|
|
|
|
def test_ram_binds(self):
|
|
# 20 cores but only 3 GB -> (3*0.5)//1.5 = 1
|
|
self.assertEqual(compute_workers(20, 3.0, False), 1)
|
|
|
|
def test_ci_cap_binds(self):
|
|
# cpu 16//4=4, ram 21, cap 6 -> 4, then CI cap -> 2
|
|
self.assertEqual(compute_workers(16, 64.0, True), 2)
|
|
|
|
def test_ci_small_runner(self):
|
|
self.assertEqual(compute_workers(2, 8.0, True), 1)
|
|
|
|
def test_floor_is_one(self):
|
|
self.assertEqual(compute_workers(1, 1.0, False), 1)
|
|
|
|
def test_kwargs_override(self):
|
|
self.assertEqual(
|
|
compute_workers(20, 64.0, False, cpu_divisor=2, hard_cap=100), 10
|
|
)
|
|
|
|
|
|
class TestLookup(unittest.TestCase):
|
|
def test_returns_single_int_ge_1(self):
|
|
out = LookupModule().run([], variables={})
|
|
self.assertEqual(len(out), 1)
|
|
self.assertIsInstance(out[0], int)
|
|
self.assertGreaterEqual(out[0], 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|