From 99bf1a48956a1a8163c27a77ccf2fc0e02d78801 Mon Sep 17 00:00:00 2001 From: DAvid Anyatonwu Date: Tue, 25 Jun 2024 14:28:31 +0100 Subject: [PATCH 01/10] feat(tests): Add automated test for recording functionality --- .gitignore | 1 + tests/openadapt/test_recording.py | 138 ++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 tests/openadapt/test_recording.py diff --git a/.gitignore b/.gitignore index aed42b387..bdbea7229 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ src dist/ build/ +openadapt/error.log diff --git a/tests/openadapt/test_recording.py b/tests/openadapt/test_recording.py new file mode 100644 index 000000000..971528b92 --- /dev/null +++ b/tests/openadapt/test_recording.py @@ -0,0 +1,138 @@ +"""Module for testing the recording module.""" +import multiprocessing +import time +import os +import pytest +from unittest.mock import patch +from openadapt import record, playback, db, config, utils +from openadapt.db import crud +from openadapt.models import Recording + +@pytest.fixture +def setup_db(): + # Setup the database connection and return the session + db_session = crud.get_new_session(read_and_write=True) + yield db_session + db_session.close() + +def test_recording(setup_db): + terminate_processing = multiprocessing.Event() + terminate_recording = multiprocessing.Event() + status_pipe, child_conn = multiprocessing.Pipe() + # conn = multiprocessing.connection.Connection + # signal = conn.recv() + # print(f"Received signal: {signal}") + # signal_type = signal["type"] + # print(f"Signal type: {signal_type}") + + # Start the recording process + record_proc = multiprocessing.Process( + target=record.record, + args=("test task", terminate_processing, terminate_recording, child_conn, False) + ) + record_proc.start() + + # Wait for the recording.started signal + start_time = time.time() + while time.time() - start_time < 30: + if status_pipe.poll(): + message = status_pipe.recv() + if message.get("type") == "record.started": + print(f"Received signal: {message}") + # if signal_type == "record.started": + break + time.sleep(0.1) + else: + pytest.fail("recording.started signal not received within 30 seconds") + + # Stop the recording by emitting the stop sequence + with patch("openadapt.playback.emit_stop_sequence") as mock_emit_stop_sequence: + mock_emit_stop_sequence() + + # Wait for the recording to stop + terminate_processing.set() + record_proc.join() + + # Assert the state of the database + with setup_db as session: + recording = session.query(Recording).filter_by(task_description="test task").first() + assert recording is not None, "Recording not found in the database" + + # Assert the state of the filesystem + video_file_path = utils.get_video_file_path(recording.timestamp) + assert os.path.exists(video_file_path), "Video file not found" + + performance_plot_path = utils.get_performance_plot_file_path(recording.timestamp) + assert os.path.exists(performance_plot_path), "Performance plot not found" + +def test_record_functionality(): + # Set up multiprocessing communication + parent_conn, child_conn = multiprocessing.Pipe() + + # Set up termination events + terminate_processing = multiprocessing.Event() + terminate_recording = multiprocessing.Event() + + # Start the recording process + record_process = multiprocessing.Process( + target=record.record, + args=("Test recording", terminate_processing, terminate_recording, child_conn, False) + ) + record_process.start() + + print("Waiting for the 'record.started' signal") + print(f"Parent conn: {parent_conn}") + print(f"Child conn: {child_conn}") + print(f"Parent conn poll: {parent_conn.poll()}") + print(f"Parent conn recv: {parent_conn.recv()}") + print(f"Message: {parent_conn.recv()['type']}") + # Wait for the 'record.started' signal + start_time = time.time() + while time.time() - start_time < 30: # 30 second timeout + if parent_conn.poll(1): # 1 second timeout for poll + print(f"Message: {parent_conn.recv()['type']}") + message = parent_conn.recv() + print(f"Message: {message}") + if message['type'] == 'record.started': + break + else: + pytest.fail("Timed out waiting for 'record.started' signal") + + # Emit stop sequence using playback + keyboard_controller = playback.get_keyboard_controller() + for char in config.STOP_SEQUENCES[0]: + playback.play_key_event( + playback.create_key_event("press", char), + keyboard_controller + ) + playback.play_key_event( + playback.create_key_event("release", char), + keyboard_controller + ) + + # Wait for the recording to stop + terminate_recording.wait(timeout=30) + if not terminate_recording.is_set(): + pytest.fail("Recording did not stop within the expected time") + + # Clean up the recording process + record_process.join(timeout=5) + if record_process.is_alive(): + record_process.terminate() + + # Assert database state + with crud.get_new_session() as session: + recording = session.query(Recording).order_by(Recording.id.desc()).first() + assert recording is not None, "No recording was created in the database" + assert recording.task_description == "Test recording" + + # Assert filesystem state + video_path = utils.get_video_file_path(recording.timestamp) + assert os.path.exists(video_path), f"Video file not found at {video_path}" + + performance_plot_path = utils.get_performance_plot_file_path(recording.timestamp) + assert os.path.exists(performance_plot_path), f"Performance plot not found at {performance_plot_path}" + +if __name__ == "__main__": + pytest.main([__file__]) + From c0fcd22389f4e8c7a3644dd8f4666f231c1c7428 Mon Sep 17 00:00:00 2001 From: David Anyatonwu Date: Fri, 5 Jul 2024 09:43:18 +0100 Subject: [PATCH 02/10] fix(recording): Improve logging and error handling for recording process --- tests/openadapt/test_recording.py | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/tests/openadapt/test_recording.py b/tests/openadapt/test_recording.py index 971528b92..7d2002924 100644 --- a/tests/openadapt/test_recording.py +++ b/tests/openadapt/test_recording.py @@ -7,6 +7,9 @@ from openadapt import record, playback, db, config, utils from openadapt.db import crud from openadapt.models import Recording +from loguru import logger + +RECORD_STARTED_TIMEOUT = 30 # seconds @pytest.fixture def setup_db(): @@ -19,11 +22,6 @@ def test_recording(setup_db): terminate_processing = multiprocessing.Event() terminate_recording = multiprocessing.Event() status_pipe, child_conn = multiprocessing.Pipe() - # conn = multiprocessing.connection.Connection - # signal = conn.recv() - # print(f"Received signal: {signal}") - # signal_type = signal["type"] - # print(f"Signal type: {signal_type}") # Start the recording process record_proc = multiprocessing.Process( @@ -38,8 +36,7 @@ def test_recording(setup_db): if status_pipe.poll(): message = status_pipe.recv() if message.get("type") == "record.started": - print(f"Received signal: {message}") - # if signal_type == "record.started": + logger.info(f"Received signal: {message}") break time.sleep(0.1) else: @@ -80,19 +77,19 @@ def test_record_functionality(): ) record_process.start() - print("Waiting for the 'record.started' signal") - print(f"Parent conn: {parent_conn}") - print(f"Child conn: {child_conn}") - print(f"Parent conn poll: {parent_conn.poll()}") - print(f"Parent conn recv: {parent_conn.recv()}") - print(f"Message: {parent_conn.recv()['type']}") + logger.info("Waiting for the 'record.started' signal") + logger.info(f"Parent conn: {parent_conn}") + logger.info(f"Child conn: {child_conn}") + logger.info(f"Parent conn poll: {parent_conn.poll()}") + logger.info(f"Parent conn recv: {parent_conn.recv()}") + logger.info(f"Message: {parent_conn.recv()['type']}") # Wait for the 'record.started' signal start_time = time.time() - while time.time() - start_time < 30: # 30 second timeout + while time.time() - start_time < RECORD_STARTED_TIMEOUT: if parent_conn.poll(1): # 1 second timeout for poll - print(f"Message: {parent_conn.recv()['type']}") + logger.info(f"Message: {parent_conn.recv()['type']}") message = parent_conn.recv() - print(f"Message: {message}") + logger.info(f"Message: {message}") if message['type'] == 'record.started': break else: From ff5a436326ae3622e34f11ca302910787236161f Mon Sep 17 00:00:00 2001 From: David Anyatonwu <51977119+onyedikachi-david@users.noreply.github.com> Date: Fri, 5 Jul 2024 22:04:37 +0100 Subject: [PATCH 03/10] use const for record started timeout Co-authored-by: Richard Abrich --- tests/openadapt/test_recording.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/openadapt/test_recording.py b/tests/openadapt/test_recording.py index 7d2002924..25d3e488d 100644 --- a/tests/openadapt/test_recording.py +++ b/tests/openadapt/test_recording.py @@ -108,7 +108,7 @@ def test_record_functionality(): ) # Wait for the recording to stop - terminate_recording.wait(timeout=30) + terminate_recording.wait(timeout=RECORD_STARTED_TIMEOUT) if not terminate_recording.is_set(): pytest.fail("Recording did not stop within the expected time") From 3b774e9ab5ff9a8f555f5a794f780bb85aeff59f Mon Sep 17 00:00:00 2001 From: David Anyatonwu <51977119+onyedikachi-david@users.noreply.github.com> Date: Fri, 5 Jul 2024 22:06:12 +0100 Subject: [PATCH 04/10] use const for record started timeout Co-authored-by: Richard Abrich --- tests/openadapt/test_recording.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/openadapt/test_recording.py b/tests/openadapt/test_recording.py index 25d3e488d..7f1d6dddc 100644 --- a/tests/openadapt/test_recording.py +++ b/tests/openadapt/test_recording.py @@ -32,7 +32,7 @@ def test_recording(setup_db): # Wait for the recording.started signal start_time = time.time() - while time.time() - start_time < 30: + while time.time() - start_time < RECORD_STARTED_TIMEOUT: if status_pipe.poll(): message = status_pipe.recv() if message.get("type") == "record.started": From 52ca7c119d35d2ae95f91b4a1da14197851b5f29 Mon Sep 17 00:00:00 2001 From: David Anyatonwu <51977119+onyedikachi-david@users.noreply.github.com> Date: Fri, 5 Jul 2024 22:06:37 +0100 Subject: [PATCH 05/10] use const for record started timeout Co-authored-by: Richard Abrich --- tests/openadapt/test_recording.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/openadapt/test_recording.py b/tests/openadapt/test_recording.py index 7f1d6dddc..f7c548499 100644 --- a/tests/openadapt/test_recording.py +++ b/tests/openadapt/test_recording.py @@ -40,7 +40,7 @@ def test_recording(setup_db): break time.sleep(0.1) else: - pytest.fail("recording.started signal not received within 30 seconds") + pytest.fail(f"recording.started signal not received within {RECORD_STARTED_TIMEOUT} seconds") # Stop the recording by emitting the stop sequence with patch("openadapt.playback.emit_stop_sequence") as mock_emit_stop_sequence: From 818b2ab89f61435fab8665e84d8178bc40f7c948 Mon Sep 17 00:00:00 2001 From: David Anyatonwu Date: Fri, 5 Jul 2024 22:15:53 +0100 Subject: [PATCH 06/10] removed unnecessary timeout --- tests/openadapt/test_recording.py | 62 ++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/tests/openadapt/test_recording.py b/tests/openadapt/test_recording.py index f7c548499..127aec295 100644 --- a/tests/openadapt/test_recording.py +++ b/tests/openadapt/test_recording.py @@ -1,4 +1,5 @@ """Module for testing the recording module.""" + import multiprocessing import time import os @@ -11,6 +12,7 @@ RECORD_STARTED_TIMEOUT = 30 # seconds + @pytest.fixture def setup_db(): # Setup the database connection and return the session @@ -18,6 +20,7 @@ def setup_db(): yield db_session db_session.close() + def test_recording(setup_db): terminate_processing = multiprocessing.Event() terminate_recording = multiprocessing.Event() @@ -26,7 +29,13 @@ def test_recording(setup_db): # Start the recording process record_proc = multiprocessing.Process( target=record.record, - args=("test task", terminate_processing, terminate_recording, child_conn, False) + args=( + "test task", + terminate_processing, + terminate_recording, + child_conn, + False, + ), ) record_proc.start() @@ -40,7 +49,9 @@ def test_recording(setup_db): break time.sleep(0.1) else: - pytest.fail(f"recording.started signal not received within {RECORD_STARTED_TIMEOUT} seconds") + pytest.fail( + f"recording.started signal not received within {RECORD_STARTED_TIMEOUT} seconds" + ) # Stop the recording by emitting the stop sequence with patch("openadapt.playback.emit_stop_sequence") as mock_emit_stop_sequence: @@ -52,7 +63,9 @@ def test_recording(setup_db): # Assert the state of the database with setup_db as session: - recording = session.query(Recording).filter_by(task_description="test task").first() + recording = ( + session.query(Recording).filter_by(task_description="test task").first() + ) assert recording is not None, "Recording not found in the database" # Assert the state of the filesystem @@ -62,21 +75,28 @@ def test_recording(setup_db): performance_plot_path = utils.get_performance_plot_file_path(recording.timestamp) assert os.path.exists(performance_plot_path), "Performance plot not found" + def test_record_functionality(): # Set up multiprocessing communication parent_conn, child_conn = multiprocessing.Pipe() - + # Set up termination events terminate_processing = multiprocessing.Event() terminate_recording = multiprocessing.Event() - + # Start the recording process record_process = multiprocessing.Process( target=record.record, - args=("Test recording", terminate_processing, terminate_recording, child_conn, False) + args=( + "Test recording", + terminate_processing, + terminate_recording, + child_conn, + False, + ), ) record_process.start() - + logger.info("Waiting for the 'record.started' signal") logger.info(f"Parent conn: {parent_conn}") logger.info(f"Child conn: {child_conn}") @@ -90,46 +110,46 @@ def test_record_functionality(): logger.info(f"Message: {parent_conn.recv()['type']}") message = parent_conn.recv() logger.info(f"Message: {message}") - if message['type'] == 'record.started': + if message["type"] == "record.started": break else: pytest.fail("Timed out waiting for 'record.started' signal") - + # Emit stop sequence using playback keyboard_controller = playback.get_keyboard_controller() for char in config.STOP_SEQUENCES[0]: playback.play_key_event( - playback.create_key_event("press", char), - keyboard_controller + playback.create_key_event("press", char), keyboard_controller ) playback.play_key_event( - playback.create_key_event("release", char), - keyboard_controller + playback.create_key_event("release", char), keyboard_controller ) - + # Wait for the recording to stop terminate_recording.wait(timeout=RECORD_STARTED_TIMEOUT) if not terminate_recording.is_set(): pytest.fail("Recording did not stop within the expected time") - + # Clean up the recording process - record_process.join(timeout=5) + record_process.join() if record_process.is_alive(): record_process.terminate() - + # Assert database state with crud.get_new_session() as session: recording = session.query(Recording).order_by(Recording.id.desc()).first() assert recording is not None, "No recording was created in the database" assert recording.task_description == "Test recording" - + # Assert filesystem state video_path = utils.get_video_file_path(recording.timestamp) assert os.path.exists(video_path), f"Video file not found at {video_path}" - + performance_plot_path = utils.get_performance_plot_file_path(recording.timestamp) - assert os.path.exists(performance_plot_path), f"Performance plot not found at {performance_plot_path}" + assert os.path.exists( + performance_plot_path + ), f"Performance plot not found at {performance_plot_path}" + if __name__ == "__main__": pytest.main([__file__]) - From bbec18929db3990cba2cde1772aa5dbddfd5d412 Mon Sep 17 00:00:00 2001 From: David Anyatonwu Date: Tue, 17 Sep 2024 13:19:16 +0100 Subject: [PATCH 07/10] fixed: now works after some refactor Signed-off-by: David Anyatonwu --- tests/openadapt/test_recording.py | 192 ++++++++++++------------------ 1 file changed, 79 insertions(+), 113 deletions(-) diff --git a/tests/openadapt/test_recording.py b/tests/openadapt/test_recording.py index 127aec295..38f2b40df 100644 --- a/tests/openadapt/test_recording.py +++ b/tests/openadapt/test_recording.py @@ -4,13 +4,13 @@ import time import os import pytest -from unittest.mock import patch -from openadapt import record, playback, db, config, utils +from openadapt import record, playback, utils, video +from openadapt.config import config from openadapt.db import crud -from openadapt.models import Recording +from openadapt.models import Recording, ActionEvent from loguru import logger -RECORD_STARTED_TIMEOUT = 30 # seconds +RECORD_STARTED_TIMEOUT = 120 # Increased timeout to 120 seconds @pytest.fixture @@ -21,62 +21,9 @@ def setup_db(): db_session.close() -def test_recording(setup_db): - terminate_processing = multiprocessing.Event() - terminate_recording = multiprocessing.Event() - status_pipe, child_conn = multiprocessing.Pipe() - - # Start the recording process - record_proc = multiprocessing.Process( - target=record.record, - args=( - "test task", - terminate_processing, - terminate_recording, - child_conn, - False, - ), - ) - record_proc.start() - - # Wait for the recording.started signal - start_time = time.time() - while time.time() - start_time < RECORD_STARTED_TIMEOUT: - if status_pipe.poll(): - message = status_pipe.recv() - if message.get("type") == "record.started": - logger.info(f"Received signal: {message}") - break - time.sleep(0.1) - else: - pytest.fail( - f"recording.started signal not received within {RECORD_STARTED_TIMEOUT} seconds" - ) - - # Stop the recording by emitting the stop sequence - with patch("openadapt.playback.emit_stop_sequence") as mock_emit_stop_sequence: - mock_emit_stop_sequence() - - # Wait for the recording to stop - terminate_processing.set() - record_proc.join() - - # Assert the state of the database - with setup_db as session: - recording = ( - session.query(Recording).filter_by(task_description="test task").first() - ) - assert recording is not None, "Recording not found in the database" - - # Assert the state of the filesystem - video_file_path = utils.get_video_file_path(recording.timestamp) - assert os.path.exists(video_file_path), "Video file not found" - - performance_plot_path = utils.get_performance_plot_file_path(recording.timestamp) - assert os.path.exists(performance_plot_path), "Performance plot not found" - - def test_record_functionality(): + logger.info("Starting test_record_functionality") + # Set up multiprocessing communication parent_conn, child_conn = multiprocessing.Pipe() @@ -95,60 +42,79 @@ def test_record_functionality(): False, ), ) - record_process.start() - - logger.info("Waiting for the 'record.started' signal") - logger.info(f"Parent conn: {parent_conn}") - logger.info(f"Child conn: {child_conn}") - logger.info(f"Parent conn poll: {parent_conn.poll()}") - logger.info(f"Parent conn recv: {parent_conn.recv()}") - logger.info(f"Message: {parent_conn.recv()['type']}") - # Wait for the 'record.started' signal - start_time = time.time() - while time.time() - start_time < RECORD_STARTED_TIMEOUT: - if parent_conn.poll(1): # 1 second timeout for poll - logger.info(f"Message: {parent_conn.recv()['type']}") - message = parent_conn.recv() - logger.info(f"Message: {message}") - if message["type"] == "record.started": - break - else: - pytest.fail("Timed out waiting for 'record.started' signal") - - # Emit stop sequence using playback - keyboard_controller = playback.get_keyboard_controller() - for char in config.STOP_SEQUENCES[0]: - playback.play_key_event( - playback.create_key_event("press", char), keyboard_controller - ) - playback.play_key_event( - playback.create_key_event("release", char), keyboard_controller - ) - - # Wait for the recording to stop - terminate_recording.wait(timeout=RECORD_STARTED_TIMEOUT) - if not terminate_recording.is_set(): - pytest.fail("Recording did not stop within the expected time") - - # Clean up the recording process - record_process.join() - if record_process.is_alive(): - record_process.terminate() - - # Assert database state - with crud.get_new_session() as session: - recording = session.query(Recording).order_by(Recording.id.desc()).first() - assert recording is not None, "No recording was created in the database" - assert recording.task_description == "Test recording" - - # Assert filesystem state - video_path = utils.get_video_file_path(recording.timestamp) - assert os.path.exists(video_path), f"Video file not found at {video_path}" - - performance_plot_path = utils.get_performance_plot_file_path(recording.timestamp) - assert os.path.exists( - performance_plot_path - ), f"Performance plot not found at {performance_plot_path}" + + try: + record_process.start() + logger.info("Recording process started") + + # Wait for the 'record.started' signal + start_time = time.time() + while time.time() - start_time < RECORD_STARTED_TIMEOUT: + if parent_conn.poll(1): # 1 second timeout for poll + message = parent_conn.recv() + logger.info(f"Received message: {message}") + if message["type"] == "record.started": + logger.info("Received 'record.started' signal") + break + else: + logger.debug("No message received, continuing to wait...") + else: + logger.error("Timed out waiting for 'record.started' signal") + pytest.fail("Timed out waiting for 'record.started' signal") + + # Wait a short time to ensure some data is recorded + time.sleep(5) + + logger.info("Stopping the recording") + terminate_processing.set() # Signal the recording to stop + + # Wait for the recording to stop + logger.info("Waiting for recording to stop") + terminate_recording.wait(timeout=RECORD_STARTED_TIMEOUT) + if not terminate_recording.is_set(): + logger.error("Recording did not stop within the expected time") + pytest.fail("Recording did not stop within the expected time") + + logger.info("Recording stopped successfully") + + # Assert database state + with crud.get_new_session(read_and_write=True) as session: + recording = session.query(Recording).order_by(Recording.id.desc()).first() + assert recording is not None, "No recording was created in the database" + assert recording.task_description == "Test recording" + logger.info("Database assertions passed") + + # Assert filesystem state + video_path = video.get_video_file_path(recording.timestamp) + if not os.path.exists(video_path): + logger.warning(f"Video file not found at {video_path}") + # Check if video recording is enabled in the configuration + if config.RECORD_VIDEO: + logger.error("Video recording is enabled but no video file was created") + else: + logger.info("Video recording is disabled in the configuration") + else: + logger.info(f"Video file found at {video_path}") + + performance_plot_path = utils.get_performance_plot_file_path(recording.timestamp) + if not os.path.exists(performance_plot_path): + logger.warning(f"Performance plot not found at {performance_plot_path}") + else: + logger.info(f"Performance plot found at {performance_plot_path}") + + logger.info("Filesystem assertions completed") + + except Exception as e: + logger.exception(f"An error occurred during the test: {e}") + raise + + finally: + # Clean up the recording process + if record_process.is_alive(): + logger.info("Terminating recording process") + record_process.terminate() + record_process.join() + logger.info("Test completed") if __name__ == "__main__": From 33b9cebd888a1df0626f127c1ec6bde95d859291 Mon Sep 17 00:00:00 2001 From: David Anyatonwu Date: Tue, 17 Sep 2024 15:11:56 +0100 Subject: [PATCH 08/10] chore: increase record timeout and added assert Signed-off-by: David Anyatonwu --- tests/openadapt/test_recording.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/openadapt/test_recording.py b/tests/openadapt/test_recording.py index 38f2b40df..ab60cdb29 100644 --- a/tests/openadapt/test_recording.py +++ b/tests/openadapt/test_recording.py @@ -10,7 +10,7 @@ from openadapt.models import Recording, ActionEvent from loguru import logger -RECORD_STARTED_TIMEOUT = 120 # Increased timeout to 120 seconds +RECORD_STARTED_TIMEOUT = 360 # Increased timeout to 120 seconds @pytest.fixture @@ -86,23 +86,23 @@ def test_record_functionality(): # Assert filesystem state video_path = video.get_video_file_path(recording.timestamp) - if not os.path.exists(video_path): - logger.warning(f"Video file not found at {video_path}") - # Check if video recording is enabled in the configuration - if config.RECORD_VIDEO: - logger.error("Video recording is enabled but no video file was created") - else: - logger.info("Video recording is disabled in the configuration") - else: + if config.RECORD_VIDEO: + assert os.path.exists(video_path), f"Video file not found at {video_path}" logger.info(f"Video file found at {video_path}") + else: + logger.info("Video recording is disabled in the configuration") performance_plot_path = utils.get_performance_plot_file_path(recording.timestamp) - if not os.path.exists(performance_plot_path): - logger.warning(f"Performance plot not found at {performance_plot_path}") - else: - logger.info(f"Performance plot found at {performance_plot_path}") + assert os.path.exists(performance_plot_path), f"Performance plot not found at {performance_plot_path}" + logger.info(f"Performance plot found at {performance_plot_path}") + + # Assert that at least one action event was recorded + with crud.get_new_session(read_and_write=True) as session: + action_events = crud.get_action_events(session, recording) + assert len(action_events) > 0, "No action events were recorded" + logger.info(f"Number of action events recorded: {len(action_events)}") - logger.info("Filesystem assertions completed") + logger.info("All assertions passed") except Exception as e: logger.exception(f"An error occurred during the test: {e}") From 160d4fc24ec907d62778360b0c77e08a7c78cabe Mon Sep 17 00:00:00 2001 From: David Anyatonwu Date: Tue, 17 Sep 2024 15:30:21 +0100 Subject: [PATCH 09/10] chore: comment on increased timeout Signed-off-by: David Anyatonwu --- tests/openadapt/test_recording.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/openadapt/test_recording.py b/tests/openadapt/test_recording.py index ab60cdb29..5c8423472 100644 --- a/tests/openadapt/test_recording.py +++ b/tests/openadapt/test_recording.py @@ -10,7 +10,7 @@ from openadapt.models import Recording, ActionEvent from loguru import logger -RECORD_STARTED_TIMEOUT = 360 # Increased timeout to 120 seconds +RECORD_STARTED_TIMEOUT = 360 # Increased timeout to 6 minutes @pytest.fixture From 03ac124e37c252d9bad0068a94e1e301e7b36cfe Mon Sep 17 00:00:00 2001 From: David Anyatonwu <51977119+onyedikachi-david@users.noreply.github.com> Date: Sun, 13 Oct 2024 10:36:30 +0100 Subject: [PATCH 10/10] removed unused DB setup function. --- tests/openadapt/test_recording.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/openadapt/test_recording.py b/tests/openadapt/test_recording.py index 5c8423472..404b86fbe 100644 --- a/tests/openadapt/test_recording.py +++ b/tests/openadapt/test_recording.py @@ -13,13 +13,6 @@ RECORD_STARTED_TIMEOUT = 360 # Increased timeout to 6 minutes -@pytest.fixture -def setup_db(): - # Setup the database connection and return the session - db_session = crud.get_new_session(read_and_write=True) - yield db_session - db_session.close() - def test_record_functionality(): logger.info("Starting test_record_functionality")