| 1 |
#!/usr/bin/env python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
import asyncio |
| 4 |
from datetime import datetime, timedelta |
| 5 |
import pytest |
| 6 |
|
| 7 |
from aiohttp_sse_client2 import client as sse_client |
| 8 |
|
| 9 |
from .const import WPT_SERVER |
| 10 |
|
| 11 |
|
| 12 |
@pytest.mark.asyncio |
| 13 |
async def test_eventsource_request_cancellation(): |
| 14 |
"""Test EventSource: reconnection event. |
| 15 |
|
| 16 |
..seealso: https://github.com/web-platform-tests/wpt/blob/master/ |
| 17 |
eventsource/eventsource-request-cancellation.htm |
| 18 |
""" |
| 19 |
closed = False |
| 20 |
def on_open(): |
| 21 |
if closed: |
| 22 |
assert False |
| 23 |
|
| 24 |
def on_error(): |
| 25 |
assert source.ready_state == sse_client.READY_STATE_CLOSED |
| 26 |
|
| 27 |
try: |
| 28 |
async with sse_client.EventSource( |
| 29 |
WPT_SERVER + 'resources/message.py?sleep=1000&message=' + |
| 30 |
"retry:1000\ndata:abc\n\n", |
| 31 |
on_open=on_open, |
| 32 |
on_error=on_error |
| 33 |
) as source: |
| 34 |
raise ConnectionAbortedError |
| 35 |
except ConnectionAbortedError: |
| 36 |
closed = True |
| 37 |
await asyncio.sleep(1) |
| 38 |
assert source.ready_state == sse_client.READY_STATE_CLOSED |
| 39 |
pass |