def test_prepareConnectionCalledAfterConnectionMade(self):
        """
        The C{prepareConnection} callback is invoked only once a connection is
        made.
        """
        prepares = [0]

        def prepareConnection(_proto):
            prepares[0] += 1

        clock = Clock()
        cq, service = self.makeReconnector(prepareConnection=prepareConnection,
                                           fireImmediately=False,
                                           clock=clock)

        cq.connectQueue[0].errback(Exception('connection attempt failed'))
        self.assertEqual(0, prepares[0])  # Not called yet.

        clock.advance(AT_LEAST_ONE_ATTEMPT)
        cq.connectQueue[1].callback(None)

        self.assertEqual(1, prepares[0])  # Was called.

        The C{prepareConnection} callback is invoked only once a connection is
        made.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/application/test/test_internet.py