wait for proxy to exit in test_external_proxy

.terminate() only sends the signal,
it doesn't wait for the process to exit.

If the process doesn't exit promptly,
the next instance may try to grab the port before the previous process has released it,
causing failure with EADDRINUSE.
This commit is contained in:
Min RK
2017-11-29 15:22:45 +01:00
parent ee76772e1b
commit cb9f356a69

View File

@@ -66,6 +66,7 @@ def test_external_proxy(request):
def _cleanup_proxy(): def _cleanup_proxy():
if proxy.poll() is None: if proxy.poll() is None:
proxy.terminate() proxy.terminate()
proxy.wait(timeout=10)
request.addfinalizer(_cleanup_proxy) request.addfinalizer(_cleanup_proxy)
def wait_for_proxy(): def wait_for_proxy():
@@ -95,16 +96,17 @@ def test_external_proxy(request):
host = '%s.%s' % (name, urlparse(app.subdomain_host).hostname) host = '%s.%s' % (name, urlparse(app.subdomain_host).hostname)
user_spec = host + user_path user_spec = host + user_path
assert sorted(routes.keys()) == ['/', user_spec] assert sorted(routes.keys()) == ['/', user_spec]
# teardown the proxy and start a new one in the same place # teardown the proxy and start a new one in the same place
proxy.terminate() proxy.terminate()
proxy.wait(timeout=10)
proxy = Popen(cmd, env=env) proxy = Popen(cmd, env=env)
yield wait_for_proxy() yield wait_for_proxy()
routes = yield app.proxy.get_all_routes() routes = yield app.proxy.get_all_routes()
assert list(routes.keys()) == [] assert list(routes.keys()) == []
# poke the server to update the proxy # poke the server to update the proxy
r = yield api_request(app, 'proxy', method='post') r = yield api_request(app, 'proxy', method='post')
r.raise_for_status() r.raise_for_status()
@@ -115,6 +117,7 @@ def test_external_proxy(request):
# teardown the proxy, and start a new one with different auth and port # teardown the proxy, and start a new one with different auth and port
proxy.terminate() proxy.terminate()
proxy.wait(timeout=10)
new_auth_token = 'different!' new_auth_token = 'different!'
env['CONFIGPROXY_AUTH_TOKEN'] = new_auth_token env['CONFIGPROXY_AUTH_TOKEN'] = new_auth_token
proxy_port = 55432 proxy_port = 55432