Skip to content

Commit

Permalink
Add test for finalizer, which broke in 3.8 due to underlying change i…
Browse files Browse the repository at this point in the history
…n Pool._repopulate_pool, which also manifests as a hang in long-running tests that manage to kill all the worker processes.
  • Loading branch information
CleanCut committed Jul 15, 2021
1 parent 4770654 commit aa572e1
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions green/test/test_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import multiprocessing
import os
from pathlib import PurePath
import subprocess
import sys
import tempfile
from textwrap import dedent
import unittest

try:
from unittest.mock import MagicMock
except:
from mock import MagicMock

from green import cmdline


class TestFinalizer(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()

def test_finalizer(self):
"""
Test that the finalizer works on Python 3.8+
"""
sub_tmpdir = tempfile.mkdtemp(dir=self.tmpdir)
for i in range(multiprocessing.cpu_count() * 2):
fh = open(os.path.join(sub_tmpdir, f"test_finalizer{i}.py"), "w")
fh.write(
dedent(
f"""
import unittest
class Pass{i}(unittest.TestCase):
def test_pass{i}(self):
pass
def msg():
print("finalizer worked")
"""
)
)
fh.close()
args = [
sys.executable,
"-m",
"green.cmdline",
"--finalizer=test_finalizer0.msg",
"--maxtasksperchild=1",
]
pythonpath = str(PurePath(__file__).parent.parent.parent)
print(pythonpath)
print(
subprocess.run(
args,
cwd=sub_tmpdir,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
env={"PYTHONPATH": pythonpath},
timeout=10,
).stdout.decode("utf-8")
)

0 comments on commit aa572e1

Please sign in to comment.