From b898f155b2c4be82822bbff0da4a8f0703a8c660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dean=20Qui=C3=B1anola?= Date: Thu, 18 Jun 2026 10:18:13 -0700 Subject: [PATCH] test: fix two flaky serverless tests Both tests fail intermittently regardless of source changes, blocking make quality-check and CI. - TestRunWorker invoked run_worker -> run_fitness_checks, whose _memory_check probes real host memory and exits when <4GB. Stub run_fitness_checks in asyncSetUp; fitness checks are covered by tests/test_serverless/test_modules/test_fitness/. - test_download_files_from_urls asserted get() call order, but downloads run in parallel threads (executor.map preserves result order, not call order). Assert the set of requested URLs instead. Refs SLS-268 --- tests/test_serverless/test_utils/test_download.py | 12 ++++++++---- tests/test_serverless/test_worker.py | 12 +++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/test_serverless/test_utils/test_download.py b/tests/test_serverless/test_utils/test_download.py index bc04db95..b7533f5c 100644 --- a/tests/test_serverless/test_utils/test_download.py +++ b/tests/test_serverless/test_utils/test_download.py @@ -95,10 +95,14 @@ def test_download_files_from_urls(self, mock_open_file, mock_get, mock_makedirs) self.assertEqual(len(downloaded_files), len(urls)) - for index, url in enumerate(urls): - # Check that the url was called with SyncClientSession.get - self.assertIn(url, mock_get.call_args_list[index][0]) - + # Downloads run in parallel threads, so the order of get() calls is + # non-deterministic; assert the set of requested URLs instead of order. + requested_urls = {call.args[0] for call in mock_get.call_args_list} + self.assertEqual(requested_urls, set(urls)) + + # executor.map preserves input order in results, so downloaded_files + # still aligns positionally with urls. + for index in range(len(urls)): # Check that the file has the correct extension self.assertTrue(downloaded_files[index].endswith(".jpg")) diff --git a/tests/test_serverless/test_worker.py b/tests/test_serverless/test_worker.py index e1fd743f..28544add 100644 --- a/tests/test_serverless/test_worker.py +++ b/tests/test_serverless/test_worker.py @@ -6,7 +6,7 @@ import os import sys from unittest import mock -from unittest.mock import patch, mock_open, Mock, MagicMock +from unittest.mock import patch, mock_open, Mock, MagicMock, AsyncMock from unittest import IsolatedAsyncioTestCase import nest_asyncio @@ -182,6 +182,16 @@ class TestRunWorker(IsolatedAsyncioTestCase): async def asyncSetUp(self): os.environ["RUNPOD_WEBHOOK_GET_JOB"] = "https://test.com" + # Fitness checks probe real host resources (e.g. available memory) and + # exit the process when unmet; they have dedicated coverage in + # tests/test_serverless/test_modules/test_fitness/. Stub them here so + # run_worker tests are deterministic regardless of host state. + fitness_patcher = patch( + "runpod.serverless.worker.run_fitness_checks", new=AsyncMock() + ) + fitness_patcher.start() + self.addCleanup(fitness_patcher.stop) + # Set up the config self.config = { "handler": MagicMock(),