Skip to content

Commit f87e5c5

Browse files
Andy-Jostclaude
andcommitted
test(cuda.core): collect garbage before each file-descriptor baseline in the VMM IPC tests
init_cuda no longer runs gc.collect() at every teardown (#3053), so objects left by earlier tests (child pipes, queues, descriptors) can be collected in the middle of a test that counts process-wide file descriptors, and the count then drops below its baseline. Collect before taking the baseline. Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent c7210c8 commit f87e5c5

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

‎cuda_core/tests/memory_ipc/test_vmm_ipc.py‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ def _open_fds():
8888
return len(os.listdir("/proc/self/fd"))
8989

9090

91+
def _settled_open_fds():
92+
"""The open file descriptor count after a garbage collection.
93+
94+
Objects left by earlier tests may still hold file descriptors (child
95+
pipes, queues, descriptors), and ``init_cuda`` no longer collects at
96+
every teardown. Collecting here keeps a baseline stable against a
97+
collection that the test itself triggers later.
98+
"""
99+
gc.collect()
100+
return _open_fds()
101+
102+
91103
def _has_note(exc, text):
92104
"""Whether ``text`` is in one of the exception's notes, or in its message on Python 3.10."""
93105
return any(text in note for note in getattr(exc, "__notes__", ())) or text in str(exc)
@@ -241,7 +253,7 @@ def test_main(self, vmm_ipc_device):
241253
for i, value in enumerate(values):
242254
_fill(moved, value, offset=i * gran, size=gran)
243255

244-
fds_before = _open_fds()
256+
fds_before = _settled_open_fds()
245257
desc = moved.ipc_descriptor
246258
assert desc.size == 3 * gran
247259
assert desc._chunk_sizes == (gran, gran, gran)
@@ -551,7 +563,7 @@ def test_exporter_holds_none_without_a_descriptor(self, vmm_ipc_device):
551563
first = mr.allocate(1)
552564
gran = first.size
553565
buf = mr.modify_allocation(first, 2 * gran)
554-
fds0 = _open_fds()
566+
fds0 = _settled_open_fds()
555567
desc = buf.ipc_descriptor
556568
assert desc.sizes == (gran, gran)
557569
assert _open_fds() == fds0 + 2
@@ -579,7 +591,7 @@ def test_process_argument_releases_with_the_process_object(self, vmm_ipc_device)
579591
device = vmm_ipc_device
580592
mr = _resource(device)
581593
buf = mr.allocate(1)
582-
fds0 = _open_fds()
594+
fds0 = _settled_open_fds()
583595
process = mp.Process(target=_close_argument, args=(buf,))
584596
process.start()
585597
process.join(timeout=CHILD_TIMEOUT_SEC)
@@ -624,7 +636,7 @@ def child_main(device_id, to_child, from_child):
624636
desc = to_child.get(timeout=CHILD_TIMEOUT_SEC)
625637
# A first import lets the driver finish any lazy initialization before counting.
626638
Buffer.from_ipc_descriptor(mr, desc, stream=device.default_stream).close()
627-
counts = {"with_descriptor": _open_fds()}
639+
counts = {"with_descriptor": _settled_open_fds()}
628640
imported = Buffer.from_ipc_descriptor(mr, desc, stream=device.default_stream)
629641
counts["after_import"] = _open_fds()
630642
del desc
@@ -665,7 +677,7 @@ def test_export_near_the_limit(self, vmm_ipc_device):
665677
os.close(fd)
666678
break
667679
fillers.append(fd)
668-
baseline = _open_fds()
680+
baseline = _settled_open_fds()
669681
# Room for two more descriptors: a three-allocation export cannot complete.
670682
resource.setrlimit(resource.RLIMIT_NOFILE, (highest + 1 + 2, hard))
671683
failure = None
@@ -712,7 +724,7 @@ def test_round_trip_with_os_dup(self, vmm_ipc_device):
712724
buf = mr.modify_allocation(first, 2 * gran)
713725
_fill(buf, 0x71, size=gran)
714726
_fill(buf, 0x72, offset=gran, size=gran)
715-
fds0 = _open_fds()
727+
fds0 = _settled_open_fds()
716728
desc = buf.ipc_descriptor
717729
assert desc.handle_type == "posix_fd"
718730
assert desc.sizes == (gran, gran)

0 commit comments

Comments
 (0)