Skip to content

Commit e8ce16f

Browse files
committed
update more tests
1 parent 96794f1 commit e8ce16f

8 files changed

Lines changed: 62 additions & 38 deletions

File tree

src/sentry/types/cell.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,18 +285,18 @@ def _parse_locality_config(
285285

286286

287287
def load_from_config(
288-
region_config: list[CellConfig],
288+
cell_config: list[CellConfig],
289289
locality_config: list[LocalityConfig],
290290
) -> CellDirectory:
291291
try:
292-
if not region_config and not locality_config:
292+
if not cell_config and not locality_config:
293293
return generate_monolith_cell_directory()
294-
cells = set(_parse_raw_config(region_config))
294+
cells = set(_parse_raw_config(cell_config))
295295
localities = set(_parse_locality_config(locality_config))
296296
return CellDirectory(cells, localities)
297297
except Exception as e:
298298
sentry_sdk.capture_exception(e)
299-
raise CellConfigurationError("Unable to parse region_config.") from e
299+
raise CellConfigurationError("Unable to parse cell config.") from e
300300

301301

302302
_global_directory: CellDirectory | None = None

tests/sentry/synapse/endpoints/test_org_cell_mappings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
from sentry.testutils.cases import APITestCase
77
from sentry.testutils.cell import override_cells
88
from sentry.testutils.silo import control_silo_test
9-
from sentry.types.cell import Cell, RegionCategory
9+
from sentry.types.cell import Cell
1010

11-
us_cell = Cell("us", 1, "https://us.testserver", RegionCategory.MULTI_TENANT)
12-
de_cell = Cell("de", 2, "https://de.testserver", RegionCategory.MULTI_TENANT)
11+
us_cell = Cell("us", 1, "https://us.testserver")
12+
de_cell = Cell("de", 2, "https://de.testserver")
1313
cell_config = (us_cell, de_cell)
1414

1515

tests/sentry/types/test_cell.py

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from django.db import router
77
from django.test import RequestFactory, override_settings
88

9-
from sentry.conf.types.cell_config import CellConfig
9+
from sentry.conf.types.cell_config import CellConfig, LocalityConfig
1010
from sentry.models.organizationmapping import OrganizationMapping
1111
from sentry.organizations.services.organization import organization_service
1212
from sentry.silo.base import SiloLimit, SiloMode
@@ -48,20 +48,38 @@ class CellDirectoryTest(TestCase):
4848
"name": "us",
4949
"snowflake_id": 1,
5050
"address": "http://us.testserver",
51-
"category": RegionCategory.MULTI_TENANT.name,
5251
},
5352
{
5453
"name": "eu",
5554
"snowflake_id": 2,
5655
"address": "http://eu.testserver",
5756
"api_gateway_address": "http://eu-gateway.testserver",
58-
"category": RegionCategory.MULTI_TENANT.name,
5957
},
6058
{
6159
"name": "acme",
6260
"snowflake_id": 3,
6361
"address": "http://acme.testserver",
62+
},
63+
]
64+
65+
_LOCALITY_INPUTS: list[LocalityConfig] = [
66+
{
67+
"name": "us",
68+
"cells": ["us"],
69+
"category": RegionCategory.MULTI_TENANT.name,
70+
"new_org_cell": "us",
71+
},
72+
{
73+
"name": "eu",
74+
"cells": ["eu"],
75+
"category": RegionCategory.MULTI_TENANT.name,
76+
"new_org_cell": "eu",
77+
},
78+
{
79+
"name": "acme",
80+
"cells": ["acme"],
6481
"category": RegionCategory.SINGLE_TENANT.name,
82+
"new_org_cell": "acme",
6583
},
6684
]
6785

@@ -79,7 +97,12 @@ class CellDirectoryTest(TestCase):
7997
@staticmethod
8098
@contextmanager
8199
def _in_global_state(directory: CellDirectory) -> Generator[None]:
82-
with get_test_env_directory().swap_state(tuple(directory.cells)):
100+
# Pass localities through even when empty; omitting them (None) makes
101+
# the test directory synthesize a 1:1 MULTI_TENANT locality per cell,
102+
# which would override the categories defined in the config under test.
103+
with get_test_env_directory().swap_state(
104+
tuple(directory.cells), localities=tuple(directory.localities)
105+
):
83106
yield
84107

85108
def test_cell_config_parsing_in_monolith(self) -> None:
@@ -117,7 +140,6 @@ def test_get_generated_monolith_cell(self) -> None:
117140
local_cell = get_local_cell()
118141
assert local_cell.name == "defaultland"
119142
assert local_cell.snowflake_id == 0
120-
assert local_cell.category == RegionCategory.MULTI_TENANT
121143

