Skip to content

Commit 83a86a2

Browse files
committed
issue #482: tests: fail DockerMixin tests if stray processes exist
1 parent e352b9e commit 83a86a2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/testlib.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,22 @@ def get_host(self):
454454
def wait_for_sshd(self):
455455
wait_for_port(self.get_host(), self.port, pattern='OpenSSH')
456456

457+
def check_processes(self):
458+
args = ['docker', 'exec', self.container_name, 'ps', '-o', 'comm=']
459+
counts = {}
460+
for comm in subprocess__check_output(args).splitlines():
461+
comm = comm.strip()
462+
counts[comm] = counts.get(comm, 0) + 1
463+
464+
if counts != {'ps': 1, 'sshd': 1}:
465+
assert 0, (
466+
'Docker container %r contained extra running processes '
467+
'after test completed: %r' % (
468+
self.container_name,
469+
counts
470+
)
471+
)
472+
457473
def close(self):
458474
args = ['docker', 'rm', '-f', self.container_name]
459475
subprocess__check_output(args)
@@ -501,6 +517,7 @@ def setUpClass(cls):
501517

502518
@classmethod
503519
def tearDownClass(cls):
520+
cls.dockerized_ssh.check_processes()
504521
cls.dockerized_ssh.close()
505522
super(DockerMixin, cls).tearDownClass()
506523

0 commit comments

Comments
 (0)