test-commandserver: change way of triggering early crash
authorYuya Nishihara <yuya@tcha.org>
Sat, 10 Nov 2018 18:16:33 +0900
changeset 53587 6a75363f834a299b85ad88dd2e96ca61804fc232
parent 53586 96be0ecad6485c616fec15ac8debfbadcb6c22a4
child 53588 368ecbf734af109b936f309e7feec788d5597290
push id1079
push usergszorc@mozilla.com
push dateMon, 10 Dec 2018 19:44:59 +0000
test-commandserver: change way of triggering early crash Future patches will move the logging facility out of the server class, so cmdserver.log can't be (ab)used for this purpose. Instead, let's hook the factory function to raise exception.
tests/test-commandserver.t
--- a/tests/test-commandserver.t
+++ b/tests/test-commandserver.t
@@ -841,40 +841,49 @@ unix domain socket:
   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' > ../earlycrasher.py
+  > from mercurial import commandserver, extensions
+  > def _serverequest(orig, ui, repo, conn, createcmdserver):
+  >     def createcmdserver(*args, **kwargs):
+  >         raise Exception('crash')
+  >     return orig(ui, repo, conn, createcmdserver)
+  > def extsetup(ui):
+  >     extensions.wrapfunction(commandserver, b'_serverequest', _serverequest)
+  > EOF
   $ cat <<EOF >> .hg/hgrc
-  > [cmdserver]
-  > log = inexistent/path.log
+  > [extensions]
+  > earlycrasher = ../earlycrasher.py
   > EOF
   >>> from hgclient import bprint, check, readchannel, unixserver
   >>> server = unixserver(b'.hg/server.sock', b'.hg/server.log')
   >>> def earlycrash(conn):
   ...     while True:
   ...         try:
   ...             ch, data = readchannel(conn)
   ...             for l in data.splitlines(True):
   ...                 if not l.startswith(b'  '):
   ...                     bprint(b'%c, %r' % (ch, l))
   ...         except EOFError:
   ...             break
   >>> check(earlycrash, server.connect)
   e, 'Traceback (most recent call last):\n'
-  e, "(IOError|FileNotFoundError): .*" (re)
+  e, 'Exception: crash\n'
   >>> server.shutdown()
 
   $ cat .hg/server.log | grep -v '^  '
   listening at .hg/server.sock
   Traceback (most recent call last):
-  (IOError|FileNotFoundError): .* (re)
+  Exception: crash
   killed!
 #endif
 #if no-unix-socket
 
   $ hg serve --cmdserver unix -a .hg/server.sock
   abort: unsupported platform
   [255]