]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2855] Notify on the socket if a response is ready
authorMukund Sivaraman <muks@isc.org>
Thu, 27 Jun 2013 01:59:16 +0000 (07:29 +0530)
committerMukund Sivaraman <muks@isc.org>
Sun, 30 Jun 2013 15:57:29 +0000 (21:27 +0530)
src/lib/python/isc/memmgr/builder.py
src/lib/python/isc/memmgr/tests/builder_tests.py

index 6b1b19347fa6cdf8d38d06b54ecb26485f65e0e9..ae38f1eb4ab33004adefb2da15436ebb6455d121 100644 (file)
@@ -92,9 +92,13 @@ class MemorySegmentBuilder:
                         # queue.
                         with self._lock:
                             self._response_queue.append(('bad_command',))
-                        # In this case, we do not notify the main
-                        # thread about a response on the socket, as
-                        # we quit the main loop here anyway (and any
-                        # enclosing thread).
+
                         self._shutdown = True
                         break
+
+                # Notify (any main thread) on the socket about a
+                # response. Otherwise, the main thread may wait in its
+                # loop without knowing there was a problem.
+                if len(self._response_queue) > 0:
+                    while self._sock.send(b'x') != 1:
+                        continue
index 4234b9166c839d27526faa062986fcc9492e240f..1fae17928ebda55864d87faf04aecdcb9ef0d0ea 100644 (file)
@@ -15,6 +15,7 @@
 
 import unittest
 import socket
+import select
 import threading
 
 import isc.log
@@ -63,6 +64,17 @@ class TestMemorySegmentBuilder(unittest.TestCase):
                 self._builder_command_queue.append('bad_command')
             self._builder_cv.notify_all()
 
+        # Wait 5 seconds to receive a notification on the socket from
+        # the builder.
+        (reads, _, _) = select.select([self._master_sock], [], [], 5)
+        self.assertTrue(self._master_sock in reads)
+
+        # Reading 1 byte should not block us here, especially as the
+        # socket is ready to read. It's a hack, but this is just a
+        # testcase.
+        got = self._master_sock.recv(1)
+        self.assertEqual(got, b'x')
+
         # Wait 5 seconds at most for the main loop of the builder to
         # exit.
         self._builder_thread.join(5)