Skip to content

Commit a76861b

Browse files
authored
chore(spanner): fix event loop leak in unit tests (#17343)
This PR resolves leaky asyncio event loops inside the Spanner unit tests that were causing flaky results during local nox testing. The original version of the event loop was not closing out events and we were left with too many open files. Fixes #17049
1 parent 7f988ff commit a76861b

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

  • packages/google-cloud-spanner/tests/unit/gapic

packages/google-cloud-spanner/tests/unit/gapic/conftest.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ def provide_loop_to_sync_grpc_tests():
1111
If no global loop exists, `grpc.aio` engine crashes during initialization.
1212
"""
1313
try:
14-
loop = asyncio.get_event_loop()
14+
asyncio.get_running_loop()
1515
except RuntimeError:
1616
loop = asyncio.new_event_loop()
1717
asyncio.set_event_loop(loop)
18-
19-
yield
20-
# No close here, just ensure existance
18+
try:
19+
yield
20+
finally:
21+
loop.close()
22+
asyncio.set_event_loop(None)
23+
else:
24+
yield

0 commit comments

Comments
 (0)