Skip to content

Commit

Permalink
chore: update test case
Browse files Browse the repository at this point in the history
  • Loading branch information
berrytern committed Oct 2, 2024
1 parent 48ca475 commit c37a152
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion amqp_client_python/rabbitmq/async_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ async def rpc_subscribe(

self.queue_bind(queue_name, exchange_name, routing_key)
if not self.consumers[queue_name]:
registered: Future[bool] = Future(loop=self.ioloop)
registered: Future[bool] = self.ioloop.create_future()
self.consumers[queue_name] = True
func = partial(self.on_message, queue_name)
self._channel.basic_consume(
Expand Down
19 changes: 9 additions & 10 deletions tests/unit/channels/test_rpc_subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ async def test_async_channel_subscribe(

future_publisher = Future(loop=loop)
future_publisher.set_result(True)
connection_mock.ioloop.create_future.side_effect = [
future_publisher,
]
connection_mock.ioloop.call_later = loop.call_later
connection_mock.ioloop.create_future.return_value = future_publisher
channel_factory_mock.create_channel.return_value = channel_mock
channel = AsyncChannel(channel_factory=channel_factory_mock, channel_type=ConnectionType.RPC_SERVER)
channel = AsyncChannel(
channel_factory=channel_factory_mock, channel_type=ConnectionType.RPC_SERVER
)
channel.open(connection_mock)

async def handle(*body):
Expand All @@ -34,7 +35,7 @@ async def handle(*body):
)
assert channel._channel == channel_mock
assert iscoroutine(rpc_subscribe)
assert await rpc_subscribe is None
assert (await rpc_subscribe) is None
channel_mock.basic_consume.assert_called_once()
assert channel_mock.basic_consume.call_args.args == (queue_name,)

Expand All @@ -54,9 +55,7 @@ async def test_rpc_subscribe_publisher_started(
future_publisher = Future(loop=loop)
if consumer:
future_publisher.set_result(True)
connection_mock.ioloop.create_future.side_effect = [
future_publisher,
]
connection_mock.ioloop.create_future.return_value = future_publisher
connection_mock.ioloop.call_later = loop.call_later
channel_factory_mock.create_channel.return_value = channel_mock
channel = AsyncChannel(channel_factory=channel_factory_mock)
Expand All @@ -66,10 +65,10 @@ async def handle(*body):
return b"result"

rpc_subscribe = channel.rpc_subscribe(
exchange, routing_key, queue_name, handle, content_type, connection_mock.ioloop
exchange, routing_key, queue_name, handle, content_type
)
if consumer:
assert await rpc_subscribe is None
assert (await rpc_subscribe) is None
assert channel.rpc_publisher_starting is True
else:
with pytest.raises(EventBusException):
Expand Down

0 comments on commit c37a152

Please sign in to comment.