Use a single process in testing, not the Pool
This commit is contained in:
parent
9af8d4f186
commit
10f22834ee
@ -75,10 +75,18 @@ class Command(MultiProcessMixin, ProgressBarMixin, BaseCommand):
|
||||
|
||||
try:
|
||||
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:
|
||||
list(
|
||||
tqdm.tqdm(
|
||||
pool.imap_unordered(update_document_archive_file, document_ids),
|
||||
pool.imap_unordered(
|
||||
update_document_archive_file,
|
||||
document_ids,
|
||||
),
|
||||
total=len(document_ids),
|
||||
disable=self.no_progress_bar,
|
||||
),
|
||||
|
@ -93,12 +93,12 @@ class Command(MultiProcessMixin, ProgressBarMixin, BaseCommand):
|
||||
work_pkgs.append(_WorkPackage(first_doc, second_doc))
|
||||
|
||||
# Don't spin up a pool of 1 process
|
||||
if options["processes"] == 1:
|
||||
if self.process_count == 1:
|
||||
results = []
|
||||
for work in tqdm.tqdm(work_pkgs, disable=self.no_progress_bar):
|
||||
results.append(_process_and_match(work))
|
||||
else:
|
||||
with multiprocessing.Pool(processes=options["processes"]) as pool:
|
||||
else: # pragma: no cover
|
||||
with multiprocessing.Pool(processes=self.process_count) as pool:
|
||||
results = list(
|
||||
tqdm.tqdm(
|
||||
pool.imap_unordered(_process_and_match, work_pkgs),
|
||||
|
@ -70,6 +70,10 @@ class Command(MultiProcessMixin, ProgressBarMixin, BaseCommand):
|
||||
# with postgres.
|
||||
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:
|
||||
list(
|
||||
tqdm.tqdm(
|
||||
|
@ -36,7 +36,7 @@ class TestArchiver(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
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):
|
||||
doc = self.make_models()
|
||||
|
@ -83,13 +83,13 @@ class TestMakeThumbnails(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
def test_command(self):
|
||||
self.assertIsNotFile(self.d1.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.d2.thumbnail_path)
|
||||
|
||||
def test_command_documentid(self):
|
||||
self.assertIsNotFile(self.d1.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.assertIsNotFile(self.d2.thumbnail_path)
|
||||
|
Loading…
x
Reference in New Issue
Block a user