From d5a449020d03ddee6547d2b65981b3bb084052cb Mon Sep 17 00:00:00 2001 From: Klaas van Schelven Date: Tue, 6 May 2025 10:42:18 +0200 Subject: [PATCH] Stress test: more fat-tailed randomness direct cause: the ability to create test-data for many-Issue setups --- bsmain/management/commands/stress_test.py | 25 ++++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/bsmain/management/commands/stress_test.py b/bsmain/management/commands/stress_test.py index 8cc6456..5b0fc98 100644 --- a/bsmain/management/commands/stress_test.py +++ b/bsmain/management/commands/stress_test.py @@ -16,6 +16,19 @@ from bugsink.streams import compress_with_zlib, WBITS_PARAM_FOR_GZIP, WBITS_PARA from issues.utils import get_values +def random_postfix(): + # avoids numbers, because when usedd in the type I imagine numbers may at some point be ignored in the grouping. + random_number = random.random() + + if random_number < 0.1: + # 10% of the time we simply sample from 1M to create a "fat tail". + unevenly_distributed_number = int(random.random() * 1_000_000) + else: + unevenly_distributed_number = int(1 / random_number) + + return "".join([chr(ord("A") + int(c)) for c in str(unevenly_distributed_number)]) + + class Command(BaseCommand): def add_arguments(self, parser): @@ -112,21 +125,13 @@ class Command(BaseCommand): k, v = tag.split(":", 1) if v == "RANDOM": - # avoids numbers in the type because I imagine numbers may at some point be ignored in the grouping. - into_chars = lambda i: "".join([chr(ord("A") + int(c)) for c in str(i)]) # noqa - - unevenly_distributed_number = int(1 / (random.random() + 0.0000001)) - v = "value-" + into_chars(unevenly_distributed_number) + v = "value-" + random_postfix() data["tags"][k] = v if options["random_type"]: - # avoids numbers in the type because I imagine numbers may at some point be ignored in the grouping. - into_chars = lambda i: "".join([chr(ord("A") + int(c)) for c in str(i)]) # noqa - - unevenly_distributed_number = int(1 / (random.random() + 0.0000001)) values = get_values(data["exception"]) - values[0]["type"] = "Exception" + into_chars(unevenly_distributed_number) + values[0]["type"] = "Exception" + random_postfix() data_bytes = json.dumps(data).encode("utf-8")