Skip to content

Commit b65dfb1

Browse files
authored
Ref #497: add cache bust for Normandy recipes sync check (#739)
1 parent 643315b commit b65dfb1

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

checks/normandy/remotesettings_recipes.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
The lists of missing and extraneous recipes are returned for the baseline and
66
capabilities collections.
77
"""
8+
import random
9+
810
from poucave.typings import CheckResult
911
from poucave.utils import fetch_json
1012

1113

1214
NORMANDY_URL = "{server}/api/v1/recipe/signed/?enabled=1&only_baseline_capabilities={baseline_only}"
13-
REMOTESETTINGS_URL = "{server}/buckets/main/collections/{cid}/records"
15+
REMOTESETTINGS_URL = (
16+
"{server}/buckets/main/collections/{cid}/changeset?_expected={expected}"
17+
)
1418

1519

1620
def compare_recipes_lists(a, b):
@@ -38,14 +42,18 @@ async def run(normandy_server: str, remotesettings_server: str) -> CheckResult:
3842

3943
# Baseline recipes published on Remote Settings.
4044
rs_recipes_baseline_url = REMOTESETTINGS_URL.format(
41-
server=remotesettings_server, cid="normandy-recipes"
45+
server=remotesettings_server,
46+
cid="normandy-recipes",
47+
expected=random.randint(999999000000, 999999999999),
4248
)
43-
rs_recipes_baseline = (await fetch_json(rs_recipes_baseline_url))["data"]
49+
rs_recipes_baseline = (await fetch_json(rs_recipes_baseline_url))["changes"]
4450
# Recipes with advanced capabilities.
4551
rs_recipes_caps_urls = REMOTESETTINGS_URL.format(
46-
server=remotesettings_server, cid="normandy-recipes-capabilities"
52+
server=remotesettings_server,
53+
cid="normandy-recipes-capabilities",
54+
expected=random.randint(999999000000, 999999999999),
4755
)
48-
rs_recipes_caps = (await fetch_json(rs_recipes_caps_urls))["data"]
56+
rs_recipes_caps = (await fetch_json(rs_recipes_caps_urls))["changes"]
4957

5058
# Make sure the baseline recipes are all listed in the baseline collection
5159
missing_baseline, extras_baseline = compare_recipes_lists(

tests/checks/normandy/test_remotesettings_recipes.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
from unittest import mock
2+
13
from checks.normandy.remotesettings_recipes import NORMANDY_URL, run
24

35

46
NORMANDY_SERVER = "http://n"
57
REMOTESETTINGS_SERVER = "http://rs/v1"
68
REMOTESETTINGS_BASELINE_URL = (
7-
REMOTESETTINGS_SERVER + "/buckets/main/collections/normandy-recipes/records"
9+
REMOTESETTINGS_SERVER
10+
+ "/buckets/main/collections/normandy-recipes/changeset?_expected=42"
811
)
912
REMOTESETTINGS_CAPABILITIES_URL = (
1013
REMOTESETTINGS_SERVER
11-
+ "/buckets/main/collections/normandy-recipes-capabilities/records"
14+
+ "/buckets/main/collections/normandy-recipes-capabilities/changeset?_expected=42"
1215
)
1316

1417
NORMANDY_RECIPE = {
@@ -67,13 +70,16 @@ async def test_positive(mock_aioresponses):
6770
)
6871
mock_aioresponses.get(
6972
REMOTESETTINGS_CAPABILITIES_URL,
70-
payload={"data": [REMOTESETTINGS_RECIPE, REMOTESETTINGS_RECIPE_WITH_CAPS]},
73+
payload={"changes": [REMOTESETTINGS_RECIPE, REMOTESETTINGS_RECIPE_WITH_CAPS]},
7174
)
7275
mock_aioresponses.get(
73-
REMOTESETTINGS_BASELINE_URL, payload={"data": [REMOTESETTINGS_RECIPE]}
76+
REMOTESETTINGS_BASELINE_URL, payload={"changes": [REMOTESETTINGS_RECIPE]}
7477
)
7578

76-
status, data = await run(NORMANDY_SERVER, REMOTESETTINGS_SERVER)
79+
with mock.patch(
80+
"checks.normandy.remotesettings_recipes.random.randint", return_value=42
81+
):
82+
status, data = await run(NORMANDY_SERVER, REMOTESETTINGS_SERVER)
7783

7884
assert status is True
7985
assert data == {
@@ -94,13 +100,17 @@ async def test_negative(mock_aioresponses):
94100
)
95101
mock_aioresponses.get(
96102
REMOTESETTINGS_CAPABILITIES_URL,
97-
payload={"data": [REMOTESETTINGS_RECIPE_WITH_CAPS]},
103+
payload={"changes": [REMOTESETTINGS_RECIPE_WITH_CAPS]},
98104
)
99105
mock_aioresponses.get(
100106
REMOTESETTINGS_BASELINE_URL,
101-
payload={"data": [RECIPE_42]},
107+
payload={"changes": [RECIPE_42]},
102108
)
103-
status, data = await run(NORMANDY_SERVER, REMOTESETTINGS_SERVER)
109+
110+
with mock.patch(
111+
"checks.normandy.remotesettings_recipes.random.randint", return_value=42
112+
):
113+
status, data = await run(NORMANDY_SERVER, REMOTESETTINGS_SERVER)
104114

105115
assert status is False
106116
assert data == {

0 commit comments

Comments
 (0)