mirror of
https://github.com/facefusion/facefusion.git
synced 2026-09-16 04:25:27 +02:00
convert content store (#1236)
* convert content store * add local_id variables * add local_id variables * fix misconcept of clear() in stores, pass session id to threads
This commit is contained in:
@@ -11,7 +11,8 @@ def is_test_job_file(file_path : str, job_status : JobStatus) -> bool:
|
||||
|
||||
|
||||
def get_test_job_file(file_path : str, job_status : JobStatus) -> str:
|
||||
jobs_path = os.path.join(get_test_jobs_directory(), resolve_local_id())
|
||||
local_id = resolve_local_id()
|
||||
jobs_path = os.path.join(get_test_jobs_directory(), local_id)
|
||||
|
||||
return os.path.join(jobs_path, job_status, file_path)
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ from facefusion.common_helper import is_linux, is_windows
|
||||
from facefusion.download import conditional_download
|
||||
from facefusion.hash_helper import create_hash
|
||||
from facefusion.libraries import datachannel as datachannel_module
|
||||
from facefusion.session_context import set_session_id
|
||||
from facefusion.types import RtcPeer, SessionId, VideoCodec
|
||||
from .assert_helper import get_test_example_file, get_test_examples_directory
|
||||
|
||||
@@ -150,11 +151,14 @@ def test_run_peer_loop(video_codec : VideoCodec, payload_type : int, session_id
|
||||
|
||||
assert rtc_store.has_peer(session_id) is True
|
||||
|
||||
with patch('facefusion.apis.stream_manager.receive_video_frames'):
|
||||
with patch('facefusion.apis.stream_manager.run_video_encode_loop'):
|
||||
thread = threading.Thread(target = run_peer_loop, args = (session_id, rtc_peer), daemon = True)
|
||||
thread.start()
|
||||
thread.join(timeout = 5.0)
|
||||
with patch('facefusion.apis.stream_manager.ThreadPoolExecutor') as thread_pool_executor_mock:
|
||||
with patch('facefusion.apis.stream_manager.receive_video_frames'):
|
||||
with patch('facefusion.apis.stream_manager.run_video_encode_loop'):
|
||||
thread = threading.Thread(target = run_peer_loop, args = (session_id, rtc_peer), daemon = True)
|
||||
thread.start()
|
||||
thread.join(timeout = 5.0)
|
||||
|
||||
thread_pool_executor_mock.assert_called_once_with(max_workers = 8, initializer = set_session_id, initargs = (session_id,))
|
||||
|
||||
assert rtc_store.has_peer(session_id) is False
|
||||
|
||||
|
||||
@@ -34,7 +34,8 @@ def before_all() -> None:
|
||||
|
||||
@pytest.fixture(scope = 'function', autouse = True)
|
||||
def before_each() -> None:
|
||||
jobs_path = os.path.join(get_test_jobs_directory(), resolve_local_id())
|
||||
local_id = resolve_local_id()
|
||||
jobs_path = os.path.join(get_test_jobs_directory(), local_id)
|
||||
|
||||
clear_jobs(get_test_jobs_directory())
|
||||
init_jobs(jobs_path)
|
||||
|
||||
@@ -34,7 +34,8 @@ def before_all() -> None:
|
||||
|
||||
@pytest.fixture(scope = 'function', autouse = True)
|
||||
def before_each() -> None:
|
||||
jobs_path = os.path.join(get_test_jobs_directory(), resolve_local_id())
|
||||
local_id = resolve_local_id()
|
||||
jobs_path = os.path.join(get_test_jobs_directory(), local_id)
|
||||
|
||||
clear_jobs(get_test_jobs_directory())
|
||||
init_jobs(jobs_path)
|
||||
|
||||
@@ -1,11 +1,29 @@
|
||||
import pytest
|
||||
|
||||
from facefusion.content_store import calculate_rate, clear, get_hit, set_hit, tick
|
||||
from facefusion import session_context
|
||||
from facefusion.content_store import calculate_rate, clear, get_hit, init, set_hit, tick
|
||||
|
||||
|
||||
@pytest.fixture(scope = 'function', autouse = True)
|
||||
def before_each() -> None:
|
||||
clear()
|
||||
local_id = session_context.resolve_local_id()
|
||||
|
||||
session_context.set_session_id(local_id)
|
||||
init()
|
||||
|
||||
|
||||
def test_init() -> None:
|
||||
local_id = session_context.resolve_local_id()
|
||||
|
||||
session_context.set_session_id('session-a')
|
||||
init()
|
||||
set_hit()
|
||||
|
||||
assert get_hit() == 1
|
||||
|
||||
session_context.set_session_id(local_id)
|
||||
|
||||
assert get_hit() == 0
|
||||
|
||||
|
||||
def test_get_hit() -> None:
|
||||
@@ -23,7 +41,7 @@ def test_set_hit() -> None:
|
||||
assert get_hit() == 2
|
||||
|
||||
|
||||
def test_get_rate() -> None:
|
||||
def test_calculate_rate() -> None:
|
||||
assert calculate_rate() == 0.0
|
||||
|
||||
for _ in range(100):
|
||||
|
||||
@@ -1,61 +1,60 @@
|
||||
import pytest
|
||||
|
||||
from facefusion.process_manager import clear_process_state, end, get_process_state, init_process_state, is_pending, is_processing, is_stopping, set_process_state, start, stop
|
||||
from facefusion.session_context import set_session_id
|
||||
from facefusion import session_context
|
||||
from facefusion.process_manager import clear, end, get_state, init, is_pending, is_processing, is_stopping, set_state, start, stop
|
||||
|
||||
|
||||
@pytest.fixture(scope = 'function', autouse = True)
|
||||
def before_each() -> None:
|
||||
set_session_id('session-a')
|
||||
clear_process_state()
|
||||
set_session_id('session-b')
|
||||
clear_process_state()
|
||||
set_session_id('session-a')
|
||||
session_context.set_session_id('session-a')
|
||||
clear()
|
||||
session_context.set_session_id('session-b')
|
||||
clear()
|
||||
session_context.set_session_id('session-a')
|
||||
|
||||
|
||||
def test_init_process_state() -> None:
|
||||
assert get_process_state() is None
|
||||
def test_init() -> None:
|
||||
set_state('processing')
|
||||
init()
|
||||
|
||||
init_process_state()
|
||||
|
||||
assert get_process_state() == 'pending'
|
||||
assert get_state() == 'pending'
|
||||
|
||||
|
||||
def test_get_process_state() -> None:
|
||||
set_process_state('processing')
|
||||
set_session_id('session-b')
|
||||
set_process_state('stopping')
|
||||
def test_get_state() -> None:
|
||||
set_state('processing')
|
||||
session_context.set_session_id('session-b')
|
||||
set_state('stopping')
|
||||
|
||||
assert get_process_state() == 'stopping'
|
||||
assert get_state() == 'stopping'
|
||||
|
||||
set_session_id('session-a')
|
||||
session_context.set_session_id('session-a')
|
||||
|
||||
assert get_process_state() == 'processing'
|
||||
|
||||
|
||||
def test_clear_process_state() -> None:
|
||||
set_process_state('processing')
|
||||
clear_process_state()
|
||||
|
||||
assert get_process_state() is None
|
||||
assert get_state() == 'processing'
|
||||
|
||||
|
||||
def test_start() -> None:
|
||||
set_process_state('pending')
|
||||
set_state('pending')
|
||||
start()
|
||||
|
||||
assert is_processing()
|
||||
|
||||
|
||||
def test_stop() -> None:
|
||||
set_process_state('processing')
|
||||
set_state('processing')
|
||||
stop()
|
||||
|
||||
assert is_stopping()
|
||||
|
||||
|
||||
def test_end() -> None:
|
||||
set_process_state('processing')
|
||||
set_state('processing')
|
||||
end()
|
||||
|
||||
assert is_pending()
|
||||
|
||||
|
||||
def test_clear() -> None:
|
||||
set_state('processing')
|
||||
clear()
|
||||
|
||||
assert get_state() == 'pending'
|
||||
|
||||
@@ -5,7 +5,8 @@ from facefusion.session_context import get_session_id, resolve_local_id, set_ses
|
||||
|
||||
@pytest.fixture(scope = 'function', autouse = True)
|
||||
def before_each() -> None:
|
||||
set_session_id(resolve_local_id())
|
||||
local_id = resolve_local_id()
|
||||
set_session_id(local_id)
|
||||
|
||||
|
||||
def test_get_session_id() -> None:
|
||||
|
||||
Reference in New Issue
Block a user