Skip to content

Commit

Permalink
Avoid DNS lookups for localhost as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
jerith committed Feb 24, 2014
1 parent 36e652a commit 6f3a79a
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion vumi/application/tests/test_rapidsms_relay.py
Expand Up @@ -129,7 +129,7 @@ def cb(request):
def _call_relay(self, data, auth=None):
data = json.dumps(data)
host = self.app.web_resource.getHost()
send_url = "http://localhost:%d/send" % (host.port,)
send_url = "http://127.0.0.1:%d/send" % (host.port,)
headers = {}
if auth is not None:
headers['Authorization'] = basic_auth_string(*auth)
Expand Down
2 changes: 1 addition & 1 deletion vumi/blinkenlights/tests/test_metrics_workers.py
Expand Up @@ -316,7 +316,7 @@ def setUp(self):
self.add_cleanup(self.udp_server.stopListening)
self.worker = yield self.worker_helper.get_worker(
metrics_workers.UDPMetricsCollector, {
'metrics_host': 'localhost',
'metrics_host': '127.0.0.1',
'metrics_port': self.udp_server.getHost().port,
})

Expand Down
2 changes: 1 addition & 1 deletion vumi/persist/txredis_manager.py
Expand Up @@ -136,7 +136,7 @@ def _manager_from_config(cls, client_config, manager_config):
Key prefix for namespacing.
"""

host = client_config.pop('host', 'localhost')
host = client_config.pop('host', '127.0.0.1')
port = client_config.pop('port', 6379)

factory = VumiRedisClientFactory(**client_config)
Expand Down
2 changes: 1 addition & 1 deletion vumi/service.py
Expand Up @@ -385,7 +385,7 @@ def list_bindings(self):
# which may lead to errors if the RabbitMQ Management REST api
# changes
resp = yield http_request(
"http://localhost:55672/api/bindings", headers={
"http://127.0.0.1:55672/api/bindings", headers={
'Authorization': basic_auth_string(
self.vumi_options['username'],
self.vumi_options['password']),
Expand Down
24 changes: 12 additions & 12 deletions vumi/tests/test_config.py
Expand Up @@ -389,12 +389,12 @@ def test_server_endpoint_field(self):
field, config={'port': 80}),
TCP4ServerEndpoint, interface='', port=80)
self.check_endpoint(self.field_value(
field, config={'host': 'localhost', 'port': 80}),
TCP4ServerEndpoint, interface='localhost', port=80)
field, config={'host': '127.0.0.1', 'port': 80}),
TCP4ServerEndpoint, interface='127.0.0.1', port=80)

self.assertEqual(self.field_value(field), None)

self.assert_field_invalid(field, config={'host': 'localhost'})
self.assert_field_invalid(field, config={'host': '127.0.0.1'})
self.assert_field_invalid(field, 'foo')

def test_server_endpoint_field_required(self):
Expand All @@ -414,13 +414,13 @@ def test_client_endpoint_field(self):
self.field_value(field, 'tcp:127.0.0.1:60'),
TCP4ClientEndpoint, host='127.0.0.1', port=60)
self.check_endpoint(self.field_value(
field, config={'host': 'localhost', 'port': 80}),
TCP4ClientEndpoint, host='localhost', port=80)
field, config={'host': '127.0.0.1', 'port': 80}),
TCP4ClientEndpoint, host='127.0.0.1', port=80)

self.assertEqual(self.field_value(field), None)

self.assert_field_invalid(field, config={'port': 80})
self.assert_field_invalid(field, config={'host': 'localhost'})
self.assert_field_invalid(field, config={'host': '127.0.0.1'})
self.assert_field_invalid(field, 'foo')

def test_client_endpoint_field_required(self):
Expand All @@ -429,19 +429,19 @@ def test_client_endpoint_field_required(self):
self.field_value(field, 'tcp:127.0.0.1:60'),
TCP4ClientEndpoint, host='127.0.0.1', port=60)
self.check_endpoint(self.field_value(
field, config={'host': 'localhost', 'port': 80}),
TCP4ClientEndpoint, host='localhost', port=80)
field, config={'host': '127.0.0.1', 'port': 80}),
TCP4ClientEndpoint, host='127.0.0.1', port=80)

self.assert_field_invalid(field)

def test_client_endpoint_field_with_port_fallback(self):
field = self.make_field(
ConfigClientEndpoint, port_fallback_default=51)
self.check_endpoint(
self.field_value(field, config={'host': 'localhost'}),
TCP4ClientEndpoint, host='localhost', port=51)
self.field_value(field, config={'host': '127.0.0.1'}),
TCP4ClientEndpoint, host='127.0.0.1', port=51)
self.check_endpoint(self.field_value(
field, config={'host': 'localhost', 'port': 80}),
TCP4ClientEndpoint, host='localhost', port=80)
field, config={'host': '127.0.0.1', 'port': 80}),
TCP4ClientEndpoint, host='127.0.0.1', port=80)

self.assert_field_invalid(field, config={'port': 80})
2 changes: 1 addition & 1 deletion vumi/tests/test_service.py
Expand Up @@ -67,7 +67,7 @@ def _connect(self, *_args, **_kw):
class TestWorkerCreator(VumiTestCase):
def get_creator(self, **options):
vumi_options = {
"hostname": "localhost",
"hostname": "127.0.0.1",
"port": 5672,
"username": "vumitest",
"password": "vumitest",
Expand Down
2 changes: 1 addition & 1 deletion vumi/transports/irc/tests/test_irc.py
Expand Up @@ -172,7 +172,7 @@ def test_alter_collided_nick(self):


class StubbyIrcServerProtocol(IRC):
hostname = 'localhost'
hostname = '127.0.0.1'

def irc_unknown(self, prefix, command, params):
self.factory.events.put((prefix, command, params))
Expand Down
2 changes: 1 addition & 1 deletion vumi/transports/mtech_ussd/tests/test_mtech_ussd.py
Expand Up @@ -16,7 +16,7 @@ def setUp(self):
'transport_type': 'ussd',
'ussd_string_prefix': '*120*666#',
'web_path': "/foo",
'web_host': "localhost",
'web_host': "127.0.0.1",
'web_port': 0,
'username': 'testuser',
'password': 'testpass',
Expand Down
2 changes: 1 addition & 1 deletion vumi/transports/parlayx/tests/test_parlayx.py
Expand Up @@ -73,7 +73,7 @@ def setUp(self):
'remote_notification_uri': 'notification_uri',
}
self.tx_helper = self.add_helper(TransportHelper(ParlayXTransport))
self.uri = 'http://localhost:%s%s' % (
self.uri = 'http://127.0.0.1:%s%s' % (
self.port, config['web_notification_path'])

def _create_client(transport, config):
Expand Down
Expand Up @@ -562,7 +562,7 @@ class TestESME(VumiTestCase):
def setUp(self):
config = SmppTransportConfig({
"transport_name": "transport_name",
"host": 'localhost',
"host": '127.0.0.1',
"port": 2775,
"system_id": 'test_system',
"password": 'password',
Expand Down
8 changes: 4 additions & 4 deletions vumi/transports/smpp/deprecated/tests/test_smpp.py
Expand Up @@ -25,7 +25,7 @@ class TestSmppTransportConfig(VumiTestCase):
def required_config(self, config_params):
config = {
"transport_name": "my_transport",
"twisted_endpoint": "tcp:host=localhost:port=0",
"twisted_endpoint": "tcp:host=127.0.0.1:port=0",
"system_id": "vumitest-vumitest-vumitest",
"password": "password",
}
Expand Down Expand Up @@ -70,7 +70,7 @@ class TestSmppTransport(VumiTestCase):
def setUp(self):
config = {
"system_id": "vumitest-vumitest-vumitest",
"twisted_endpoint": "tcp:host=localhost:port=0",
"twisted_endpoint": "tcp:host=127.0.0.1:port=0",
"password": "password",
"smpp_bind_timeout": 12,
"smpp_enquire_link_interval": 123,
Expand Down Expand Up @@ -835,7 +835,7 @@ def setUp(self):
"transport_name": self.tx_helper.transport_name,
"system_id": "VumiTestSMSC",
"password": "password",
"host": "localhost",
"host": "127.0.0.1",
"port": 0,
"transport_type": "smpp",
}
Expand Down Expand Up @@ -904,7 +904,7 @@ def setUp(self):
"transport_name": self.tx_helper.transport_name,
"system_id": "VumiTestSMSC",
"password": "password",
"host": "localhost",
"host": "127.0.0.1",
"port": 0,
"transport_type": "smpp",
}
Expand Down
2 changes: 1 addition & 1 deletion vumi/transports/smpp/tests/test_protocol.py
Expand Up @@ -107,7 +107,7 @@ def get_protocol(self, config={},

default_config = {
'transport_name': 'sphex_transport',
'twisted_endpoint': 'tcp:host=localhost:port=0',
'twisted_endpoint': 'tcp:host=127.0.0.1:port=0',
'deliver_short_message_processor': (
'vumi.transports.smpp.processors.'
'DeliverShortMessageProcessor'),
Expand Down
2 changes: 1 addition & 1 deletion vumi/transports/vas2nets/tests/test_failures.py
Expand Up @@ -145,7 +145,7 @@ def test_send_sms_noconn(self):
"""
# TODO: Figure out a solution that doesn't require hoping that
# nothing's listening on this port.
self.worker.config['url'] = 'http://localhost:9999/'
self.worker.config['url'] = 'http://127.0.0.1:9999/'

