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

Clean up parallel testing logic

Generalize LockProcess into ParallelTestProcess, which I'll be using for AtomicCreateIfMissing tests momentarily.
parent 75f7c6d6
Branches
No related tags found
No related merge requests found
......@@ -88,15 +88,18 @@ def ELFT_lock_proc(title, file, qresults, qcommands):
return 1
qresults.put(f"{title} {ELFT_MSG_DONE}")
class LockProcess:
def __init__(self, name, lockfile, process, qresults, qcommands):
import multiprocessing
class ParallelTestProcess:
def __init__(self, name, func, data):
self.name = name
self.lockfile = lockfile
self.process = process
self.qresults = qresults
self.qcommands = qcommands
self.data = data
self.qresults = multiprocessing.Queue()
self.qcommands = multiprocessing.Queue()
self.process = multiprocessing.Process(target=ELFT_lock_proc,
args=[name, data, self.qresults, self.qcommands])
self.running = False
def start(self):
if self.running:
raise RuntimeError("trying to start() an already running process")
......@@ -119,14 +122,6 @@ class LockProcess:
class ExclusiveLockFileTests(DTestCase):
def create_lock_process(self, name, lockfile):
from multiprocessing import Process, Queue
qresults = Queue()
qcommands = Queue()
p = Process(target=ELFT_lock_proc,
args=[name, lockfile, qresults, qcommands])
return LockProcess(name, lockfile, p, qresults, qcommands)
def test_exclusivelockfile(self):
from tempfile import TemporaryDirectory
# Trying to deterministically test non-deterministic code is awful
......@@ -136,7 +131,7 @@ class ExclusiveLockFileTests(DTestCase):
open(lockfile,"x").close()
try:
lockfile = dir+"/lock"
p = [self.create_lock_process(f"p{i}", lockfile) for i in range(3)]
p = [ParallelTestProcess(f"p{i}", ELFT_lock_proc, lockfile) for i in range(3)]
p[0].start()
self.assertEqual(p[0].get(), f"p0 {ELFT_MSG_WAITING}")
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment