Add basic tests for the Hosts file implementation in ATS
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/c857fe71 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/c857fe71 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/c857fe71 Branch: refs/heads/master Commit: c857fe719276e3ee9e186e062cba66a7eb35a376 Parents: 0c030e2 Author: Thomas Jackson <[email protected]> Authored: Mon Jul 6 19:50:23 2015 -0700 Committer: Thomas Jackson <[email protected]> Committed: Tue Jul 7 19:19:31 2015 -0700 ---------------------------------------------------------------------- ci/tsqa/tests/test_hostdb.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c857fe71/ci/tsqa/tests/test_hostdb.py ---------------------------------------------------------------------- diff --git a/ci/tsqa/tests/test_hostdb.py b/ci/tsqa/tests/test_hostdb.py index bd5c307..e17d79a 100644 --- a/ci/tsqa/tests/test_hostdb.py +++ b/ci/tsqa/tests/test_hostdb.py @@ -21,6 +21,7 @@ Test hostdb import os import requests import time +import tsqa.test_cases import helpers @@ -86,3 +87,38 @@ class TestHostDBFailedDNS(helpers.EnvironmentCase): self.assertGreater(time.time() - start, self.configs['records.config']['CONFIG']['proxy.config.hostdb.lookup_timeout']) self.assertEqual(ret.status_code, 502) self.assertIn('ATS', ret.headers['server']) + + +class TestHostDBHostsFile(helpers.EnvironmentCase, tsqa.test_cases.HTTPBinCase): + ''' + Tests for hostdb's host-file implementation + ''' + @classmethod + def setUpEnv(cls, env): + hosts_file_path = os.path.join(env.layout.prefix, 'hosts') + with open(hosts_file_path, 'w') as fh: + fh.write('127.0.0.1 local') + + cls.configs['records.config']['CONFIG'].update({ + 'proxy.config.http.response_server_enabled': 2, # only add server headers when there weren't any + 'proxy.config.hostdb.lookup_timeout': 2, + 'proxy.config.url_remap.remap_required': 1, + 'proxy.config.http.connect_attempts_max_retries': 1, + 'proxy.config.hostdb.host_file.interval': 30, + 'proxy.config.hostdb.host_file.path': hosts_file_path, + 'proxy.config.diags.debug.enabled': 1, + 'proxy.config.diags.debug.tags': 'hostdb', + }) + + cls.configs['remap.config'].add_line('map http://local/ http://local:{0}/'.format(cls.http_endpoint.address[1])) + + + def test_basic(self): + # TODO add stat, then wait for the stat to increment + time.sleep(5) # wait for the continuation to load the hosts file + ret = requests.get( + 'http://local/get', + proxies=self.proxies, + ) + self.assertEqual(ret.status_code, 200) + self.assertEqual('127.0.0.1', ret.json()['origin'])