self.worker.failure_published = FailureCounter(1)
msg = self.make_outbound("outbound")
Expand Down
2 changes: 1 addition & 1 deletion vumi/transports/vas2nets/tests/test_vas2nets.py
Expand Up @@ -284,7 +284,7 @@ def test_send_sms_fail(self):
def test_send_sms_noconn(self):
# TODO: Figure out a solution that doesn't require hoping that
# nothing's listening on this port.
self.transport.config['url'] = 'http://localhost:9999/'
self.transport.config['url'] = 'http://127.0.0.1:9999/'
msg = yield self.make_dispatch_outbound("hello")

[twisted_failure] = self.flushLoggedErrors(TemporaryFailure)
Expand Down
6 changes: 3 additions & 3 deletions vumi/transports/vas2nets/tests/test_vas2nets_stubs.py
Expand Up @@ -80,7 +80,7 @@ def setUp(self):
'web_port': 9999,
'web_receive_path': '/t/receive',
'web_receipt_path': '/t/receipt',
'url': 'http://localhost:9998/t/send',
'url': 'http://127.0.0.1:9998/t/send',
}
self.worker = yield self.worker_helper.get_worker(
StubbedFakeVas2NetsWorker, self.config, start=False)
Expand All @@ -98,7 +98,7 @@ def render_request(self, resource, request):

