From 6dbc46da44d7c8bed8444284e96827d08770f482 Mon Sep 17 00:00:00 2001 From: quentin on chickenita Date: Mon, 3 Jul 2023 17:58:11 +0200 Subject: [PATCH] fix endnodes for condition channels that launch ever if the condition is false --- pypeman/channels.py | 9 ++++--- pypeman/nodes.py | 1 - pypeman/tests/test_channel.py | 46 +++++++++++++++++++++++------------ 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/pypeman/channels.py b/pypeman/channels.py index 530b41d8..8a09313c 100644 --- a/pypeman/channels.py +++ b/pypeman/channels.py @@ -229,7 +229,7 @@ def _reset_test(self): if self.final_nodes: for node in self.final_nodes: node._reset_test() - if self.final_nodes: + if self.fail_nodes: for node in self.fail_nodes: node._reset_test() @@ -362,7 +362,6 @@ async def handle(self, msg): if self.status in [BaseChannel.STOPPED, BaseChannel.STOPPING]: raise ChannelStopped("Channel is stopped so you can't send message.") - self.logger.info("chan %s handle %s", str(self), str(msg)) has_callback = hasattr(self, "_callback") setattr(msg, "chan_rslt", None) @@ -749,8 +748,12 @@ def test_condition(self, msg): return self.condition async def subhandle(self, msg): + result = await self.process(msg) + return result + + async def handle(self, msg): if self.test_condition(msg): - result = await self.process(msg) + result = await super().handle(msg) else: if self.next_node: result = await self.next_node.handle(msg) diff --git a/pypeman/nodes.py b/pypeman/nodes.py index e64c44b1..e22a36e8 100644 --- a/pypeman/nodes.py +++ b/pypeman/nodes.py @@ -161,7 +161,6 @@ async def handle(self, msg): # TODO : Make sure exceptions are well raised (does not happen if i.e 1/0 here atm) if self.store_input_as: msg.add_context(self.store_input_as, msg) - if self.passthrough: old_msg = msg.copy() # Allow process as coroutine function diff --git a/pypeman/tests/test_channel.py b/pypeman/tests/test_channel.py index 1bea27df..e1c6fa6c 100644 --- a/pypeman/tests/test_channel.py +++ b/pypeman/tests/test_channel.py @@ -358,35 +358,49 @@ def test_condchan_endnodes(self): chan1.add_fail_nodes(chan1_endfail) chan1.add_join_nodes(chan1_endok) chan1.add_final_nodes(chan1_endfinal) + + condchan_end = TstNode(name="condchan_end") + condchan.add_final_nodes(condchan_end) + chan1._reset_test() + # Test Msg don't enter in exc subchan startmsg = generate_msg(message_content="startmsg") self.start_channels() self.loop.run_until_complete(chan1.handle(startmsg)) - self.assertTrue( - chan1_endok.processed, - "chan1 ok_endnodes not called") - self.assertTrue( - chan1_endfinal.processed, - "chan1 final_endnodes not called") - self.assertFalse( - chan1_endfail.processed, + self.assertEqual( + chan1_endok.processed, 1, + "chan1 ok_endnodes not called or called multiple times") + self.assertEqual( + chan1_endfinal.processed, 1, + "chan1 final_endnodes not called or called multiple times") + self.assertEqual( + chan1_endfail.processed, 0, + "chan1 fail_callback called when nobody ask to him") + self.assertEqual( + chan1_endfail.processed, 0, "chan1 fail_callback called when nobody ask to him") + self.assertEqual( + condchan_end.processed, 0, + "condchan1 final_callback called when nobody ask to him") chan1._reset_test() n3exc.mock(output=raise_exc) excmsg = generate_msg(message_content="exc") with self.assertRaises(Exception): self.loop.run_until_complete(chan1.handle(excmsg)) - self.assertTrue( - chan1_endfail.processed, - "chan1 fail_endnodes not called") - self.assertTrue( - chan1_endfinal.processed, - "chan1 final_endnodes not called") - self.assertFalse( - chan1_endok.processed, + self.assertEqual( + chan1_endfail.processed, 1, + "chan1 fail_endnodes not called or called multiple times") + self.assertEqual( + chan1_endfinal.processed, 1, + "chan1 final_endnodes not called or called multiple times") + self.assertEqual( + chan1_endok.processed, 0, "chan1 ok_callback called when nobody ask to him") + self.assertEqual( + condchan_end.processed, 1, + "condchan1 final_callback not called or called multiple times") def test_casecondchan_endnodes(self): """