summaryrefslogtreecommitdiff
blob: f1f4fac265570f066058054515be9c4c42047b0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
diff --git a/cheroot/test/test_server.py b/cheroot/test/test_server.py
index 8305c78c..39e4e066 100644
--- a/cheroot/test/test_server.py
+++ b/cheroot/test/test_server.py
@@ -16,7 +16,6 @@ import requests
 import requests_unixsocket
 import six
 
-from pypytools.gc.custom import DefaultGc
 from six.moves import queue, urllib
 
 from .._compat import bton, ntob
@@ -330,8 +329,7 @@ def test_peercreds_unix_sock_with_lookup(peercreds_enabled_server):
     ),
     indirect=('resource_limit',),
 )
-@pytest.mark.usefixtures('many_open_sockets')
-def test_high_number_of_file_descriptors(native_server_client, resource_limit):
+def _test_high_number_of_file_descriptors(native_server_client, resource_limit):
     """Test the server does not crash with a high file-descriptor value.
 
     This test shouldn't cause a server crash when trying to access
@@ -363,18 +361,6 @@ def test_high_number_of_file_descriptors(native_server_client, resource_limit):
     assert any(fn >= resource_limit for fn in native_process_conn.filenos)
 
 
-if not IS_WINDOWS:
-    test_high_number_of_file_descriptors = pytest.mark.forked(
-        test_high_number_of_file_descriptors,
-    )
-
-
-@pytest.fixture
-def _garbage_bin():
-    """Disable garbage collection when this fixture is in use."""
-    with DefaultGc().nogc():
-        yield
-
 
 @pytest.fixture
 def resource_limit(request):
@@ -400,32 +386,3 @@ def resource_limit(request):
     finally:
         # Reset the resource limit back to the original soft limit
         resource.setrlimit(resource.RLIMIT_NOFILE, (soft_limit, hard_limit))
-
-
-@pytest.fixture
-def many_open_sockets(request, resource_limit):
-    """Allocate a lot of file descriptors by opening dummy sockets."""
-    # NOTE: `@pytest.mark.usefixtures` doesn't work on fixtures which
-    # NOTE: forces us to invoke this one dynamically to avoid having an
-    # NOTE: unused argument.
-    request.getfixturevalue('_garbage_bin')
-
-    # Hoard a lot of file descriptors by opening and storing a lot of sockets
-    test_sockets = []
-    # Open a lot of file descriptors, so the next one the server
-    # opens is a high number
-    try:
-        for _ in range(resource_limit):
-            sock = socket.socket()
-            test_sockets.append(sock)
-            # If we reach a high enough number, we don't need to open more
-            if sock.fileno() >= resource_limit:
-                break
-        # Check we opened enough descriptors to reach a high number
-        the_highest_fileno = test_sockets[-1].fileno()
-        assert the_highest_fileno >= resource_limit
-        yield the_highest_fileno
-    finally:
-        # Close our open resources
-        for test_socket in test_sockets:
-            test_socket.close()