Ensure connection is active in graceful shutdown tests
Recent versions of eventlet close idle connections, so just opening a connection is no longer sufficient to trigger graceful shutdown behavior. This change sends a request and adds a delay on the server side so the connection will be active throughout the test. Change-Id: I4e908c1fb1a61d8a57769e2aa85c02a21722367b Closes-Bug: 1788959
This commit is contained in:
parent
a850fda322
commit
2705800cd3
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
import eventlet.wsgi
|
import eventlet.wsgi
|
||||||
import greenlet
|
import greenlet
|
||||||
|
@ -122,10 +123,13 @@ class Server(service.ServiceBase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def run(port_queue, workers=3):
|
def run(port_queue, workers=3, process_time=0):
|
||||||
eventlet.patcher.monkey_patch()
|
eventlet.patcher.monkey_patch()
|
||||||
|
|
||||||
def hi_app(environ, start_response):
|
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')])
|
start_response('200 OK', [('Content-Type', 'application/json')])
|
||||||
yield 'hi'
|
yield 'hi'
|
||||||
|
|
||||||
|
|
|
@ -625,13 +625,19 @@ class EventletServerProcessLauncherTest(base.ServiceBaseTestCase):
|
||||||
|
|
||||||
def run_server(self):
|
def run_server(self):
|
||||||
queue = multiprocessing.Queue()
|
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,
|
proc = multiprocessing.Process(target=eventlet_service.run,
|
||||||
args=(queue,),
|
args=(queue,),
|
||||||
kwargs={'workers': self.workers})
|
kwargs={'workers': self.workers,
|
||||||
|
'process_time': 5})
|
||||||
proc.start()
|
proc.start()
|
||||||
|
|
||||||
port = queue.get()
|
port = queue.get()
|
||||||
conn = socket.create_connection(('127.0.0.1', port))
|
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
|
# 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
|
# the server implementation where it takes some time to set up the
|
||||||
|
@ -660,10 +666,14 @@ class EventletServerProcessLauncherTest(base.ServiceBaseTestCase):
|
||||||
# connected.
|
# connected.
|
||||||
os.kill(proc.pid, signal.SIGTERM)
|
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.
|
# option graceful_shutdown_timeout is not specified.
|
||||||
# we can not wait forever ... so 3 seconds are enough
|
# we can not wait forever ... so 1 second is enough.
|
||||||
time.sleep(3)
|
# 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())
|
self.assertTrue(proc.is_alive())
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue