Skip to content

test: strengthen test_cache_bypass with mocks instead of live ES dependency#138

Merged
shuchenliu merged 2 commits intot1_cache_bypassfrom
copilot/sub-pr-137
Mar 3, 2026
Merged

test: strengthen test_cache_bypass with mocks instead of live ES dependency#138
shuchenliu merged 2 commits intot1_cache_bypassfrom
copilot/sub-pr-137

Conversation

Copy link
Contributor

Copilot AI commented Mar 3, 2026

test_cache_bypass only checked that run_query(..., bypass_cache=True) returned results against a live ES instance — it never verified that indices.clear_cache was actually invoked. The test would skip silently on any connection failure, giving false confidence.

Changes

  • Inject AsyncMock ES connection — eliminates the live ES requirement and the try/connect/skip pattern entirely
  • Monkeypatch run_single_query — decouples the assertion from actual query execution
  • Assert clear_cache called correctly — verifies indices.clear_cache is invoked once with the configured index name when bypass_cache=True
  • Assert run_single_query called with expected payload — confirms the query execution path runs after cache clearing
mock_es = AsyncMock()
mock_es.indices.clear_cache.return_value = {"_shards": {"successful": 1, "total": 1}}
driver.es_connection = mock_es

monkeypatch.setattr(driver_mod, "run_single_query", AsyncMock(return_value=[]))

hits = await driver.run_query(payload, bypass_cache=True)

mock_es.indices.clear_cache.assert_called_once_with(
    index=driver_mod.CONFIG.tier1.elasticsearch.index_name
)
mock_run_single.assert_called_once_with(
    es_connection=mock_es,
    index_name=driver_mod.CONFIG.tier1.elasticsearch.index_name,
    query=payload,
)

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

@sentry
Copy link

sentry bot commented Mar 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-authored-by: shuchenliu <5944967+shuchenliu@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix implementation of bypass_cache flag based on feedback test: strengthen test_cache_bypass with mocks instead of live ES dependency Mar 3, 2026
@shuchenliu shuchenliu marked this pull request as ready for review March 3, 2026 04:48
@shuchenliu shuchenliu merged commit a81a5a8 into t1_cache_bypass Mar 3, 2026
5 checks passed
@shuchenliu shuchenliu deleted the copilot/sub-pr-137 branch March 3, 2026 04:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants