Skip to content

Commit 0c26c7e

Browse files
Merge pull request #817 from pyathena-dev/fix/816-cache-test-work-group
Assert cache hits in the test work group instead of primary
2 parents c7ca9a1 + 28c713d commit 0c26c7e

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

‎docs/usage.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ See the [Athena documentation](https://docs.aws.amazon.com/athena/latest/ug/reus
221221

222222
You can attempt to re-use the results from a previously executed query to help save time and money in the cases where your underlying data isn't changing.
223223
Set the `cache_size` or `cache_expiration_time` parameter of `cursor.execute()` to a number larger than 0 to enable caching.
224+
`cache_size` is the number of the most recent query executions in the work group to search, including executions by other clients of the same work group.
225+
In a busy work group, a previous execution may no longer be among them.
224226

225227
```python
226228
from pyathena import connect

‎tests/pyathena/test_cursor.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ def test_iterator(self, cursor):
9393
assert list(cursor) == [(1,)]
9494
pytest.raises(StopIteration, cursor.__next__)
9595

96+
# Cache hits are asserted in ENV.work_group: the default work group runs most test
97+
# queries, which can push earlier executions out of the cache_size window.
98+
@pytest.mark.parametrize("cursor", [{"work_group": ENV.work_group}], indirect=["cursor"])
9699
def test_cache_size(self, cursor):
97100
# To test caching, we need to make sure the query is unique, otherwise
98101
# we might accidentally pick up the cache results from another CI run.
@@ -143,6 +146,7 @@ def test_cache_expiration_time(self, cursor):
143146
assert query_id_1 != query_id_2
144147
assert query_id_3 in [query_id_1, query_id_2]
145148

149+
@pytest.mark.parametrize("cursor", [{"work_group": ENV.work_group}], indirect=["cursor"])
146150
def test_cache_expiration_time_with_cache_size(self, cursor):
147151
# Cache miss
148152
query = f"SELECT * FROM one_row -- {datetime.now(timezone.utc)!s}"

0 commit comments

Comments
 (0)