-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for finalizer, which broke in 3.8 due to underlying change i…
…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
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
) |