Rev 3390: Add optional thread_name_suffix parameter to in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Apr 29 16:51:51 BST 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3390
revision-id:pqm at pqm.ubuntu.com-20080429155137-0w5littcl831pq4m
parent: pqm at pqm.ubuntu.com-20080429014232-4b86ax5pwynnf11i
parent: andrew.bennetts at canonical.com-20080429134340-c5ef1fxrptoynikx
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2008-04-29 16:51:37 +0100
message:
  Add optional thread_name_suffix parameter to
  	SmartTCPServer_for_testing. (Andrew Bennetts)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/smart/server.py         server.py-20061110062051-chzu10y32vx8gvur-1
  bzrlib/tests/test_smart.py     test_smart.py-20061122024551-ol0l0o0oofsu9b3t-2
    ------------------------------------------------------------
    revno: 3386.1.1
    revision-id:andrew.bennetts at canonical.com-20080429134340-c5ef1fxrptoynikx
    parent: pqm at pqm.ubuntu.com-20080428083317-x033hd0yn73mqaj7
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: thread-name-suffix
    timestamp: Tue 2008-04-29 23:43:40 +1000
    message:
      Add optional thread_name_suffix parameter to SmartTCPServer.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/smart/server.py         server.py-20061110062051-chzu10y32vx8gvur-1
      bzrlib/tests/test_smart.py     test_smart.py-20061122024551-ol0l0o0oofsu9b3t-2
=== modified file 'NEWS'
--- a/NEWS	2008-04-28 06:24:16 +0000
+++ b/NEWS	2008-04-29 13:43:40 +0000
@@ -58,6 +58,10 @@
 
   TESTING:
 
+    * Add ``thread_name_suffix`` parameter to SmartTCPServer_for_testing, to
+      make it easy to identify which test spawned a thread with an unhandled
+      exception. (Andrew Bennetts)
+
   INTERNALS:
 
     * Implement xml8 serializer.  (Aaron Bentley)

=== modified file 'bzrlib/smart/server.py'
--- a/bzrlib/smart/server.py	2008-04-21 01:07:17 +0000
+++ b/bzrlib/smart/server.py	2008-04-29 13:43:40 +0000
@@ -74,7 +74,7 @@
         self._stopped = threading.Event()
         self.root_client_path = root_client_path
 
-    def serve(self):
+    def serve(self, thread_name_suffix=''):
         self._should_terminate = False
         # for hooks we are letting code know that a server has started (and
         # later stopped).
@@ -116,7 +116,7 @@
                         if e.args[0] != errno.EBADF:
                             trace.warning("listening socket error: %s", e)
                     else:
-                        self.serve_conn(conn)
+                        self.serve_conn(conn, thread_name_suffix)
             except KeyboardInterrupt:
                 # dont log when CTRL-C'd.
                 raise
@@ -139,21 +139,23 @@
         """Return the url of the server"""
         return "bzr://%s:%d/" % self._sockname
 
-    def serve_conn(self, conn):
+    def serve_conn(self, conn, thread_name_suffix):
         # For WIN32, where the timeout value from the listening socket
         # propogates to the newly accepted socket.
         conn.setblocking(True)
         conn.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
         handler = SmartServerSocketStreamMedium(
             conn, self.backing_transport, self.root_client_path)
-        connection_thread = threading.Thread(None, handler.serve, name='smart-server-child')
+        thread_name = 'smart-server-child' + thread_name_suffix
+        connection_thread = threading.Thread(
+            None, handler.serve, name=thread_name)
         connection_thread.setDaemon(True)
         connection_thread.start()
 
-    def start_background_thread(self):
+    def start_background_thread(self, thread_name_suffix=''):
         self._started.clear()
         self._server_thread = threading.Thread(None,
-                self.serve,
+                self.serve, args=(thread_name_suffix,),
                 name='server-' + self.get_url())
         self._server_thread.setDaemon(True)
         self._server_thread.start()
@@ -213,9 +215,10 @@
     This server is backed by the process's cwd.
     """
 
-    def __init__(self):
+    def __init__(self, thread_name_suffix=''):
         SmartTCPServer.__init__(self, None)
         self.client_path_extra = None
+        self.thread_name_suffix = thread_name_suffix
         
     def get_backing_transport(self, backing_transport_server):
         """Get a backing transport from a server we are decorating."""
@@ -246,7 +249,7 @@
         self.backing_transport = transport.get_transport(
             self.chroot_server.get_url())
         self.root_client_path = self.client_path_extra = client_path_extra
-        self.start_background_thread()
+        self.start_background_thread(self.thread_name_suffix)
 
     def tearDown(self):
         self.stop_background_thread()

=== modified file 'bzrlib/tests/test_smart.py'
--- a/bzrlib/tests/test_smart.py	2008-04-08 08:13:33 +0000
+++ b/bzrlib/tests/test_smart.py	2008-04-29 13:43:40 +0000
@@ -104,7 +104,10 @@
         # the default or a parameterized class, but rather use the
         # TestCaseWithTransport infrastructure to set up a smart server and
         # transport.
-        self.transport_server = smart.server.SmartTCPServer_for_testing
+        self.transport_server = self.make_transport_server
+
+    def make_transport_server(self):
+        return smart.server.SmartTCPServer_for_testing('-' + self.id())
 
     def get_smart_medium(self):
         """Get a smart medium to use in tests."""




More information about the bazaar-commits mailing list