Skip to content

Commit 2d43ec1

Browse files
committed
Add test capturing missed expectation.
1 parent 4e0e813 commit 2d43ec1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/test_zip.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import multiprocessing
2+
import os
13
import sys
24
import unittest
35

46
from importlib_metadata import (
7+
FastPath,
58
PackageNotFoundError,
69
distribution,
710
distributions,
@@ -47,6 +50,37 @@ def test_one_distribution(self):
4750
dists = list(distributions(path=sys.path[:1]))
4851
assert len(dists) == 1
4952

53+
@unittest.skipUnless(
54+
hasattr(os, 'register_at_fork')
55+
and 'fork' in multiprocessing.get_all_start_methods(),
56+
'requires fork-based multiprocessing support',
57+
)
58+
def test_fastpath_cache_cleared_in_forked_child(self):
59+
zip_path = sys.path[0]
60+
61+
FastPath(zip_path)
62+
self.assertEqual(FastPath.__new__.cache_info().currsize, 1)
63+
64+
ctx = multiprocessing.get_context('fork')
65+
parent_conn, child_conn = ctx.Pipe()
66+
67+
def child(conn, root):
68+
try:
69+
before = FastPath.__new__.cache_info().currsize
70+
FastPath(root)
71+
after = FastPath.__new__.cache_info().currsize
72+
conn.send((before, after))
73+
finally:
74+
conn.close()
75+
76+
proc = ctx.Process(target=child, args=(child_conn, zip_path))
77+
proc.start()
78+
child_conn.close()
79+
cache_sizes = parent_conn.recv()
80+
proc.join()
81+
82+
self.assertEqual(cache_sizes, (0, 1))
83+
5084

5185
class TestEgg(TestZip):
5286
def setUp(self):

0 commit comments

Comments
 (0)