@defer.inlineCallbacks
    def test_reconnecting(self):
        self.runtime_environment.configure()
        cm = self.runtime_environment.configuration_manager
        dm = self.runtime_environment.dependency_manager

        self.create_pb_server()
        cm.set('pb.clients.test_client.endpoint', self.port%'tcp:host=localhost:port=%i')
        cm.set('pipelines.test_pipeline', [{'eval-lambda': {'lambda': 'baton: baton["deferred"].callback("foo")'}}])
        pp = pipeline_provider.PipelineProvider()
        pp.configure(self.runtime_environment)

        self.application.startService()
        self.addCleanup(self.application.stopService)

        client_provider = spread_provider.PBClientProvider()
        client_provider.configure(self.runtime_environment)

        client_factory_dependency = dm.add_dependency(self, dict(provider='pb.client.test_client'))
        client_root_dependency = dm.add_dependency(self, dict(provider='pb.client.test_client.root_object'))
        dm.resolve_initial_states()

        factory = yield client_factory_dependency.wait_for_resource()
        self.assertIsInstance(factory, spread_provider.PipedPBClientFactory)

        # we set the max_delay in order to make the unit test run quicker
        factory.max_delay = 0

        root = yield client_root_dependency.wait_for_resource()
        self.assertIsInstance(root, pb.RemoteReference)

        yield self.server.stopService()

        # trying to use the root object now should result in an exception
        try:
            yield root.callRemote('omg')
        except pb.PBConnectionLost as e:
            pass
        else:
            self.fail('pb.PBConnectionLost was not raised.')

        # the disconnect event will propagate in _this_ reactor iteration, so wait one
        yield util.wait(0)

        # both dependencies should now be unavailable
        self.assertFalse(client_factory_dependency.is_ready)
        self.assertFalse(client_root_dependency.is_ready)

        # start the server again
        yield self.server.startService()

        # wait for the dependencies to become available again
        new_factory = yield client_factory_dependency.wait_for_resource()
        new_root = yield client_root_dependency.wait_for_resource()

        # the same factory object should be used
        self.assertEquals(new_factory, factory)
        # but the root objects differ
        self.assertNotEquals(new_root, root)

        result = yield new_root.callRemote('anything')
        self.assertEquals(result, 'foo')
dataset/ETHPy150Open foundit/Piped/piped/providers/test/test_spread_provider.py/PBClientTest.test_reconnecting/swapped operands of `%`