def _test_check_infrastructure(self, response, response_text):
        stdout = StringIO()
        stderr = StringIO()
        mock_agent_class = make_mock_agent_class(response)
        self.patch(monitor, 'Agent', mock_agent_class)

        d = monitor.check_infrastructure(self.MOCKURL, stdout, stderr)
        def _check(ign):
            agent = mock_agent_class.agent
            self.failUnlessEqual(agent.method, 'GET')
            self.failUnlessEqual(agent.url, self.MOCKURL)
            self.failUnlessIsInstance(agent.headers, Headers)
            self.failUnlessEqual(agent.pool, None)
            stream = stdout if response.code == 200 else stderr
            self.failUnlessEqual(stream.getvalue(),
                                 "Response for %s: %s" % (self.MOCKURL, response_text))
        d.addCallback(_check)
        return d
def checker(stdout, stderr):
    d = defer.succeed(None)
    for url in URLS_TO_CHECK:
        d.addCallback(lambda ign, url=url: check_infrastructure(url, stdout, stderr))
    return d