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 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'
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
|
Loading…
Reference in New Issue