Browse Source

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
Ben Nemec 7 months ago
parent
commit
2705800cd3
2 changed files with 19 additions and 5 deletions
  1. 5
    1
      oslo_service/tests/eventlet_service.py
  2. 14
    4
      oslo_service/tests/test_service.py

+ 5
- 1
oslo_service/tests/eventlet_service.py View File

@@ -17,6 +17,7 @@
17 17
 
18 18
 import socket
19 19
 import sys
20
+import time
20 21
 
21 22
 import eventlet.wsgi
22 23
 import greenlet
@@ -122,10 +123,13 @@ class Server(service.ServiceBase):
122 123
             pass
123 124
 
124 125
 
125
-def run(port_queue, workers=3):
126
+def run(port_queue, workers=3, process_time=0):
126 127
     eventlet.patcher.monkey_patch()
127 128
 
128 129
     def hi_app(environ, start_response):
130
+        # Some requests need to take time to process so the connection
131
+        # remains active.
132
+        time.sleep(process_time)
129 133
         start_response('200 OK', [('Content-Type', 'application/json')])
130 134
         yield 'hi'
131 135
 

+ 14
- 4
oslo_service/tests/test_service.py View File

@@ -625,13 +625,19 @@ class EventletServerProcessLauncherTest(base.ServiceBaseTestCase):
625 625
 
626 626
     def run_server(self):
627 627
         queue = multiprocessing.Queue()
628
+        # NOTE(bnemec): process_time of 5 needs to be longer than the graceful
629
+        # shutdown timeout in the "exceeded" test below, but also needs to be
630
+        # shorter than the timeout in the regular graceful shutdown test.
628 631
         proc = multiprocessing.Process(target=eventlet_service.run,
629 632
                                        args=(queue,),
630
-                                       kwargs={'workers': self.workers})
633
+                                       kwargs={'workers': self.workers,
634
+                                               'process_time': 5})
631 635
         proc.start()
632 636
 
633 637
         port = queue.get()
634 638
         conn = socket.create_connection(('127.0.0.1', port))
639
+        # Send request to make the connection active.
640
+        conn.sendall(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
635 641
 
636 642
         # NOTE(blk-u): The sleep shouldn't be necessary. There must be a bug in
637 643
         # the server implementation where it takes some time to set up the
@@ -660,10 +666,14 @@ class EventletServerProcessLauncherTest(base.ServiceBaseTestCase):
660 666
         # connected.
661 667
         os.kill(proc.pid, signal.SIGTERM)
662 668
 
663
-        # server with graceful shutdown must wait forewer if
669
+        # server with graceful shutdown must wait forever if
664 670
         # option graceful_shutdown_timeout is not specified.
665
-        # we can not wait forever ... so 3 seconds are enough
666
-        time.sleep(3)
671
+        # we can not wait forever ... so 1 second is enough.
672
+        # NOTE(bnemec): In newer versions of eventlet that drop idle
673
+        # connections, this needs to be long enough to allow the signal
674
+        # handler to fire but short enough that our request doesn't complete
675
+        # or the connection will be closed and the server will stop.
676
+        time.sleep(1)
667 677
 
668 678
         self.assertTrue(proc.is_alive())
669 679
 

Loading…
Cancel
Save