def test_get_sever_description(self):
        """Test the get_description method."""
        ai = ActivationInstance(self.config)
        self.patch(ai, 'is_already_running', lambda: False)

        description = yield ai.get_server_description()
        self.assertEqual(description, self.server_description)
示例#2
0
def server_listen(server_factory, service_name, activation_cmdline,
                  description, reactor=None):
    """Connect the IPC server factory."""
    config = ActivationConfig(service_name, activation_cmdline, description)
    ai = ActivationInstance(config)
    description = yield ai.get_server_description()

    if reactor is None:
        from twisted.internet import reactor
    server = endpoints.serverFromString(reactor, description)
    connector = yield server.listen(server_factory)
    defer.returnValue(connector)
    def test_get_description_fails_if_service_already_started(self):
        """The get_description method fails if service already started."""
        server = self.get_server()
        self.addCleanup(server.clean_up)

        class TestConnect(object):
            """A fake connection object."""

            @defer.inlineCallbacks
            def connect(my_self, factory):
                """A fake connection."""
                conn_fact = yield server.connect_client(PortDetectFactory)
                self.patch(factory, 'is_listening', conn_fact.is_listening)
                defer.returnValue(conn_fact)

        self.patch(
            tcpactivation, 'clientFromString', lambda *args: TestConnect())

        yield server.listen_server(protocol.ServerFactory)

        ai = ActivationInstance(self.config)
        yield self.assertFailure(ai.get_server_description(),
                                 AlreadyStartedError)