Skip to content

Commit

Permalink
test_concurrent_close should be sync only
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepyStick committed Sep 13, 2024
1 parent 04e96b5 commit 3b8c85c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
17 changes: 9 additions & 8 deletions test/asynchronous/test_change_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,24 +346,25 @@ async def test_aggregate_cursor_blocks(self):
self._test_next_blocks(change_stream)

@no_type_check
async def test_concurrent_close(self):
"""Ensure a AsyncChangeStream can be closed from another thread."""
@async_client_context.require_sync
def test_concurrent_close(self):
"""Ensure a ChangeStream can be closed from another thread."""
# Use a short wait time to speed up the test.
async with await self.change_stream(max_await_time_ms=250) as change_stream:
with self.change_stream(max_await_time_ms=250) as change_stream:

async def iterate_cursor():
def iterate_cursor():
try:
async for _ in change_stream:
for _ in change_stream:
pass
except OperationFailure as e:
if e.code != 237: # AsyncCursorKilled error code
raise

t = threading.Thread(target=iterate_cursor)
t.start()
await self.watched_collection().insert_one({})
await asyncio.sleep(1)
await change_stream.close()
self.watched_collection().insert_one({})
asyncio.sleep(1)
change_stream.close()
t.join(3)
self.assertFalse(t.is_alive())

Expand Down
1 change: 1 addition & 0 deletions test/test_change_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ def test_aggregate_cursor_blocks(self):
self._test_next_blocks(change_stream)

@no_type_check
@client_context.require_sync
def test_concurrent_close(self):
"""Ensure a ChangeStream can be closed from another thread."""
# Use a short wait time to speed up the test.
Expand Down

0 comments on commit 3b8c85c

Please sign in to comment.