Skip to content

Commit 4c93665

Browse files
committed
move cache test to datasource
1 parent 1db5f56 commit 4c93665

File tree

3 files changed

+57
-183
lines changed

3 files changed

+57
-183
lines changed

ibis-server/tests/routers/v2/connector/test_postgres.py

+57
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import base64
2+
import os
3+
import shutil
24
from urllib.parse import quote_plus, urlparse
35

46
import orjson
@@ -10,6 +12,7 @@
1012
from testcontainers.postgres import PostgresContainer
1113

1214
from app.model.validator import rules
15+
from app.query_cache import QueryCacheManager
1316
from tests.conftest import file_path
1417

1518
pytestmark = pytest.mark.postgres
@@ -124,6 +127,15 @@ def postgres(request) -> PostgresContainer:
124127
return pg
125128

126129

130+
@pytest.fixture(scope="function")
131+
def cache_dir():
132+
temp_dir = "/tmp/wren-engine-test"
133+
os.makedirs(temp_dir, exist_ok=True)
134+
yield temp_dir
135+
# Clean up after the test
136+
shutil.rmtree(temp_dir, ignore_errors=True)
137+
138+
127139
async def test_query(client, manifest_str, postgres: PostgresContainer):
128140
connection_info = _to_connection_info(postgres)
129141
response = await client.post(
@@ -164,6 +176,51 @@ async def test_query(client, manifest_str, postgres: PostgresContainer):
164176
}
165177

166178

179+
async def test_query_with_cache(
180+
client, manifest_str, postgres: PostgresContainer, cache_dir, monkeypatch
181+
):
182+
# Override the cache path to use our test directory
183+
monkeypatch.setattr(
184+
QueryCacheManager,
185+
"_get_cache_path",
186+
lambda self, key: f"{cache_dir}/{key}.cache",
187+
)
188+
189+
connection_info = _to_connection_info(postgres)
190+
191+
# First request - should miss cache
192+
response1 = await client.post(
193+
url=f"{base_url}/query?cacheEnable=true", # Enable cache
194+
json={
195+
"connectionInfo": connection_info,
196+
"manifestStr": manifest_str,
197+
"sql": 'SELECT * FROM "Orders" LIMIT 10',
198+
},
199+
)
200+
201+
assert response1.status_code == 200
202+
assert response1.headers["X-Cache-Hit"] == "false"
203+
result1 = response1.json()
204+
205+
# Second request with same SQL - should hit cache
206+
response2 = await client.post(
207+
url=f"{base_url}/query?cacheEnable=true", # Enable cache
208+
json={
209+
"connectionInfo": connection_info,
210+
"manifestStr": manifest_str,
211+
"sql": 'SELECT * FROM "Orders" LIMIT 10',
212+
},
213+
)
214+
assert response2.status_code == 200
215+
assert response2.headers["X-Cache-Hit"] == "true"
216+
result2 = response2.json()
217+
218+
# Verify results are identical
219+
assert result1["data"] == result2["data"]
220+
assert result1["columns"] == result2["columns"]
221+
assert result1["dtypes"] == result2["dtypes"]
222+
223+
167224
async def test_query_with_connection_url(
168225
client, manifest_str, postgres: PostgresContainer
169226
):

ibis-server/tests/routers/v2/query_cache/__init__.py

Whitespace-only changes.

ibis-server/tests/routers/v2/query_cache/test_cache.py

-183
This file was deleted.

0 commit comments

Comments
 (0)