Skip to content

Commit c375821

Browse files
test(spanner): fix IndexError in async session retry deadline unit test (googleapis#17140)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/google-cloud-python/issues) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) ### Root Cause In Python 3.13 (and under recent `pytest-asyncio` / `asyncio` runtimes), the asynchronous event loop and task scheduling infrastructure makes internal calls to `time.time()` during coroutine execution and retry delay handling. In `test_run_in_transaction_w_abort_w_retry_metadata_deadline`, `time.time` was mocked using a helper that popped from a fixed 2-element list on every invocation (`_results.pop(0)`). The extra internal event loop calls exhausted `_results` prematurely, deterministically raising an `IndexError: pop from empty list` when `_delay_until_retry` checked the deadline. ### Solution Updated the `_time` mock helper in `packages/google-cloud-spanner/tests/unit/_async/test_session.py` to return the last timestamp repeatedly once `_results` has reached its final element: ```python def _time(_results=[1, 1.5]): if len(_results) > 1: return _results.pop(0) return _results[0]
1 parent 2670eab commit c375821

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

packages/google-cloud-spanner/tests/unit/_async/test_session.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,9 @@ async def unit_of_work(txn, *args, **kw):
18021802

18031803
# retry once w/ timeout_secs=1
18041804
def _time(_results=[1, 1.5]):
1805-
return _results.pop(0)
1805+
if len(_results) > 1:
1806+
return _results.pop(0)
1807+
return _results[0]
18061808

18071809
with mock.patch("time.time", _time):
18081810
with mock.patch(

0 commit comments

Comments
 (0)