@inlineCallbacks
def test_receive_sent_sms(self):
resource = FakeVas2NetsHandler('http://localhost:9999/t/receipt', (0,))
resource = FakeVas2NetsHandler('http://127.0.0.1:9999/t/receipt', (0,))
resource.schedule_delivery = lambda *a: None

request = create_request({
Expand All @@ -121,7 +121,7 @@ def test_receive_sent_sms(self):

@inlineCallbacks
def test_deliver_receipt(self):
resource = FakeVas2NetsHandler('http://localhost:9999/t/receipt', (0,))
resource = FakeVas2NetsHandler('http://127.0.0.1:9999/t/receipt', (0,))
yield self.test_worker.startWorker()

yield resource.deliver_receipt('smsid', 'msgid', 'provider', 'sender')
Expand Down
2 changes: 1 addition & 1 deletion vumi/transports/vas2nets/transport_stubs.py
Expand Up @@ -129,7 +129,7 @@ class FakeVas2NetsWorker(Worker):
@inlineCallbacks
def startWorker(self):
url = urlparse(self.config.get('url'))
receipt_url = "http://localhost:%s%s" % (
receipt_url = "http://127.0.0.1:%s%s" % (
self.config.get('web_port'), self.config.get('web_receipt_path'))

self.receipt_resource = yield self.start_web_resources(
Expand Down
Expand Up @@ -19,7 +19,7 @@ def setUp(self):
'transport_type': 'ussd',
'ussd_string_prefix': '*120*666#',
'web_path': "/foo",
'web_host': "localhost",
'web_host': "127.0.0.1",
'web_port': 0,
'username': 'testuser',
'password': 'testpass',
Expand Down Expand Up @@ -56,7 +56,7 @@ def test_inbound_new_continue(self):
response = yield d
correct_response = '<request>\n\t<headertext>OK</headertext>\n\t' \
'<options>\n\t\t<option command="1" order="1" ' \
'callback="http://localhost/foo" display="False" >' \
'callback="http://127.0.0.1/foo" display="False" >' \
'</option>\n\t</options>\n</request>'
self.assertEqual(response, correct_response)

Expand Down Expand Up @@ -86,7 +86,7 @@ def test_inbound_resume_continue(self):
response = yield d
correct_response = '<request>\n\t<headertext>OK</headertext>\n\t' \
'<options>\n\t\t<option command="1" order="1" ' \
'callback="http://localhost/foo" display="False" >' \
'callback="http://127.0.0.1/foo" display="False" >' \
'</option>\n\t</options>\n</request>'
self.assertEqual(response, correct_response)

Expand Down

0 comments on commit 6f3a79a

Please sign in to comment.