Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions tests/test_serverless/test_utils/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand Down
12 changes: 11 additions & 1 deletion tests/test_serverless/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down