Skip to content

Commit

Permalink
fix: correct confluent middlewares order
Browse files Browse the repository at this point in the history
  • Loading branch information
Lancetnik committed Nov 29, 2024
1 parent bc2bf8c commit eb3ff01
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion faststream/confluent/broker/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ async def publish_batch(
correlation_id = correlation_id or gen_cor_id()

call: AsyncFunc = self._producer.publish_batch
for m in self._middlewares:
for m in self._middlewares[::-1]:
call = partial(m(None).publish_scope, call)

await call(
Expand Down
32 changes: 26 additions & 6 deletions tests/brokers/base/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,22 @@ async def handler(msg):
mock.exit_inner.assert_called_once()
mock.exit_outer.assert_called_once()

assert [c.args[0] for c in mock.sub.call_args_list] == ["outer", "inner"]
assert [c.args[0] for c in mock.pub.call_args_list] == ["outer", "inner"]
assert [c.args[0] for c in mock.enter.call_args_list] == ["outer", "inner"]
assert [c.args[0] for c in mock.exit.call_args_list] == ["inner", "outer"]
assert [c.args[0] for c in mock.sub.call_args_list] == [
"outer",
"inner",
], mock.sub.call_args_list
assert [c.args[0] for c in mock.pub.call_args_list] == [
"outer",
"inner",
], mock.pub.call_args_list
assert [c.args[0] for c in mock.enter.call_args_list] == [
"outer",
"inner",
], mock.enter.call_args_list
assert [c.args[0] for c in mock.exit.call_args_list] == [
"inner",
"outer",
], mock.exit.call_args_list

async def test_publisher_middleware_order(
self, event: asyncio.Event, queue: str, mock: Mock, raw_broker
Expand Down Expand Up @@ -261,7 +273,11 @@ async def handler(msg):
mock.consume_middle.assert_called_once()
mock.consume_outer.assert_called_once()

assert [c.args[0] for c in mock.call_args_list] == ["outer", "middle", "inner"]
assert [c.args[0] for c in mock.call_args_list] == [
"outer",
"middle",
"inner",
], mock.call_args_list

async def test_consume_with_middleware_order(
self, event: asyncio.Event, queue: str, mock: Mock, raw_broker
Expand Down Expand Up @@ -312,7 +328,11 @@ async def handler(msg):
mock.consume_outer.assert_called_once()

assert event.is_set()
assert [c.args[0] for c in mock.call_args_list] == ["outer", "middle", "inner"]
assert [c.args[0] for c in mock.call_args_list] == [
"outer",
"middle",
"inner",
], mock.call_args_list


@pytest.mark.asyncio
Expand Down

0 comments on commit eb3ff01

Please sign in to comment.