|
9 | 9 | import mock |
10 | 10 | import msgpack |
11 | 11 | import pytest |
12 | | -import asyncio |
13 | 12 |
|
14 | 13 | from ably import api_version |
15 | 14 | from ably import AblyException, IncompatibleClientIdException |
|
20 | 19 | from test.ably import utils |
21 | 20 |
|
22 | 21 | from test.ably.testapp import TestApp |
23 | | -from test.ably.utils import VaryByProtocolTestsMetaclass, dont_vary_protocol, BaseAsyncTestCase |
| 22 | +from test.ably.utils import VaryByProtocolTestsMetaclass, dont_vary_protocol, BaseAsyncTestCase, assert_waiter |
24 | 23 |
|
25 | 24 | log = logging.getLogger(__name__) |
26 | 25 |
|
@@ -402,26 +401,31 @@ async def test_interoperability(self): |
402 | 401 | expected_value = input_msg.get('expectedValue') |
403 | 402 |
|
404 | 403 | # 1) |
405 | | - await channel.publish(data=expected_value) |
406 | | - # temporary added delay, we need to investigate why messages don't appear immediately |
407 | | - await asyncio.sleep(1) |
408 | | - async with httpx.AsyncClient(http2=True) as client: |
409 | | - r = await client.get(url, auth=auth) |
410 | | - item = r.json()[0] |
411 | | - assert item.get('encoding') == encoding |
412 | | - if encoding == 'json': |
413 | | - assert json.loads(item['data']) == json.loads(msg_data) |
414 | | - else: |
415 | | - assert item['data'] == msg_data |
| 404 | + response = await channel.publish(data=expected_value) |
| 405 | + assert response.status_code == 201 |
| 406 | + |
| 407 | + async def check_data(): |
| 408 | + async with httpx.AsyncClient(http2=True) as client: |
| 409 | + r = await client.get(url, auth=auth) |
| 410 | + item = r.json()[0] |
| 411 | + encoding_is_correct = item.get('encoding') == encoding |
| 412 | + if encoding == 'json': |
| 413 | + return encoding_is_correct and json.loads(item['data']) == json.loads(msg_data) |
| 414 | + else: |
| 415 | + return encoding_is_correct and item['data'] == msg_data |
| 416 | + |
| 417 | + await assert_waiter(check_data) |
416 | 418 |
|
417 | 419 | # 2) |
418 | | - await channel.publish(messages=[Message(data=msg_data, encoding=encoding)]) |
419 | | - # temporary added delay, we need to investigate why messages don't appear immediately |
420 | | - await asyncio.sleep(1) |
421 | | - history = await channel.history() |
422 | | - message = history.items[0] |
423 | | - assert message.data == expected_value |
424 | | - assert type(message.data) == type_mapping[expected_type] |
| 420 | + response = await channel.publish(messages=[Message(data=msg_data, encoding=encoding)]) |
| 421 | + assert response.status_code == 201 |
| 422 | + |
| 423 | + async def check_history(): |
| 424 | + history = await channel.history() |
| 425 | + message = history.items[0] |
| 426 | + return message.data == expected_value and type(message.data) == type_mapping[expected_type] |
| 427 | + |
| 428 | + await assert_waiter(check_history) |
425 | 429 |
|
426 | 430 | # https://github.com/ably/ably-python/issues/130 |
427 | 431 | async def test_publish_slash(self): |
|
0 commit comments