Skip to content

Commit

Permalink
unit test for progress to logger
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewThe committed Dec 15, 2023
1 parent cf26361 commit 3fce61b
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions tests/unit_tests/test_job_pool.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
from job_pool import JobPool, AbnormalPoolTerminationError
import sys
import time
import pytest

from job_pool import JobPool, AbnormalPoolTerminationError


def add_one(i):
return i + 1


def exit_if_one(value):
if value:
sys.exit(123)
return value


def test_add_one():
"""Tests that the results are in the correct order"""
pool = JobPool(4)
Expand All @@ -17,12 +24,6 @@ def test_add_one():
assert results == list(range(1, 21))


def exit_if_one(value):
if value:
sys.exit(123)
return value


def test_exited_process():
pool = JobPool(4, timeout=10)
for value in [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]:
Expand Down Expand Up @@ -89,5 +90,18 @@ def test_maxtasksperchild_with_exited_process():
_ = pool.checkPool()


def test_write_progress_to_logger(caplog):
"""Tests that each job finishes within timeout, but total time is allowed to exceed timeout"""
pool = JobPool(4, maxtasksperchild=2, write_progress_to_logger=True)
for value in [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]:
pool.applyAsync(add_one, [value])

results = pool.checkPool()

assert "100%" in caplog.text

assert results == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]


if __name__ == "__main__":
test_maxtasksperchild_with_exited_process()
test_write_progress_to_logger()

0 comments on commit 3fce61b

Please sign in to comment.