def test_process_does_not_block(self):
        mock_socket = Mock()
        mock_socket.recv_unicode.side_effect = zmq.Again()

        server = ControlServer(None, connection_string="127.0.0.1:10000")
        server._socket = mock_socket
        assertRaisesNothing(self, server.process)

        mock_socket.recv_unicode.assert_has_calls([call(flags=zmq.NOBLOCK)])
Ejemplo n.º 2
0
    def test_connection(self, mock_context):
        cs = ControlServer(None, connection_string='127.0.0.1:10001')
        cs.start_server()

        mock_context.assert_has_calls([
            call(),
            call().socket(zmq.REP),
            call().socket().bind('tcp://127.0.0.1:10001')
        ])
    def test_connection(self, mock_context):
        cs = ControlServer(None, connection_string="127.0.0.1:10001")
        cs.start_server()

        mock_context.assert_has_calls([
            call(),
            call().socket(zmq.REP),
            call().socket().setsockopt(zmq.RCVTIMEO, 100),
            call().socket().bind("tcp://127.0.0.1:10001"),
        ])
Ejemplo n.º 4
0
    def test_server_can_only_be_started_once(self, mock_context):
        server = ControlServer(None, connection_string='127.0.0.1:10000')
        server.start_server()
        server.start_server()

        mock_context.assert_has_calls([
            call(),
            call().socket(zmq.REP),
            call().socket().bind('tcp://127.0.0.1:10000')
        ])
    def test_server_can_only_be_started_once(self, mock_context):
        server = ControlServer(None, connection_string="127.0.0.1:10000")
        server.start_server()
        server.start_server()

        mock_context.assert_has_calls([
            call(),
            call().socket(zmq.REP),
            call().socket().setsockopt(zmq.RCVTIMEO, 100),
            call().socket().bind("tcp://127.0.0.1:10000"),
        ])
Ejemplo n.º 6
0
    def _create_control_server(self, control_server):
        if control_server is None:
            return None

        return ControlServer(
            {
                "device":
                ExposedObject(
                    self._device,
                    exclude_inherited=True,
                    lock=self._adapters.device_lock,
                ),
                "simulation":
                ExposedObject(
                    self,
                    exclude=("start", "control_server", "log"),
                    exclude_inherited=True,
                ),
                "interface":
                ExposedObject(
                    self._adapters,
                    exclude=(
                        "device_lock",
                        "add_adapter",
                        "remove_adapter",
                        "handle",
                        "log",
                    ),
                    exclude_inherited=True,
                ),
            },
            control_server,
        )
    def _create_control_server(self, control_server):
        if control_server is None:
            return None

        return ControlServer(
            {
                'device':
                self._device,
                'simulation':
                ExposedObject(self, exclude=('start', 'control_server'))
            }, control_server)
Ejemplo n.º 8
0
    def _create_control_server(self, control_server):
        if control_server is None:
            return None

        return ControlServer(
            {
                'device':
                ExposedObject(self._device,
                              exclude_inherited=True,
                              lock=self._adapters.device_lock),
                'simulation':
                ExposedObject(self,
                              exclude=('start', 'control_server', 'log'),
                              exclude_inherited=True),
                'interface':
                ExposedObject(self._adapters,
                              exclude=('device_lock', 'add_adapter',
                                       'remove_adapter', 'handle', 'log'),
                              exclude_inherited=True)
            }, control_server)
 def test_is_running(self, mock_context):
     server = ControlServer(None, connection_string="127.0.0.1:10000")
     self.assertFalse(server.is_running)
     server.start_server()
     self.assertTrue(server.is_running)
Ejemplo n.º 10
0
    def test_exposed_object_collection_is_constructed(self,
                                                      exposed_object_mock):
        ControlServer(object_map="test", connection_string="127.0.0.1:10000")

        exposed_object_mock.assert_called_once_with("test")
Ejemplo n.º 11
0
    def test_exposed_object_is_exposed_directly(self):
        mock_collection = Mock(spec=ExposedObject)

        server = ControlServer(object_map=mock_collection,
                               connection_string="127.0.0.1:10000")
        self.assertEqual(server.exposed_object, mock_collection)
Ejemplo n.º 12
0
    def test_process_raises_if_not_started(self):
        server = ControlServer(None, connection_string="127.0.0.1:10000")

        self.assertRaises(Exception, server.process)