コード例 #1
0
    def test_dns_resolve(self):
        old = util.gethostbyname

        def _gethost(*args):
            return '0.0.0.0'

        util.gethostbyname = _gethost

        try:
            res = dns_resolve('http://example.com')
            res2 = dns_resolve('http://example.com')  # cache
        finally:
            util.gethostbyname = old

        self.assertEqual(res, ('http://0.0.0.0:80', 'example.com', '0.0.0.0'))
        self.assertEqual(res, res2)
コード例 #2
0
ファイル: test_util.py プロジェクト: edmoz/loads
    def test_dns_resolve(self):
        old = util.gethostbyname

        def _gethost(*args):
            return '0.0.0.0'

        util.gethostbyname = _gethost

        try:
            res = dns_resolve('http://example.com')
            res2 = dns_resolve('http://example.com')   # cache
        finally:
            util.gethostbyname = old

        self.assertEqual(res, ('http://0.0.0.0:80', 'example.com', '0.0.0.0'))
        self.assertEqual(res, res2)
コード例 #3
0
ファイル: measure.py プロジェクト: Awingu/loads
 def request(self, method, url, headers=None, **kwargs):
     if not url.startswith('https://') and self.dns_resolve:
         url, original, resolved = dns_resolve(url)
         if headers is None:
             headers = {}
         headers['Host'] = original
     return super(Session, self).request(
         method, url, headers=headers, **kwargs)
コード例 #4
0
ファイル: measure.py プロジェクト: kayoung1222/KorStock
 def request(self, method, url, headers=None, **kwargs):
     if not url.startswith('https://'):
         url, original, resolved = dns_resolve(url)
         if headers is None:
             headers = {}
         headers['Host'] = original
     return super(Session, self).request(
         method, url, headers=headers, **kwargs)
コード例 #5
0
 def test_dns_resolve_fallbacks_on_gethostbyname(self, hostbyname,
                                                 hostbyname_ex):
     # Older versions of gevent don't have the gethostbyname_ex method. Be
     # sure we fallback on the right version if the method doesn't exist.
     hostbyname_ex.side_effect = AttributeError()
     hostbyname.return_value = '0.0.0.0'
     self.assertEquals(dns_resolve('http://mozilla.org'),
                       ('http://0.0.0.0:80', 'mozilla.org', '0.0.0.0'))
     self.assertTrue(hostbyname.called)
コード例 #6
0
ファイル: test_util.py プロジェクト: strategist922/loads
 def test_dns_resolve_fallbacks_on_gethostbyname(self, hostbyname,
                                                 hostbyname_ex):
     # Older versions of gevent don't have the gethostbyname_ex method. Be
     # sure we fallback on the right version if the method doesn't exist.
     hostbyname_ex.side_effect = AttributeError()
     hostbyname.return_value = '0.0.0.0'
     self.assertEquals(dns_resolve(
         'http://mozilla.org'),
         ('http://0.0.0.0:80', 'mozilla.org', '0.0.0.0'))
     self.assertTrue(hostbyname.called)
コード例 #7
0
ファイル: test_util.py プロジェクト: strategist922/loads
    def test_dns_resolve(self):
        with mock.patch('loads.util.gevent_socket.gethostbyname_ex') as mocked:
            mocked.return_value = ('example.com', ['example.com'],
                                   ['0.0.0.0', '1.1.1.1'])

            # Initial query should populate the cache and return
            # randomly-selected resolved address.
            url, original, resolved = dns_resolve('http://example.com')
            self.assertEqual(original, 'example.com')
            self.assertEqual(url, 'http://' + resolved + ':80')
            self.assertTrue(resolved in ("0.0.0.0", "1.1.1.1"))
            self.assertEqual(mocked.call_count, 1)
            # Subsequent queries should be fulfilled from the cache
            # and should balance between all resolved addresses.
            addrs = set()
            for _ in xrange(10):
                addrs.add(dns_resolve('http://example.com')[2])
            self.assertEqual(addrs, set(('0.0.0.0', '1.1.1.1')))
            self.assertEqual(mocked.call_count, 1)
コード例 #8
0
    def test_dns_resolve(self):
        with mock.patch('loads.util.gevent_socket.gethostbyname_ex') as mocked:
            mocked.return_value = ('example.com', ['example.com'],
                                   ['0.0.0.0', '1.1.1.1'])

            # Initial query should populate the cache and return
            # randomly-selected resolved address.
            url, original, resolved = dns_resolve('http://example.com')
            self.assertEqual(original, 'example.com')
            self.assertEqual(url, 'http://' + resolved + ':80')
            self.assertTrue(resolved in ("0.0.0.0", "1.1.1.1"))
            self.assertEqual(mocked.call_count, 1)
            # Subsequent queries should be fulfilled from the cache
            # and should balance between all resolved addresses.
            addrs = set()
            for _ in xrange(10):
                addrs.add(dns_resolve('http://example.com')[2])
            self.assertEqual(addrs, set(('0.0.0.0', '1.1.1.1')))
            self.assertEqual(mocked.call_count, 1)
コード例 #9
0
ファイル: measure.py プロジェクト: edmoz/loads
    def send(self, request, **kwargs):
        """Do the actual request from within the session, doing some
        measures at the same time about the request (duration, status, etc).
        """
        request.url, original, resolved = dns_resolve(request.url)
        request.headers['Host'] = original

        # attach some information to the request object for later use.
        start = datetime.datetime.utcnow()
        res = _Session.send(self, request, **kwargs)
        res.started = start
        res.method = request.method
        self._analyse_request(res)
        return res
コード例 #10
0
    def send(self, request, **kwargs):
        """Do the actual request from within the session, doing some
        measures at the same time about the request (duration, status, etc).
        """
        if not request.url.startswith('https://'):
            request.url, original, resolved = dns_resolve(request.url)
            request.headers['Host'] = original

        # attach some information to the request object for later use.
        start = datetime.datetime.utcnow()
        res = _Session.send(self, request, **kwargs)
        res.started = start
        res.method = request.method
        self._analyse_request(res)
        return res