From 83b777ae9fd7ef703a749d0c74163f3c8fac5b0c Mon Sep 17 00:00:00 2001 From: "Dr. Dennis Wittich" Date: Fri, 28 Feb 2025 17:46:06 +0100 Subject: [PATCH] fix outbox test --- learning_loop_node/detector/outbox.py | 2 ++ .../tests/detector/test_client_communication.py | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/learning_loop_node/detector/outbox.py b/learning_loop_node/detector/outbox.py index 640e3c7..06110f8 100644 --- a/learning_loop_node/detector/outbox.py +++ b/learning_loop_node/detector/outbox.py @@ -208,8 +208,10 @@ async def _upload_batch(self, items: List[str]) -> None: if response.status == 200: self.upload_counter += len(items) + self.log.debug('Uploaded %s images', len(items)) for item in items: self._clear_item(item) + self.log.debug('Cleared %s images', len(items)) return if response.status == 422: diff --git a/learning_loop_node/tests/detector/test_client_communication.py b/learning_loop_node/tests/detector/test_client_communication.py index b8b4ee5..162c442 100644 --- a/learning_loop_node/tests/detector/test_client_communication.py +++ b/learning_loop_node/tests/detector/test_client_communication.py @@ -183,8 +183,9 @@ async def test_api_responsive_during_large_upload(test_detector_node: DetectorNo with open(test_image_path, 'rb') as f: image_bytes = f.read() - for _ in range(200): - test_detector_node.outbox.save(image_bytes) + for _ in range(100): + files = {('files', ('test.jpg', image_bytes, 'image/jpeg'))} + requests.post(f'http://localhost:{GLOBALS.detector_port}/upload', files=files, timeout=5) outbox_size_early = len(get_outbox_files(test_detector_node.outbox)) await asyncio.sleep(5) # NOTE: we wait 5 seconds because the continuous upload is running every 5 seconds @@ -193,7 +194,7 @@ async def test_api_responsive_during_large_upload(test_detector_node: DetectorNo response = requests.get(f'http://localhost:{GLOBALS.detector_port}/outbox_mode', timeout=2) assert response.status_code == 200, response.content - await asyncio.sleep(5) + await asyncio.sleep(7) outbox_size_late = len(get_outbox_files(test_detector_node.outbox)) assert outbox_size_late > 0, 'The outbox should not be fully cleared, maybe the node was too fast.' assert outbox_size_early > outbox_size_late, 'The outbox should have been partially emptied.'