Skip to content

Commit c801f6f

Browse files
fix: patch cache paths in concurrency tests and reuse nocache builders
1 parent 901c06a commit c801f6f

3 files changed

Lines changed: 19 additions & 17 deletions

File tree

services/workspace_db.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,12 @@ def build_composer_id_to_workspace_id_cached(
440440
nocache_enabled,
441441
)
442442

443-
if nocache_enabled(request_nocache=nocache):
444-
return build_composer_id_to_workspace_id(workspace_path, workspace_entries)
445-
446443
def build() -> dict[str, str]:
447444
return build_composer_id_to_workspace_id(workspace_path, workspace_entries)
448445

446+
if nocache_enabled(request_nocache=nocache):
447+
return build()
448+
449449
return get_or_build_cached_composer_id_to_ws(
450450
workspace_path,
451451
workspace_entries,

services/workspace_tabs.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,16 +526,15 @@ def list_workspace_tab_summaries(
526526
but ``tabs`` entries carry no ``bubbles`` field.
527527
"""
528528
workspace_entries = collect_workspace_entries(workspace_path)
529-
if nocache_enabled(request_nocache=nocache):
530-
return _build_workspace_tab_summaries_uncached(
531-
workspace_id, workspace_path, rules, workspace_entries, nocache=nocache,
532-
)
533529

534530
def build() -> tuple[dict[str, Any], int]:
535531
return _build_workspace_tab_summaries_uncached(
536532
workspace_id, workspace_path, rules, workspace_entries, nocache=nocache,
537533
)
538534

535+
if nocache_enabled(request_nocache=nocache):
536+
return build()
537+
539538
return get_or_build_cached_tab_summaries(
540539
workspace_path,
541540
workspace_entries,

tests/test_summary_cache_concurrency.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,21 @@ def _make_workspace_fixture(root: str) -> tuple[str, list[dict[str, object]]]:
4242
class TestSummaryCacheConcurrency(unittest.TestCase):
4343
def setUp(self):
4444
self.tmp = tempfile.TemporaryDirectory()
45-
self.cache_patch = patch.object(summary_cache, "CACHE_DIR", Path(self.tmp.name))
46-
self.cache_patch.start()
47-
summary_cache.PROJECTS_CACHE_FILE = Path(self.tmp.name) / "projects.json"
48-
summary_cache.COMPOSER_MAP_CACHE_FILE = (
49-
Path(self.tmp.name) / "composer-id-to-ws.json"
50-
)
51-
summary_cache.INVALID_WORKSPACE_ALIASES_CACHE_FILE = (
52-
Path(self.tmp.name) / "invalid-workspace-aliases.json"
53-
)
45+
cache_dir = Path(self.tmp.name)
46+
self._patches = [
47+
patch.object(summary_cache, "CACHE_DIR", cache_dir),
48+
patch.object(
49+
summary_cache,
50+
"PROJECTS_CACHE_FILE",
51+
cache_dir / "projects.json",
52+
),
53+
]
54+
for patcher in self._patches:
55+
patcher.start()
5456

5557
def tearDown(self):
56-
self.cache_patch.stop()
58+
for patcher in reversed(self._patches):
59+
patcher.stop()
5760
self.tmp.cleanup()
5861

5962
def test_blocked_build_recheck_returns_peer_cache(self):

0 commit comments

Comments
 (0)