122144
@override_settings(SILO_MODE=SiloMode.CONTROL)
123145
@unguarded_write(using=router.db_for_write(OrganizationMapping))
@@ -235,7 +257,7 @@ def test_find_all_cell_names(self) -> None:
235257
@override_settings(SILO_MODE=SiloMode.CONTROL)
236258
def test_find_all_multitenant_cell_names(self) -> None:
237259
with override_settings(SENTRY_MONOLITH_REGION="us"):
238-
directory = load_from_config(self._INPUTS, [])
260+
directory = load_from_config(self._INPUTS, self._LOCALITY_INPUTS)
239261
with self._in_global_state(directory):
240262
result = find_all_multitenant_cell_names()
241263
assert set(result) == {"us", "eu"}
@@ -252,8 +274,9 @@ def test_find_all_multitenant_cell_names_non_visible(self) -> None:
252274
"visible": False,
253275
},
254276
]
277+
locality_inputs: list[LocalityConfig] = self._LOCALITY_INPUTS
255278
with override_settings(SENTRY_MONOLITH_REGION="us"):
256-
directory = load_from_config(inputs, [])
279+
directory = load_from_config(inputs, locality_inputs)
257280
with self._in_global_state(directory):
258281
result = find_all_multitenant_cell_names()
259282
assert set(result) == {"us", "eu"}
@@ -265,12 +288,19 @@ def test_subdomain_is_locality(self) -> None:
265288
"name": "us",
266289
"snowflake_id": 1,
267290
"address": "https://us.testserver",
268-
"category": "MULTI_TENANT",
291+
},
292+
]
293+
localities: list[LocalityConfig] = [
294+
{
295+
"name": "us",
296+
"cells": ["us"],
297+
"category": RegionCategory.MULTI_TENANT.name,
298+
"new_org_cell": "us",
269299
},
270300
]
271301
rf = RequestFactory()
272302
with override_settings(SENTRY_MONOLITH_REGION="us"):
273-
directory = load_from_config(cells, [])
303+
directory = load_from_config(cells, localities)
274304
with self._in_global_state(directory):
275305
req = rf.get("/")
276306
setattr(req, "subdomain", "us")
@@ -285,28 +315,24 @@ def test_get_new_org_cell_for_locality(self) -> None:
285315
Cell(
286316
name="us",
287317
snowflake_id=1,
288-
category=RegionCategory.MULTI_TENANT,
289318
address="10.0.0.1",
290319
visible=True,
291320
),
292321
Cell(
293322
name="us2",
294323
snowflake_id=3,
295-
category=RegionCategory.MULTI_TENANT,
296324
address="10.0.0.2",
297325
visible=True,
298326
),
299327
Cell(
300328
name="de1",
301329
snowflake_id=2,
302-
category=RegionCategory.MULTI_TENANT,
303330
address="10.0.0.3",
304331
visible=True,
305332
),
306333
Cell(
307334
name="de2",
308335
snowflake_id=4,
309-
category=RegionCategory.MULTI_TENANT,
310336
address="10.0.0.4",
311337
visible=True,
312338
),

tests/sentry/users/api/endpoints/test_user_regions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from sentry.testutils.silo import control_silo_test
44
from sentry.types.cell import Cell, Locality, RegionCategory
55

6-
us = Cell("us", 1, "https://us.testserver", RegionCategory.MULTI_TENANT)
7-
de = Cell("de", 2, "https://de.testserver", RegionCategory.MULTI_TENANT)
8-
st = Cell("acme", 3, "https://acme.testserver", RegionCategory.SINGLE_TENANT)
6+
us = Cell("us", 1, "https://us.testserver")
7+
de = Cell("de", 2, "https://de.testserver")
8+
st = Cell("acme", 3, "https://acme.testserver")
99
cell_config = (us, de, st)
1010

