Use a single process in testing, not the Pool

This commit is contained in:
Trenton H 2023-11-09 11:21:45 -08:00
parent 9af8d4f186
commit 10f22834ee
5 changed files with 34 additions and 22 deletions

View File

@ -75,10 +75,18 @@ class Command(MultiProcessMixin, ProgressBarMixin, BaseCommand):
try: try:
logging.getLogger().handlers[0].level = logging.ERROR logging.getLogger().handlers[0].level = logging.ERROR
if self.process_count == 1:
for doc_id in document_ids:
update_document_archive_file(doc_id)
else: # pragma: no cover
with multiprocessing.Pool(self.process_count) as pool: with multiprocessing.Pool(self.process_count) as pool:
list( list(
tqdm.tqdm( tqdm.tqdm(
pool.imap_unordered(update_document_archive_file, document_ids), pool.imap_unordered(
update_document_archive_file,
document_ids,
),
total=len(document_ids), total=len(document_ids),
disable=self.no_progress_bar, disable=self.no_progress_bar,
), ),

View File

@ -93,12 +93,12 @@ class Command(MultiProcessMixin, ProgressBarMixin, BaseCommand):
work_pkgs.append(_WorkPackage(first_doc, second_doc)) work_pkgs.append(_WorkPackage(first_doc, second_doc))
# Don't spin up a pool of 1 process # Don't spin up a pool of 1 process
if options["processes"] == 1: if self.process_count == 1:
results = [] results = []
for work in tqdm.tqdm(work_pkgs, disable=self.no_progress_bar): for work in tqdm.tqdm(work_pkgs, disable=self.no_progress_bar):
results.append(_process_and_match(work)) results.append(_process_and_match(work))
else: else: # pragma: no cover
with multiprocessing.Pool(processes=options["processes"]) as pool: with multiprocessing.Pool(processes=self.process_count) as pool:
results = list( results = list(
tqdm.tqdm( tqdm.tqdm(
pool.imap_unordered(_process_and_match, work_pkgs), pool.imap_unordered(_process_and_match, work_pkgs),

View File

@ -70,6 +70,10 @@ class Command(MultiProcessMixin, ProgressBarMixin, BaseCommand):
# with postgres. # with postgres.
db.connections.close_all() db.connections.close_all()
if self.process_count == 1:
for doc_id in ids:
_process_document(doc_id)
else: # pragma: no cover
with multiprocessing.Pool(processes=self.process_count) as pool: with multiprocessing.Pool(processes=self.process_count) as pool:
list( list(
tqdm.tqdm( tqdm.tqdm(

View File

@ -36,7 +36,7 @@ class TestArchiver(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
os.path.join(self.dirs.originals_dir, f"{doc.id:07}.pdf"), os.path.join(self.dirs.originals_dir, f"{doc.id:07}.pdf"),
) )
call_command("document_archiver") call_command("document_archiver", "--processes", "1")
def test_handle_document(self): def test_handle_document(self):
doc = self.make_models() doc = self.make_models()

View File

@ -83,13 +83,13 @@ class TestMakeThumbnails(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
def test_command(self): def test_command(self):
self.assertIsNotFile(self.d1.thumbnail_path) self.assertIsNotFile(self.d1.thumbnail_path)
self.assertIsNotFile(self.d2.thumbnail_path) self.assertIsNotFile(self.d2.thumbnail_path)
call_command("document_thumbnails") call_command("document_thumbnails", "--processes", "1")
self.assertIsFile(self.d1.thumbnail_path) self.assertIsFile(self.d1.thumbnail_path)
self.assertIsFile(self.d2.thumbnail_path) self.assertIsFile(self.d2.thumbnail_path)
def test_command_documentid(self): def test_command_documentid(self):
self.assertIsNotFile(self.d1.thumbnail_path) self.assertIsNotFile(self.d1.thumbnail_path)
self.assertIsNotFile(self.d2.thumbnail_path) self.assertIsNotFile(self.d2.thumbnail_path)
call_command("document_thumbnails", "-d", f"{self.d1.id}") call_command("document_thumbnails", "--processes", "1", "-d", f"{self.d1.id}")
self.assertIsFile(self.d1.thumbnail_path) self.assertIsFile(self.d1.thumbnail_path)
self.assertIsNotFile(self.d2.thumbnail_path) self.assertIsNotFile(self.d2.thumbnail_path)