def test_get_active_description_waits_classwide(self):
     """Test the get_active_description method locks classwide."""
     d = defer.Deferred()
     ac1 = ActivationClient(self.config)
     ac2 = ActivationClient(self.config)
     self.patch(ac1, "_do_get_active_description", lambda: d)
     self.patch(ac2, "_do_get_active_description",
                lambda: defer.succeed(None))
     ac1.get_active_client_description()
     d2 = ac2.get_active_client_description()
     self.assertFalse(d2.called, "The second must wait for the first.")
     d.callback(self.client_description)
     self.assertTrue(d2.called, "The second can fire after the first.")
def ipc_client_connect(client_factory, reactor=None):
    """Connect the IPC client factory."""
    ac = ActivationClient(get_activation_config())

    if reactor is None:
        from twisted.internet import reactor

    description = yield ac.get_active_client_description()
    client = endpoints.clientFromString(reactor, description)
    port = yield client.connect(client_factory)
    defer.returnValue(port)
示例#3
0
def client_connect(client_factory, service_name, activation_cmdline,
                   description, reactor=None):
    """Connect the IPC client factory."""
    config = ActivationConfig(service_name, activation_cmdline, description)
    ac = ActivationClient(config)
    description = yield ac.get_active_client_description()

    if reactor is None:
        from twisted.internet import reactor

    client = endpoints.clientFromString(reactor, description)
    port = yield client.connect(client_factory)
    defer.returnValue(port)
def client_test(config):
    """An IRL test of the client."""
    from twisted.internet import reactor
    print("starting the client.")
    ac = ActivationClient(config)
    d = ac.get_active_client_description()

    def got_description(description):
        """The description was found."""
        print("client got server description:", description)
        reactor.stop()

    d.addCallback(got_description)
    reactor.run()