def test_prepareConnectionReturningADeferred(self):
        """
        The C{prepareConnection} callable returns a deferred and calls to
        L{ClientService.whenConnected} wait until it fires.
        """
        newProtocols = []
        newProtocolDeferred = Deferred()

        def prepareConnection(proto):
            newProtocols.append(proto)
            return newProtocolDeferred

        cq, service = self.makeReconnector(prepareConnection=prepareConnection)

        whenConnectedDeferred = service.whenConnected()
        self.assertNoResult(whenConnectedDeferred)

        newProtocolDeferred.callback(None)

        self.assertIdentical(cq.applicationProtocols[0],
                             self.successResultOf(whenConnectedDeferred))

        The C{prepareConnection} callable returns a deferred and calls to
        L{ClientService.whenConnected} wait until it fires.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/application/test/test_internet.py