Skip to content

Commit

Permalink
Move netfx tests to individual subprocesses
Browse files Browse the repository at this point in the history
  • Loading branch information
filmor committed Aug 7, 2023
1 parent 05235b9 commit 59f47f9
Showing 1 changed file with 22 additions and 31 deletions.
53 changes: 22 additions & 31 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,15 @@ def test_coreclr(example_netcore: Path):


def test_coreclr_properties(example_netcore: Path):
from multiprocessing import get_context

p = get_context("spawn").Process(
target=_do_test_coreclr_autogenerated_runtimeconfig,
args=(example_netstandard,),
kwargs=dict(properties=dict(APP_CONTEXT_BASE_DIRECTORY=str(example_netcore))),
run_in_subprocess(
_do_test_coreclr_autogenerated_runtimeconfig,
example_netstandard,
properties=dict(APP_CONTEXT_BASE_DIRECTORY=str(example_netcore)),
)
p.start()
p.join()
p.close()


def test_coreclr_autogenerated_runtimeconfig(example_netstandard: Path):
from multiprocessing import get_context

p = get_context("spawn").Process(
target=_do_test_coreclr_autogenerated_runtimeconfig, args=(example_netstandard,)
)
p.start()
p.join()
p.close()
run_in_subprocess(_do_test_coreclr_autogenerated_runtimeconfig, example_netstandard)


def _do_test_coreclr_autogenerated_runtimeconfig(
Expand All @@ -114,37 +102,31 @@ def _do_test_coreclr_autogenerated_runtimeconfig(
sys.platform != "win32", reason=".NET Framework only exists on Windows"
)
def test_netfx(example_netstandard: Path):
from clr_loader import get_netfx

netfx = get_netfx()
asm = netfx.get_assembly(example_netstandard / "example.dll")

run_tests(asm)
run_in_subprocess(_do_test_netfx, example_netstandard)


@pytest.mark.skipif(
sys.platform != "win32", reason=".NET Framework only exists on Windows"
)
def test_netfx_chinese_path(example_netstandard: Path, tmpdir_factory):
from clr_loader import get_netfx

tmp_path = Path(tmpdir_factory.mktemp("example-中国"))
shutil.copytree(example_netstandard, tmp_path, dirs_exist_ok=True)

netfx = get_netfx()
asm = netfx.get_assembly(os.path.join(example_netstandard, "example.dll"))

run_tests(asm)
run_in_subprocess(_do_test_netfx, tmp_path)


@pytest.mark.skipif(
sys.platform != "win32", reason=".NET Framework only exists on Windows"
)
def test_netfx_separate_domain(example_netstandard):
run_in_subprocess(_do_test_netfx, example_netstandard, domain="some domain")


def _do_test_netfx(example_netstandard, **kwargs):
from clr_loader import get_netfx

netfx = get_netfx(domain="some_domain")
asm = netfx.get_assembly(os.path.join(example_netstandard, "example.dll"))
netfx = get_netfx(**kwargs)
asm = netfx.get_assembly(example_netstandard / "example.dll")

run_tests(asm)

Expand All @@ -154,3 +136,12 @@ def run_tests(asm):
test_data = b"testy mctestface"
res = func(test_data)
assert res == len(test_data)


def run_in_subprocess(func, *args, **kwargs):
from multiprocessing import get_context

p = get_context("spawn").Process(target=func, args=args, kwargs=kwargs)
p.start()
p.join()
p.close()

0 comments on commit 59f47f9

Please sign in to comment.