mirror of
https://github.com/facefusion/facefusion.git
synced 2026-09-19 22:12:17 +02:00
content store (#1225)
* introduce content store for content analyser * introduce content store for content analyser part2 * guard content store as well * minor changes * minor changes * minor changes
This commit is contained in:
@@ -45,7 +45,8 @@ async def test_process_image() -> None:
|
||||
}
|
||||
]
|
||||
|
||||
await process_image(websocket_mock)
|
||||
with patch('facefusion.apis.stream_manager.analyse_frame', return_value = False):
|
||||
await process_image(websocket_mock)
|
||||
|
||||
websocket_mock.send_bytes.assert_called_once()
|
||||
|
||||
|
||||
@@ -77,16 +77,17 @@ def test_run_video_encode_loop(video_codec : VideoCodec, payload_type : int) ->
|
||||
|
||||
video_queue : Queue[Tuple[Time, Future[BufferPack]]] = Queue(maxsize = 30)
|
||||
|
||||
with ThreadPoolExecutor(max_workers = 1) as executor:
|
||||
video_queue.put((0.1, executor.submit(process_video_frame, [], video_frame)))
|
||||
with patch('facefusion.apis.stream_video.analyse_stream', return_value = False):
|
||||
with ThreadPoolExecutor(max_workers = 1) as executor:
|
||||
video_queue.put((0.1, executor.submit(process_video_frame, [], video_frame)))
|
||||
|
||||
with patch('facefusion.apis.stream_video.rtc.send_video') as send_video_mock:
|
||||
encode_loop_thread = threading.Thread(target = run_video_encode_loop, args = (rtc_peer, video_queue), daemon = True)
|
||||
encode_loop_thread.start()
|
||||
empty_future : Future[BufferPack] = Future()
|
||||
empty_future.set_result(BufferPack(buffer = bytes(), resolution = (0, 0)))
|
||||
video_queue.put((0.0, empty_future))
|
||||
encode_loop_thread.join(timeout = 5.0)
|
||||
with patch('facefusion.apis.stream_video.rtc.send_video') as send_video_mock:
|
||||
encode_loop_thread = threading.Thread(target = run_video_encode_loop, args = (rtc_peer, video_queue), daemon = True)
|
||||
encode_loop_thread.start()
|
||||
empty_future : Future[BufferPack] = Future()
|
||||
empty_future.set_result(BufferPack(buffer = bytes(), resolution = (0, 0)))
|
||||
video_queue.put((0.0, empty_future))
|
||||
encode_loop_thread.join(timeout = 5.0)
|
||||
|
||||
assert send_video_mock.called
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import pytest
|
||||
|
||||
from facefusion.content_store import calculate_rate, clear, get_hit, set_hit, tick
|
||||
|
||||
|
||||
@pytest.fixture(scope = 'function', autouse = True)
|
||||
def before_each() -> None:
|
||||
clear()
|
||||
|
||||
|
||||
def test_get_hit() -> None:
|
||||
assert get_hit() == 0
|
||||
|
||||
set_hit()
|
||||
|
||||
assert get_hit() == 1
|
||||
|
||||
|
||||
def test_set_hit() -> None:
|
||||
set_hit()
|
||||
set_hit()
|
||||
|
||||
assert get_hit() == 2
|
||||
|
||||
|
||||
def test_get_rate() -> None:
|
||||
assert calculate_rate() == 0.0
|
||||
|
||||
for _ in range(100):
|
||||
tick()
|
||||
|
||||
set_hit()
|
||||
|
||||
assert calculate_rate() == 30.0
|
||||
|
||||
|
||||
def test_clear() -> None:
|
||||
tick()
|
||||
set_hit()
|
||||
clear()
|
||||
|
||||
assert get_hit() == 0
|
||||
assert calculate_rate() == 0.0
|
||||
Reference in New Issue
Block a user