示例#1
0
    async def test_listen_reads_a_complete_message(self, base_pipeline,
                                                   encoder_app):
        session_app = ClientSessionApp(base_pipeline)
        session_app.reader = asyncio.StreamReader()

        session_app.writer = mock.MagicMock(asyncio.StreamWriter)
        session_app.writer.write = mock.Mock()
        session_app.writer.is_closing = mock.Mock()
        session_app.writer.is_closing.return_value = False

        msg = admin.TestRequestMessage("Test123")
        msg.SendingTime = datetime.utcnow().strftime(
            settings.DATETIME_FORMAT)[:-3]

        encoded_msg = encoder_app.encode_message(msg)

        asyncio.create_task(session_app.listen())
        session_app.reader.feed_data(
            encoded_msg[:-1])  # Feed first part of message

        await asyncio.sleep(0.1)

        session_app.writer.is_closing.return_value = (
            True  # Close listener after this message
        )
        session_app.reader.feed_data(
            encoded_msg[-1:])  # Feed second part of message

        await asyncio.sleep(0.1)

        assert session_app.pipeline.receive.mock_calls[0][1][0] == encoded_msg
示例#2
0
    async def test_send_stop(self, three_level_stop_app_chain):
        with connection_manager() as conn:
            pipeline = BasePipeline(connection_name=conn.name,
                                    installed_apps=three_level_stop_app_chain)

            message = await pipeline.send(admin.TestRequestMessage("Test"))
            assert message.TestReqID == "Test s3"
示例#3
0
    async def test_send_stop(self, three_level_stop_app_chain):
        with connection_manager() as conn:
            pipeline = BasePipeline(connection_name=conn.name,
                                    installed_apps=three_level_stop_app_chain)

            # Simulate all apps active
            pipeline._active_apps = OrderedDict(pipeline.apps.items())

            message = await pipeline.send(admin.TestRequestMessage("Test"))
            assert message.TestReqID == "Test s3"
示例#4
0
    def test_get_send(self, api_app):

        msg = admin.TestRequestMessage("TEST123")
        encoded_msg = encoders.to_json(msg)

        response = api_app.flask_app.post("/send",
                                          data={"message": encoded_msg})

        assert response.status_code == 200

        result = json.loads(response.data)
        assert result["success"] is True
        assert result["message"] == "Successfully added message to pipeline!"
        assert result["data"]["message"] == encoded_msg

        assert (decoders.from_json(result["data"]["message"]) == msg
                )  # Test idempotency while we're at it.
示例#5
0
文件: admin.py 项目: jcass77/WTFIX
    async def send_test_request(self):
        """
        Checks if the server is responding to TestRequest messages.
        """

        self._test_request_id = uuid.uuid4().hex
        logger.warning(
            f"{self.name}: Heartbeat exceeded, sending test request '{self._test_request_id}'..."
        )
        # Don't need to block while request is sent
        asyncio.create_task(
            self.send(admin.TestRequestMessage(utils.encode(self._test_request_id)))
        )

        # Sleep while we wait for a response on the test request
        await asyncio.sleep(self.test_request_response_delay)

        if self.is_waiting():
            self._server_not_responding.set()