1111
us_locality = Locality(

tests/sentry/users/models/test_user.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@
4444
from sentry.testutils.hybrid_cloud import HybridCloudTestMixin
4545
from sentry.testutils.outbox import outbox_runner
4646
from sentry.testutils.silo import assume_test_silo_mode, assume_test_silo_mode_of, control_silo_test
47-
from sentry.types.cell import Cell, RegionCategory, find_cells_for_user
47+
from sentry.types.cell import Cell, find_cells_for_user
4848
from sentry.users.models.authenticator import Authenticator
4949
from sentry.users.models.user import User
5050
from sentry.users.models.useremail import UserEmail
5151
from tests.sentry.backup import expect_models
5252

5353
_TEST_CELLS = (
54-
Cell("na", 1, "http://eu.testserver", RegionCategory.MULTI_TENANT),
55-
Cell("eu", 2, "http://na.testserver", RegionCategory.MULTI_TENANT),
54+
Cell("na", 1, "http://eu.testserver"),
55+
Cell("eu", 2, "http://na.testserver"),
5656
)
5757

5858

tests/sentry/utils/test_snowflake.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from sentry.testutils.cases import TestCase
1212
from sentry.testutils.cell import override_cells
1313
from sentry.testutils.helpers.datetime import freeze_time
14-
from sentry.types.cell import Cell, RegionCategory
14+
from sentry.types.cell import Cell
1515
from sentry.users.models.user import User
1616
from sentry.utils import snowflake
1717
from sentry.utils.snowflake import (
@@ -36,7 +36,7 @@ def test_uses_snowflake_id(self) -> None:
3636

3737
@freeze_time(CURRENT_TIME)
3838
def test_generate_correct_ids(self) -> None:
39-
cell = Cell("test-cell", 0, "http://testserver", RegionCategory.MULTI_TENANT)
39+
cell = Cell("test-cell", 0, "http://testserver")
4040
with override_settings(SILO_MODE=SiloMode.CELL), override_cells([cell], cell):
4141
snowflake_id = generate_snowflake_id("test_redis_key")
4242
expected_value = (16 << 48) + (
@@ -47,7 +47,7 @@ def test_generate_correct_ids(self) -> None:
4747

4848
@freeze_time(CURRENT_TIME)
4949
def test_generate_correct_ids_with_cell_sequence(self) -> None:
50-
cell = Cell("test-cell", 0, "http://testserver", RegionCategory.MULTI_TENANT)
50+
cell = Cell("test-cell", 0, "http://testserver")
5151
with override_settings(SILO_MODE=SiloMode.CELL), override_cells([cell], cell):
5252
snowflake_id = generate_snowflake_id("test_redis_key")
5353

@@ -84,8 +84,8 @@ def test_out_of_cell_sequences(self) -> None:
8484
@freeze_time(CURRENT_TIME)
8585
def test_generate_correct_ids_with_cell_id(self) -> None:
8686
cells = [
87-
c1 := Cell("test-cell-1", 1, "localhost:8001", RegionCategory.MULTI_TENANT),
88-
c2 := Cell("test-cell-2", 2, "localhost:8002", RegionCategory.MULTI_TENANT),
87+
c1 := Cell("test-cell-1", 1, "localhost:8001"),
88+
c2 := Cell("test-cell-2", 2, "localhost:8002"),
8989
]
9090
with override_settings(SILO_MODE=SiloMode.CELL):
9191
with override_cells(cells, c1):

tests/sentry/web/frontend/test_react_page.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
from sentry.testutils.cell import override_cells
1212
from sentry.testutils.helpers.options import override_options
1313
from sentry.testutils.silo import control_silo_test
14-
from sentry.types.cell import Cell, RegionCategory
14+
from sentry.types.cell import Cell
1515
from sentry.web.frontend.react_page import NON_CUSTOMER_DOMAIN_URL_NAMES, ReactMixin
1616

17-
us = Cell("us", 1, "http://us.testserver", RegionCategory.MULTI_TENANT)
17+
us = Cell("us", 1, "http://us.testserver")
1818

1919

2020
@control_silo_test
@@ -415,9 +415,9 @@ def test_document_policy_header(self) -> None:
415415
assert response.headers["Document-Policy"] == "js-profiling"
416416

417417
def test_dns_prefetch(self) -> None:
418-
us_region = Cell("us", 1, "https://us.testserver", RegionCategory.MULTI_TENANT)
419-
de_region = Cell("de", 1, "https://de.testserver", RegionCategory.MULTI_TENANT)
420-
with override_cells(cells=[us_region, de_region]):
418+
us_cell = Cell("us", 1, "https://us.testserver")
419+
de_cell = Cell("de", 1, "https://de.testserver")
420+
with override_cells(cells=[us_cell, de_cell]):
421421
user = self.create_user("bar@example.com")
422422
org = self.create_organization(owner=user)
423423
self.login_as(user)

tests/sentry/web/test_client_config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,12 @@ def test_client_config_with_region_data() -> None:
232232
name="us",
233233
snowflake_id=1,
234234
address="https//us.testserver",
235-
category=cell.RegionCategory.MULTI_TENANT,
236235
),
237236
cell.Cell(
238237
name="eu",
239238
snowflake_id=5,
240239
address="https//eu.testserver",
241240
visible=False,
242-
category=cell.RegionCategory.MULTI_TENANT,
243241
),
244242
]
245243

0 commit comments

Comments
 (0)