Commit 10b12696 authored by Marius Gedminas's avatar Marius Gedminas

Fix runzeo_logrotate_on_sigusr2

Attempting to open a file before it is created turns out not to be a
good idea.  Moved all the file opening inside the wait_until lambdas
(after extracting them into a standalone helper function, since you
can't use the with statement inside a lambda).

Also fixed test failure on Python 3.3 (r.write() returns the number of
bytes written).

Added an XXX about a possible hang while opening ClientStorage, in case
something went wrong.  I'm not sure how to fix that.
parent 1acb24d1
...@@ -1455,11 +1455,15 @@ def generate_script(name, src): ...@@ -1455,11 +1455,15 @@ def generate_script(name, src):
src=src, src=src,
)) ))
def read(filename):
with open(filename) as f:
return f.read()
def runzeo_logrotate_on_sigusr2(): def runzeo_logrotate_on_sigusr2():
""" """
>>> port = get_port() >>> port = get_port()
>>> with open('c', 'w') as r: >>> with open('c', 'w') as r:
... r.write(''' ... _ = r.write('''
... <zeo> ... <zeo>
... address %s ... address %s
... </zeo> ... </zeo>
...@@ -1477,23 +1481,23 @@ def runzeo_logrotate_on_sigusr2(): ...@@ -1477,23 +1481,23 @@ def runzeo_logrotate_on_sigusr2():
... ''') ... ''')
>>> import subprocess, signal >>> import subprocess, signal
>>> p = subprocess.Popen([sys.executable, 's', '-Cc'], close_fds=True) >>> p = subprocess.Popen([sys.executable, 's', '-Cc'], close_fds=True)
>>> with open('l') as f: >>> wait_until('started',
... wait_until('started', ... lambda : os.path.exists('l') and ('listening on' in read('l'))
... lambda : os.path.exists('l') and ('listening on' in f.read())
... ) ... )
>>> with open('l') as f: >>> oldlog = read('l')
... oldlog = f.read()
>>> os.rename('l', 'o') >>> os.rename('l', 'o')
>>> os.kill(p.pid, signal.SIGUSR2) >>> os.kill(p.pid, signal.SIGUSR2)
>>> wait_until('new file', lambda : os.path.exists('l')) >>> wait_until('new file', lambda : os.path.exists('l'))
XXX: if any of the previous commands failed, we'll hang here trying to
connect to ZEO, because doctest runs all the assertions...
>>> s = ClientStorage(port) >>> s = ClientStorage(port)
>>> s.close() >>> s.close()
>>> with open('l') as f: >>> wait_until('See logging', lambda : ('Log files ' in read('l')))
... wait_until('See logging', lambda : ('Log files ' in f.read())) >>> read('o') == oldlog # No new data in old log
>>> with open('o') as f:
... f.read() == oldlog # No new data in old log
True True
# Cleanup: # Cleanup:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment