diff tests/test-commandserver.t @ 28511:ff5f923fca3c

cmdserver: write early exception to 'e' channel in 'unix' mode In 'unix' mode, the server is typically detached from the console. Therefore a client couldn't see the exception that occurred while instantiating the server object. This patch tries to catch the early error and send it to 'e' channel even if the server isn't instantiated yet. This means the error may be sent before the initial hello message. So it's up to the client implementation whether to handle the early error message or error out as protocol violation. The error handling code is also copied to chgserver.py. I'll factor out them later if we manage to get chg passes the test suite.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 12 Mar 2016 22:03:30 +0900
parents 332926212ef8
children 3f45488d70df
line wrap: on
line diff
--- a/tests/test-commandserver.t	Sun Mar 13 01:32:42 2016 +0530
+++ b/tests/test-commandserver.t	Sat Mar 12 22:03:30 2016 +0900
@@ -717,6 +717,35 @@
   listening at .hg/server.sock
   abort: unknown command unknowncommand
   killed!
+  $ rm .hg/server.log
+
+ if server crashed before hello, traceback will be sent to 'e' channel as
+ last ditch:
+
+  $ cat <<EOF >> .hg/hgrc
+  > [cmdserver]
+  > log = inexistent/path.log
+  > EOF
+  >>> from hgclient import unixserver, readchannel, check
+  >>> server = unixserver('.hg/server.sock', '.hg/server.log')
+  >>> def earlycrash(conn):
+  ...     while True:
+  ...         try:
+  ...             ch, data = readchannel(conn)
+  ...             if not data.startswith('  '):
+  ...                 print '%c, %r' % (ch, data)
+  ...         except EOFError:
+  ...             break
+  >>> check(earlycrash, server.connect)
+  e, 'Traceback (most recent call last):\n'
+  e, "IOError: *" (glob)
+  >>> server.shutdown()
+
+  $ cat .hg/server.log | grep -v '^  '
+  listening at .hg/server.sock
+  Traceback (most recent call last):
+  IOError: * (glob)
+  killed!
 #endif
 #if no-unix-socket