66from django .db import router
77from 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
1010from sentry .models .organizationmapping import OrganizationMapping
1111from sentry .organizations .services .organization import organization_service
1212from 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 ),
0 commit comments