From da7154cc8998a822025c69ff327c8b22cce9370e Mon Sep 17 00:00:00 2001 From: stumpylog <797416+stumpylog@users.noreply.github.com> Date: Wed, 26 Aug 2026 13:43:31 -0700 Subject: [PATCH] Test: warm up cached lookups before comparing bulk permission-set query counts The 5-tag vs 50-tag comparison could pick up a one-time cold-cache query (e.g. Django's ContentType cache) on whichever call ran first, making the assertion fail independent of actual tag count -- reproduced in CI on Python 3.11/3.14 only. A throwaway warm-up call before both measured runs removes that skew. --- src/documents/tests/test_api_objects.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/documents/tests/test_api_objects.py b/src/documents/tests/test_api_objects.py index 0cdf20dc2..56a2829b2 100644 --- a/src/documents/tests/test_api_objects.py +++ b/src/documents/tests/test_api_objects.py @@ -840,7 +840,7 @@ class TestBulkEditObjects(APITestCase): "change": {"users": [self.user1.id], "groups": [group1.id]}, } - def run_with_n_tags(n: int) -> int: + def run_with_n_tags(n: int, *, capture: bool = True) -> int | None: tags = [Tag.objects.create(name=f"perm-tag-{n}-{i}") for i in range(n)] with CaptureQueriesContext(connection) as ctx: response = self.client.post( @@ -860,7 +860,13 @@ class TestBulkEditObjects(APITestCase): for tag in tags: self.assertEqual(get_users_with_perms(tag).count(), 2) self.assertEqual(get_groups_with_perms(tag).count(), 1) - return len(ctx.captured_queries) + return len(ctx.captured_queries) if capture else None + + # Warm up any one-time, process/instance-cached lookups (e.g. Django's + # ContentType cache) on the same code path before measuring, so the + # comparison below isn't skewed by whichever of the two calls happens + # to pay a cold-cache cost that has nothing to do with tag count. + run_with_n_tags(1, capture=False) small_batch_queries = run_with_n_tags(5) large_batch_queries = run_with_n_tags(50)