Commits

bb b...@gmx.de  committed 3c62c16

factored out _get_new_message; new TC

  • Participants
  • Parent commits 15eff51

Comments (0)

Files changed (2)

File araldo_websocket/endpoints/websocket_endpoint.py

         """
         return "inbound-websocketclient"
 
+    def _get_next_message(self):
+        """ Receive a single message from the WebSocket server
+            and enqueue it
+        """
+        message_str = self._websocket.recv()
+        message = self._marshalling.to_internal_format(message_str)
+        self._logger.debug(
+            "unmarshalled: %s",
+            message)
+        self.gevent_queue.put((self.name(), message))
+
     def _run(self):  # pylint: disable-msg=E0202
         """ Enter infinite gevent loop to receive messages from
             WebSocket server and push it to gevent queue
         """
         while True:
             try:
-                message_str = self._websocket.recv()
-                message = self._marshalling.to_internal_format(message_str)
-                self._logger.debug(
-                    "unmarshalled: %s",
-                    message)
-                self.gevent_queue.put((self.name(), message))
+                self._get_next_message()
             except Exception as error:
                 self._logger.debug(
                     "Unable to unmarshal message; discarding (%s)",

File test/websocket_test.py

 
 def test_outbound_plugin_id(outbound):
     assert outbound.plugin_id() == "outbound-websocketclient"
+
+
+def test_get_next_message(inbound, queue):
+    recv_mock = Mock()
+    recv_mock.return_value = "test_message"
+    with patch.object(inbound._websocket, "recv", recv_mock):
+        inbound._get_next_message()
+        assert recv_mock.called
+        assert queue.qsize() == 1