Skip to content
Snippets Groups Projects

Move pressure-vessel-adverb subprocess supervision into common code

Merged Simon McVittie requested to merge wip/smcv/into-library2 into main
@@ -302,6 +302,7 @@ class TestAdverb(BaseTest):
stdout = proc.stdout
assert stdout is not None
pid = int(stdout.read().strip())
stdout.close()
finally:
if pid:
os.kill(pid, signal.SIGTERM)
@@ -376,6 +377,7 @@ class TestAdverb(BaseTest):
stdout = proc.stdout
assert stdout is not None
self.assertEqual(stdout.read(), 'from stdin')
stdout.close()
finally:
proc.wait()
self.assertEqual(proc.returncode, 0)
@@ -421,17 +423,25 @@ class TestAdverb(BaseTest):
'--lock-file=%s/.ref' % tmpdir,
'--',
'sh', '-euc',
'echo hello > %s/.ref' % shlex.quote(tmpdir),
'exec >/dev/null; echo hello > %s/.ref' % (
shlex.quote(tmpdir),
),
],
stdin=read_end,
stdout=STDERR_FILENO,
stdout=subprocess.PIPE,
stderr=STDERR_FILENO,
universal_newlines=True,
)
try:
os.close(read_end)
# By the time sh runs, pv-adverb should have taken the lock.
# The sh process signals that it is running by closing stdout.
stdout = proc.stdout
assert stdout is not None
self.assertEqual(stdout.read(), b'')
stdout.close()
proc2 = subprocess.Popen(
self.adverb + [
'--create',
@@ -455,6 +465,7 @@ class TestAdverb(BaseTest):
stdout = proc2.stdout
assert stdout is not None
self.assertEqual(stdout.read(), b'hello\n')
stdout.close()
finally:
proc.wait()
self.assertEqual(proc.returncode, 0)
Loading