|
14 | 14 |
|
15 | 15 | from __future__ import annotations |
16 | 16 |
|
| 17 | +import gc |
17 | 18 | import subprocess |
18 | 19 | import sys |
19 | 20 |
|
@@ -42,46 +43,25 @@ def test_active_runtime_invalid_handle_asserts() -> None: |
42 | 43 |
|
43 | 44 |
|
44 | 45 | def test_live_handles_marked_consumed_and_no_assert_after_dispose() -> None: |
45 | | - code = """ |
46 | | -import gc |
47 | | -from livekit.rtc._ffi_client import FfiClient, FfiHandle |
48 | | -from livekit.rtc._proto import audio_frame_pb2, ffi_pb2 |
49 | | -
|
50 | | -req = ffi_pb2.FfiRequest() |
51 | | -req.new_audio_source.type = audio_frame_pb2.AUDIO_SOURCE_NATIVE |
52 | | -req.new_audio_source.sample_rate = 48000 |
53 | | -req.new_audio_source.num_channels = 1 |
54 | | -req.new_audio_source.queue_size_ms = 100 |
55 | | -resp = FfiClient.instance.request(req) |
56 | | -handle_id = int(resp.new_audio_source.source.handle.id) |
57 | | -assert handle_id != 0 |
58 | | -
|
59 | | -handle = FfiHandle(handle_id) |
60 | | -assert not handle.disposed |
| 46 | + handle_id = _allocate_real_handle() |
| 47 | + handle = FfiHandle(handle_id) |
| 48 | + assert not handle.disposed |
61 | 49 |
|
62 | | -# Global dispose marks all live handles consumed and sets _ffi_disposed |
63 | | -FfiClient.instance._dispose() |
64 | | -assert handle.disposed |
| 50 | + # Global dispose marks all live handles consumed and sets _ffi_disposed |
| 51 | + FfiClient.instance._dispose() |
| 52 | + assert handle.disposed |
65 | 53 |
|
66 | | -# Explicit dispose or __del__ after global dispose should be a no-op and not assert |
67 | | -handle.dispose() |
68 | | -handle.__del__() |
| 54 | + # Explicit dispose or __del__ after global dispose should be a no-op and not assert |
| 55 | + handle.dispose() |
| 56 | + handle.__del__() |
69 | 57 |
|
70 | | -# Newly instantiated handle after global dispose also safely no-ops without assert |
71 | | -late_handle = FfiHandle(12345) |
72 | | -late_handle.dispose() |
| 58 | + # Newly instantiated handle after global dispose also safely no-ops without assert |
| 59 | + late_handle = FfiHandle(12345) |
| 60 | + late_handle.dispose() |
73 | 61 |
|
74 | | -del handle |
75 | | -del late_handle |
76 | | -gc.collect() |
77 | | -""" |
78 | | - result = subprocess.run( |
79 | | - [sys.executable, "-c", code], |
80 | | - capture_output=True, |
81 | | - text=True, |
82 | | - ) |
83 | | - assert result.returncode == 0, f"Subprocess failed:\n{result.stderr}" |
84 | | - assert "AssertionError" not in result.stderr |
| 62 | + del handle |
| 63 | + del late_handle |
| 64 | + gc.collect() |
85 | 65 |
|
86 | 66 |
|
87 | 67 | def test_subprocess_exit_with_undisposed_handle_has_no_assertion_error() -> None: |
|
0 commit comments