Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions gql/transport/common/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ async def subscribe(
if listener.send_stop:
await self._stop_listener(query_id)
listener.send_stop = False
if isinstance(e, GeneratorExit):
raise e
raise e

finally:
log.debug(f"In subscribe finally for query_id {query_id}")
Expand Down
19 changes: 14 additions & 5 deletions tests/test_aiohttp_websocket_graphqlws_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,24 @@ async def test_aiohttp_websocket_graphqlws_subscription_task_cancel(
count = 10
subscription = gql(subscription_str.format(count=count))

task_cancelled = False

async def task_coro():
nonlocal count
async for result in session.subscribe(subscription):
nonlocal task_cancelled

number = result["number"]
print(f"Number received: {number}")
try:
async for result in session.subscribe(subscription):

assert number == count
number = result["number"]
print(f"Number received: {number}")

count -= 1
assert number == count

count -= 1
except asyncio.CancelledError:
print("Inside task cancelled")
task_cancelled = True

task = asyncio.ensure_future(task_coro())

Expand All @@ -317,6 +325,7 @@ async def cancel_task_coro():
await asyncio.gather(task, cancel_task)

assert count > 0
assert task_cancelled is True


@pytest.mark.asyncio
Expand Down
19 changes: 14 additions & 5 deletions tests/test_aiohttp_websocket_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,24 @@ async def test_aiohttp_websocket_subscription_task_cancel(
count = 10
subscription = gql(subscription_str.format(count=count))

task_cancelled = False

async def task_coro():
nonlocal count
async for result in session.subscribe(subscription):
nonlocal task_cancelled

number = result["number"]
print(f"Number received: {number}")
try:
async for result in session.subscribe(subscription):

assert number == count
number = result["number"]
print(f"Number received: {number}")

count -= 1
assert number == count

count -= 1
except asyncio.CancelledError:
print("Inside task cancelled")
task_cancelled = True

task = asyncio.ensure_future(task_coro())

Expand All @@ -308,6 +316,7 @@ async def cancel_task_coro():
await asyncio.gather(task, cancel_task)

assert count > 0
assert task_cancelled is True


@pytest.mark.asyncio
Expand Down
19 changes: 14 additions & 5 deletions tests/test_graphqlws_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,24 @@ async def test_graphqlws_subscription_task_cancel(
count = 10
subscription = gql(subscription_str.format(count=count))

task_cancelled = False

async def task_coro():
nonlocal count
async for result in session.subscribe(subscription):
nonlocal task_cancelled

number = result["number"]
print(f"Number received: {number}")
try:
async for result in session.subscribe(subscription):

assert number == count
number = result["number"]
print(f"Number received: {number}")

count -= 1
assert number == count

count -= 1
except asyncio.CancelledError:
print("Inside task cancelled")
task_cancelled = True

task = asyncio.ensure_future(task_coro())

Expand All @@ -315,6 +323,7 @@ async def cancel_task_coro():
await asyncio.gather(task, cancel_task)

assert count > 0
assert task_cancelled is True


@pytest.mark.asyncio
Expand Down
19 changes: 14 additions & 5 deletions tests/test_websocket_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,24 @@ async def test_websocket_subscription_task_cancel(client_and_server, subscriptio
count = 10
subscription = gql(subscription_str.format(count=count))

task_cancelled = False

async def task_coro():
nonlocal count
async for result in session.subscribe(subscription):
nonlocal task_cancelled

number = result["number"]
print(f"Number received: {number}")
try:
async for result in session.subscribe(subscription):

assert number == count
number = result["number"]
print(f"Number received: {number}")

count -= 1
assert number == count

count -= 1
except asyncio.CancelledError:
print("Inside task cancelled")
task_cancelled = True

task = asyncio.ensure_future(task_coro())

Expand All @@ -235,6 +243,7 @@ async def cancel_task_coro():
await asyncio.gather(task, cancel_task)

assert count > 0
assert task_cancelled is True


@pytest.mark.asyncio
Expand Down
Loading