[Zope-Checkins] SVN: zdaemon/trunk/src/zdaemon/tests/ Updated test
testRunIgnoresParentSignals:
Jim Fulton
jim at zope.com
Sun Oct 30 10:18:43 EST 2005
Log message for revision 39732:
Updated test testRunIgnoresParentSignals:
- Use mkdtemp to create a temporary directory to hold the test socket
rather than creating the test socket in the test directory.
Hopefully this will be more robust. Sometimes the test directory
has a path so long that the test socket can't be created.
- Changed management of donothing.sh. This script is now created by
the test in the temporarary directory with the necessary
permissions. This is to avoids possible mangling of permissions
leading to spurious test failures. It also avoids management of a
file in the source tree, which is a bonus.
Changed:
D zdaemon/trunk/src/zdaemon/tests/donothing.sh
U zdaemon/trunk/src/zdaemon/tests/parent.py
U zdaemon/trunk/src/zdaemon/tests/testzdrun.py
-=-
Deleted: zdaemon/trunk/src/zdaemon/tests/donothing.sh
===================================================================
--- zdaemon/trunk/src/zdaemon/tests/donothing.sh 2005-10-30 15:10:24 UTC (rev 39731)
+++ zdaemon/trunk/src/zdaemon/tests/donothing.sh 2005-10-30 15:18:43 UTC (rev 39732)
@@ -1,6 +0,0 @@
-#!/bin/sh
-while [ "1" -ne "2" ]; do
- sleep 10
-done
-
-
Modified: zdaemon/trunk/src/zdaemon/tests/parent.py
===================================================================
--- zdaemon/trunk/src/zdaemon/tests/parent.py 2005-10-30 15:10:24 UTC (rev 39731)
+++ zdaemon/trunk/src/zdaemon/tests/parent.py 2005-10-30 15:18:43 UTC (rev 39732)
@@ -2,16 +2,28 @@
import os
import sys
+donothing_contents = """\
+#!/bin/sh
+while [ "1" -ne "2" ]; do
+ sleep 10
+done
+"""
+
def main():
# dummy zdctl startup of zdrun
shutup()
file = os.path.normpath(os.path.abspath(sys.argv[0]))
+ tmp = sys.argv[1]
dir = os.path.dirname(file)
zctldir = os.path.dirname(dir)
zdrun = os.path.join(zctldir, 'zdrun.py')
+ donothing = os.path.join(tmp, 'donothing.sh')
+ fd = os.open(donothing, os.O_WRONLY|os.O_CREAT, 0700)
+ os.write(fd, donothing_contents)
+ os.close(fd)
args = [sys.executable, zdrun]
- args += ['-d', '-b', '10', '-s', os.path.join(dir, 'testsock'),
- '-x', '0,2', '-z', dir, os.path.join(dir, 'donothing.sh')]
+ args += ['-d', '-b', '10', '-s', os.path.join(tmp, 'testsock'),
+ '-x', '0,2', '-z', dir, donothing]
flag = os.P_NOWAIT
#cmd = ' '.join([sys.executable] + args)
#print cmd
Modified: zdaemon/trunk/src/zdaemon/tests/testzdrun.py
===================================================================
--- zdaemon/trunk/src/zdaemon/tests/testzdrun.py 2005-10-30 15:10:24 UTC (rev 39731)
+++ zdaemon/trunk/src/zdaemon/tests/testzdrun.py 2005-10-30 15:18:43 UTC (rev 39732)
@@ -3,6 +3,7 @@
import os
import sys
import time
+import shutil
import signal
import tempfile
import unittest
@@ -218,31 +219,36 @@
# We make sure that the zdrun process is still running even if
# its parent process receives an interrupt signal (it should
# not be passed to zdrun).
- zdrun_socket = os.path.join(self.here, 'testsock')
- zdctlpid = os.spawnvp(
- os.P_NOWAIT,
- sys.executable,
- [sys.executable, os.path.join(self.here, 'parent.py')]
- )
- # Wait for it to start, but no longer than a minute.
- deadline = time.time() + 60
- is_started = False
- while time.time() < deadline:
- response = send_action('status\n', zdrun_socket)
- if response is None:
- time.sleep(0.05)
- else:
- is_started = True
- break
- self.assert_(is_started, "spawned process failed to start in a minute")
- # Kill it, and wait a little to ensure it's dead.
- os.kill(zdctlpid, signal.SIGINT)
- time.sleep(0.25)
- # Make sure the child is still responsive.
- response = send_action('status\n', zdrun_socket)
- self.assert_(response is not None and '\n' in response)
- # Kill the process.
- send_action('exit\n', zdrun_socket)
+ tmp = tempfile.mkdtemp()
+ zdrun_socket = os.path.join(tmp, 'testsock')
+ try:
+ zdctlpid = os.spawnvp(
+ os.P_NOWAIT,
+ sys.executable,
+ [sys.executable, os.path.join(self.here, 'parent.py'), tmp]
+ )
+ # Wait for it to start, but no longer than a minute.
+ deadline = time.time() + 60
+ is_started = False
+ while time.time() < deadline:
+ response = send_action('status\n', zdrun_socket)
+ if response is None:
+ time.sleep(0.05)
+ else:
+ is_started = True
+ break
+ self.assert_(is_started,
+ "spawned process failed to start in a minute")
+ # Kill it, and wait a little to ensure it's dead.
+ os.kill(zdctlpid, signal.SIGINT)
+ time.sleep(0.25)
+ # Make sure the child is still responsive.
+ response = send_action('status\n', zdrun_socket)
+ self.assert_(response is not None and '\n' in response)
+ # Kill the process.
+ send_action('exit\n', zdrun_socket)
+ finally:
+ shutil.rmtree(tmp)
def testUmask(self):
# people have a strange tendency to run the tests as root
More information about the Zope-Checkins
mailing list