Skip to content

Commit 296530f

Browse files
committed
chore(rtc): restore upstream test_ffi_* files to focus PR on room sid
1 parent ced3c84 commit 296530f

2 files changed

Lines changed: 18 additions & 43 deletions

File tree

‎livekit-rtc/tests/test_ffi_client.py‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,15 @@
2222
_COUNT_ARRAY_TYPES_IN_GARBAGE = """
2323
import ctypes
2424
import gc
25-
import os
26-
import sys
2725
2826
from livekit import rtc
2927
3028
gc.collect()
3129
gc.set_debug(gc.DEBUG_SAVEALL)
32-
for _ in range(10):
30+
for _ in range(50):
3331
rtc.AudioProcessingModule()
3432
gc.collect()
35-
count = sum(isinstance(o, type(ctypes.Array)) for o in gc.garbage)
36-
sys.stdout.write(f"{count}\\n")
37-
sys.stdout.flush()
38-
os._exit(0)
33+
print(sum(isinstance(o, type(ctypes.Array)) for o in gc.garbage))
3934
"""
4035

4136

‎livekit-rtc/tests/test_ffi_handle_lifecycle.py‎

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from __future__ import annotations
1616

17+
import gc
1718
import subprocess
1819
import sys
1920

@@ -42,46 +43,25 @@ def test_active_runtime_invalid_handle_asserts() -> None:
4243

4344

4445
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
6149

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
6553

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__()
6957

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()
7361

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()
8565

8666

8767
def test_subprocess_exit_with_undisposed_handle_has_no_assertion_error() -> None:

0 commit comments

Comments
 (0)