Patchwork [024,of,179,tests-refactor] run-tests: kill daemons during Test.__del__

login
register
mail settings
Submitter Gregory Szorc
Date May 2, 2014, 6:37 p.m.
Message ID <317c7fdd311251775694.1399055861@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/4519/
State Deferred
Headers show

Comments

Gregory Szorc - May 2, 2014, 6:37 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1397964152 25200
#      Sat Apr 19 20:22:32 2014 -0700
# Branch stable
# Node ID 317c7fdd311251775694fc9231e6197b15532fdd
# Parent  005aea2ea48076ce7dc1c14a99b99b4f58a90786
run-tests: kill daemons during Test.__del__

As a safety precaution, we kill daemons in Test.__del__. This is
necessary for a subsequent patch that will reraise KeyboardInterrupt
before killdaemons() runs as part of run().

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -548,40 +548,45 @@  class Test(object):
     Test instances can be run multiple times via run(). However, multiple
     runs cannot be run concurrently.
     """
 
     def __init__(self, path, options, count, refpath):
         self._path = path
         self._options = options
         self._count = count
+        self._daemonpids = []
 
         # If we're not in --debug mode and reference output file exists,
         # check test output against it.
         if options.debug:
             self._refout = None # to match "out is None"
         elif os.path.exists(refpath):
             f = open(refpath, 'r')
             self._refout = f.read().splitlines(True)
             f.close()
         else:
             self._refout = []
 
         self._threadtmp = os.path.join(HGTMP, 'child%d' % count)
         os.mkdir(self._threadtmp)
 
     def __del__(self):
+        for entry in self._daemonpids:
+            killdaemons(entry)
+
         if self._threadtmp and not self._options.keep_tmpdir:
             shutil.rmtree(self._threadtmp, True)
 
     def run(self, result):
         testtmp = os.path.join(self._threadtmp, os.path.basename(self._path))
         os.mkdir(testtmp)
         replacements, port = self._getreplacements(testtmp)
         env = self._getenv(testtmp, port)
+        self._daemonpids.append(env['DAEMON_PIDS'])
         createhgrc(env['HGRCPATH'], self._options)
 
         starttime = time.time()
 
         def updateduration():
             result.duration = time.time() - starttime
 
         try: