diff --git a/oslo_service/tests/eventlet_service.py b/oslo_service/tests/eventlet_service.py index 687fb56b..a68642a8 100644 --- a/oslo_service/tests/eventlet_service.py +++ b/oslo_service/tests/eventlet_service.py @@ -17,6 +17,7 @@ import socket import sys +import time import eventlet.wsgi import greenlet @@ -122,10 +123,13 @@ class Server(service.ServiceBase): pass -def run(port_queue, workers=3): +def run(port_queue, workers=3, process_time=0): eventlet.patcher.monkey_patch() def hi_app(environ, start_response): + # Some requests need to take time to process so the connection + # remains active. + time.sleep(process_time) start_response('200 OK', [('Content-Type', 'application/json')]) yield 'hi' diff --git a/oslo_service/tests/test_service.py b/oslo_service/tests/test_service.py index 0114eb58..7c616000 100644 --- a/oslo_service/tests/test_service.py +++ b/oslo_service/tests/test_service.py @@ -625,13 +625,19 @@ class EventletServerProcessLauncherTest(base.ServiceBaseTestCase): def run_server(self): queue = multiprocessing.Queue() + # NOTE(bnemec): process_time of 5 needs to be longer than the graceful + # shutdown timeout in the "exceeded" test below, but also needs to be + # shorter than the timeout in the regular graceful shutdown test. proc = multiprocessing.Process(target=eventlet_service.run, args=(queue,), - kwargs={'workers': self.workers}) + kwargs={'workers': self.workers, + 'process_time': 5}) proc.start() port = queue.get() conn = socket.create_connection(('127.0.0.1', port)) + # Send request to make the connection active. + conn.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n') # NOTE(blk-u): The sleep shouldn't be necessary. There must be a bug in # the server implementation where it takes some time to set up the @@ -660,10 +666,14 @@ class EventletServerProcessLauncherTest(base.ServiceBaseTestCase): # connected. os.kill(proc.pid, signal.SIGTERM) - # server with graceful shutdown must wait forewer if + # server with graceful shutdown must wait forever if # option graceful_shutdown_timeout is not specified. - # we can not wait forever ... so 3 seconds are enough - time.sleep(3) + # we can not wait forever ... so 1 second is enough. + # NOTE(bnemec): In newer versions of eventlet that drop idle + # connections, this needs to be long enough to allow the signal + # handler to fire but short enough that our request doesn't complete + # or the connection will be closed and the server will stop. + time.sleep(1) self.assertTrue(proc.is_alive())