Skip to content
Snippets Groups Projects
Commit ed93ff02 authored by Alan De Smet's avatar Alan De Smet
Browse files

ParallelTestProcess now self-terminates on delete

This slightly simplifies usage
parent faf9710f
No related branches found
No related tags found
No related merge requests found
......@@ -106,11 +106,18 @@ class ParallelTestProcess:
self.process.start()
self.running = True
def join(self, timeout=None):
self.process.join(timeout)
self.running = False
def terminate(self):
if self.running:
self.process.terminate()
self.running = False
def is_alive(self):
return self.process.is_alive()
def get(self):
return self.qresults.get()
......@@ -120,6 +127,9 @@ class ParallelTestProcess:
def is_quiet(self):
return self.qresults.empty()
def __del__(self):
self.terminate()
class ExclusiveLockFileTests(DTestCase):
def test_exclusivelockfile(self):
......@@ -129,7 +139,7 @@ class ExclusiveLockFileTests(DTestCase):
p = []
lockfile = dir+"/lock"
open(lockfile,"x").close()
try:
lockfile = dir+"/lock"
p = [ParallelTestProcess(f"p{i}", ELFT_lock_proc, lockfile) for i in range(3)]
......@@ -157,6 +167,8 @@ class ExclusiveLockFileTests(DTestCase):
self.assertEqual(p[1].get(), f"p1 {ELFT_MSG_DONE}")
self.assertTrue(p[1].is_quiet())
# The other locks are gone, this should be trivial
p[2].start()
self.assertEqual(p[2].get(), f"p2 {ELFT_MSG_WAITING}")
......@@ -169,13 +181,11 @@ class ExclusiveLockFileTests(DTestCase):
self.assertEqual(p[2].get(), f"p2 {ELFT_MSG_DONE}")
self.assertTrue(p[2].is_quiet())
self.assertTrue(p[0].is_quiet())
self.assertTrue(p[1].is_quiet())
self.assertTrue(p[2].is_quiet())
for i in range(3):
MAXIMUM_TIME_TO_EXIT=2 # seconds
p[i].join(MAXIMUM_TIME_TO_EXIT)
self.assertFalse(p[i].is_alive())
finally:
for i in p:
i.terminate()
class AtomicCreateIfMissingTests(DTestCase):
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment