End a worker that lingers after its final result by stopping the quiet background shells it left
CI / tests (pull_request) Failing after 4m10s
CI / tests (pull_request) Failing after 4m10s
This commit is contained in:
@@ -4,6 +4,7 @@ import io
|
||||
import os
|
||||
import pathlib
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
@@ -12,6 +13,7 @@ import unittest.mock
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from loop_effects import child_shells
|
||||
from loop_effects.effects import run_python, say, system_effects
|
||||
|
||||
NOW = 1790000000
|
||||
@@ -134,3 +136,24 @@ class PythonEffect(unittest.TestCase):
|
||||
done = run_python(["-c", "pass"], gone, 60)
|
||||
self.assertEqual(done.returncode, 1)
|
||||
self.assertIn(gone, done.stderr)
|
||||
|
||||
|
||||
class ChildShells(unittest.TestCase):
|
||||
def test_reads_a_child_shell_with_its_command_and_a_heavy_slot_and_stops_it_with_what_it_started(self):
|
||||
quiet = subprocess.Popen(["bash", "-c", "sleep 60; true"])
|
||||
heavy = subprocess.Popen(["bash", "-c", "sleep 60; true # run-heavy"])
|
||||
other = subprocess.Popen(["sleep", "60"])
|
||||
try:
|
||||
time.sleep(0.3)
|
||||
shells = {shell.pid: shell for shell in child_shells.shells_of(os.getpid())}
|
||||
self.assertEqual(sorted(shells), sorted([quiet.pid, heavy.pid]))
|
||||
self.assertEqual(shells[quiet.pid].command, "bash -c sleep 60; true")
|
||||
self.assertEqual((shells[quiet.pid].holds_slot, shells[heavy.pid].holds_slot), (False, True))
|
||||
self.assertLess(abs(shells[quiet.pid].started - time.time()), 5)
|
||||
child_shells.stop(shells[quiet.pid])
|
||||
self.assertEqual(quiet.wait(timeout=5), -signal.SIGTERM)
|
||||
self.assertIsNone(other.poll())
|
||||
finally:
|
||||
for proc in (quiet, heavy, other):
|
||||
proc.kill()
|
||||
proc.wait()
|
||||
|
||||
Reference in New Issue
Block a user