'L{HTTPConnectionPool.closeCachedConnections} closes all cached
connections and removes them from the cache. It returns a Deferred
that fires when they have all lost their connections.'

def test_closeCachedConnections(self):

    persistent = []
    def addProtocol(scheme, host, port):
        p = HTTP11ClientProtocol()
        p.makeConnection(StringTransport())
        self.pool._putConnection((scheme, host, port), p)
        persistent.append(p)
    addProtocol('http', 'example.com', 80)
    addProtocol('http', 'www2.example.com', 80)
    doneDeferred = self.pool.closeCachedConnections()
    for p in persistent:
        self.assertEqual(p.transport.disconnecting, True)
    self.assertEqual(self.pool._connections, {})
    for dc in self.fakeReactor.getDelayedCalls():
        self.assertEqual(dc.cancelled, True)
    self.assertEqual(self.pool._timeouts, {})
    result = []
    doneDeferred.addCallback(result.append)
    self.assertEqual(result, [])
    persistent[0].connectionLost(Failure(ConnectionDone()))
    self.assertEqual(result, [])
    persistent[1].connectionLost(Failure(ConnectionDone()))
    self.assertEqual(result, [None])
