From 6e613427adf40d0ce1654f751ac5812a9a0f5b6c Mon Sep 17 00:00:00 2001 From: mubashir1osmani Date: Wed, 24 Jun 2026 11:06:48 -0700 Subject: [PATCH] test(e2e): take the direct-GET spend-counter path on E2E_REDIS_CLUSTER The gateway's cache sets no namespace, so the counter key is the bare spend:key:. Trigger the cluster-safe direct GET on E2E_REDIS_CLUSTER (not only on E2E_REDIS_NAMESPACE) so the cluster deploy need not set a namespace it does not use; the namespaced key is still tried first when a namespace is given. --- tests/e2e/budgets/test_spend_counter_reseed_e2e.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/e2e/budgets/test_spend_counter_reseed_e2e.py b/tests/e2e/budgets/test_spend_counter_reseed_e2e.py index 51f84665012..e964ebd5ea6 100644 --- a/tests/e2e/budgets/test_spend_counter_reseed_e2e.py +++ b/tests/e2e/budgets/test_spend_counter_reseed_e2e.py @@ -61,14 +61,18 @@ def _redis(): def _spend_counter(rds, key: str) -> float | None: """The shared spend counter for `key`, or None if it is cold. The counter key is - ``{cache namespace}:spend:key:{sha256(key)}``. With E2E_REDIS_NAMESPACE set (the - cluster-mode deploy, where a keyspace SCAN can't span shards) read it directly; - otherwise match by suffix so a local namespace need not be hard-coded.""" + the optional cache namespace plus ``spend:key:{sha256(key)}``. A cluster client + can't run a keyspace SCAN that spans shards, so on E2E_REDIS_CLUSTER (or when a + namespace is given) read the key directly - the namespaced key, then the bare + suffix. Otherwise match by suffix so a local namespace need not be hard-coded.""" digest = hashlib.sha256(key.encode()).hexdigest() suffix = f"spend:key:{digest}" namespace = os.getenv("E2E_REDIS_NAMESPACE") - if namespace: - for candidate in (f"{namespace}:{suffix}", suffix): + cluster = os.getenv("E2E_REDIS_CLUSTER", "false").lower() in ("1", "true", "yes") + if cluster or namespace: + candidates = [f"{namespace}:{suffix}"] if namespace else [] + candidates.append(suffix) + for candidate in candidates: raw = rds.get(candidate) if raw is not None: return float(raw)