def test_channel_events(self): """ Whether BaseChannel handling return a good result """ chan = BaseChannel(name="test_channel7.5", loop=self.loop) msg = generate_msg() chan.add(nodes.JsonToPython(), nodes.PythonToJson()) state_sequence = [chan.status] @events.channel_change_state.receiver def handle_change_state(channel=None, old_state=None, new_state=None): print(channel.name, old_state, new_state) state_sequence.append(new_state) @events.channel_change_state.receiver async def handle_change_state_async(channel=None, old_state=None, new_state=None): print(channel.name, old_state, new_state) # Launch channel processing self.start_channels() self.loop.run_until_complete(chan.handle(msg)) self.loop.run_until_complete(chan.stop()) print(state_sequence) valid_sequence = [BaseChannel.STOPPED, BaseChannel.STARTING, BaseChannel.WAITING, BaseChannel.PROCESSING, BaseChannel.WAITING, BaseChannel.STOPPING, BaseChannel.STOPPED] self.assertEqual(state_sequence, valid_sequence, "Sequence state is not valid")
def test_channel_stopped_dont_process_message(self): """ Whether BaseChannel handling return a good result """ chan = BaseChannel(name="test_channel7.7", loop=self.loop) msg = generate_msg() chan.add(nodes.JsonToPython(), nodes.PythonToJson()) # Launch channel processing self.start_channels() self.loop.run_until_complete(chan.handle(msg)) self.loop.run_until_complete(chan.stop()) with self.assertRaises(channels.ChannelStopped) as cm: self.loop.run_until_complete(chan.handle(msg))