Skip to content

Commit

Permalink
Ref #497: add cache bust for Normandy recipes sync check
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem committed Jan 12, 2021
1 parent 643315b commit 6829306
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
18 changes: 13 additions & 5 deletions checks/normandy/remotesettings_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
The lists of missing and extraneous recipes are returned for the baseline and
capabilities collections.
"""
import random

from poucave.typings import CheckResult
from poucave.utils import fetch_json


NORMANDY_URL = "{server}/api/v1/recipe/signed/?enabled=1&only_baseline_capabilities={baseline_only}"
REMOTESETTINGS_URL = "{server}/buckets/main/collections/{cid}/records"
REMOTESETTINGS_URL = (
"{server}/buckets/main/collections/{cid}/changeset?_expected={expected}"
)


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

# Baseline recipes published on Remote Settings.
rs_recipes_baseline_url = REMOTESETTINGS_URL.format(
server=remotesettings_server, cid="normandy-recipes"
server=remotesettings_server,
cid="normandy-recipes",
expected=random.randint(999999000000, 999999999999),
)
rs_recipes_baseline = (await fetch_json(rs_recipes_baseline_url))["data"]
rs_recipes_baseline = (await fetch_json(rs_recipes_baseline_url))["changes"]
# Recipes with advanced capabilities.
rs_recipes_caps_urls = REMOTESETTINGS_URL.format(
server=remotesettings_server, cid="normandy-recipes-capabilities"
server=remotesettings_server,
cid="normandy-recipes-capabilities",
expected=random.randint(999999000000, 999999999999),
)
rs_recipes_caps = (await fetch_json(rs_recipes_caps_urls))["data"]
rs_recipes_caps = (await fetch_json(rs_recipes_caps_urls))["changes"]

# Make sure the baseline recipes are all listed in the baseline collection
missing_baseline, extras_baseline = compare_recipes_lists(
Expand Down
26 changes: 18 additions & 8 deletions tests/checks/normandy/test_remotesettings_recipes.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
from unittest import mock

from checks.normandy.remotesettings_recipes import NORMANDY_URL, run


NORMANDY_SERVER = "http://n"
REMOTESETTINGS_SERVER = "http://rs/v1"
REMOTESETTINGS_BASELINE_URL = (
REMOTESETTINGS_SERVER + "/buckets/main/collections/normandy-recipes/records"
REMOTESETTINGS_SERVER
+ "/buckets/main/collections/normandy-recipes/changeset?_expected=42"
)
REMOTESETTINGS_CAPABILITIES_URL = (
REMOTESETTINGS_SERVER
+ "/buckets/main/collections/normandy-recipes-capabilities/records"
+ "/buckets/main/collections/normandy-recipes-capabilities/changeset?_expected=42"
)

NORMANDY_RECIPE = {
Expand Down Expand Up @@ -67,13 +70,16 @@ async def test_positive(mock_aioresponses):
)
mock_aioresponses.get(
REMOTESETTINGS_CAPABILITIES_URL,
payload={"data": [REMOTESETTINGS_RECIPE, REMOTESETTINGS_RECIPE_WITH_CAPS]},
payload={"changes": [REMOTESETTINGS_RECIPE, REMOTESETTINGS_RECIPE_WITH_CAPS]},
)
mock_aioresponses.get(
REMOTESETTINGS_BASELINE_URL, payload={"data": [REMOTESETTINGS_RECIPE]}
REMOTESETTINGS_BASELINE_URL, payload={"changes": [REMOTESETTINGS_RECIPE]}
)

status, data = await run(NORMANDY_SERVER, REMOTESETTINGS_SERVER)
with mock.patch(
"checks.normandy.remotesettings_recipes.random.randint", return_value=42
):
status, data = await run(NORMANDY_SERVER, REMOTESETTINGS_SERVER)

assert status is True
assert data == {
Expand All @@ -94,13 +100,17 @@ async def test_negative(mock_aioresponses):
)
mock_aioresponses.get(
REMOTESETTINGS_CAPABILITIES_URL,
payload={"data": [REMOTESETTINGS_RECIPE_WITH_CAPS]},
payload={"changes": [REMOTESETTINGS_RECIPE_WITH_CAPS]},
)
mock_aioresponses.get(
REMOTESETTINGS_BASELINE_URL,
payload={"data": [RECIPE_42]},
payload={"changes": [RECIPE_42]},
)
status, data = await run(NORMANDY_SERVER, REMOTESETTINGS_SERVER)

with mock.patch(
"checks.normandy.remotesettings_recipes.random.randint", return_value=42
):
status, data = await run(NORMANDY_SERVER, REMOTESETTINGS_SERVER)

assert status is False
assert data == {
Expand Down

0 comments on commit 6829306

Please sign in to comment.