Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
e1b8e5d
Update CI-tests.yml
justinmerrell Aug 28, 2023
2a917cd
Update CI-pylint.yml
justinmerrell Aug 28, 2023
b4585d3
Update test_asyncio_runner.py
justinmerrell Aug 28, 2023
ef0ce1f
Update test_asyncio_runner.py
justinmerrell Aug 28, 2023
bd727f9
Update test_asyncio_runner.py
justinmerrell Aug 28, 2023
25047db
Update test_worker.py
justinmerrell Aug 28, 2023
4868f19
fix: async tests
justinmerrell Aug 28, 2023
8ec29a8
Update test_http.py
justinmerrell Aug 28, 2023
d4e5120
Update test_http.py
justinmerrell Aug 28, 2023
5d35b6b
Update test_http.py
justinmerrell Aug 28, 2023
1b8f628
Update test_http.py
justinmerrell Aug 28, 2023
0f29407
Update test_http.py
justinmerrell Aug 28, 2023
fcfa49c
Update test_http.py
justinmerrell Aug 28, 2023
19fbcaf
Update test_http.py
justinmerrell Aug 28, 2023
c666937
Update test_http.py
justinmerrell Aug 28, 2023
7e6db97
Update test_http.py
justinmerrell Aug 28, 2023
7a0a6e0
Update test_http.py
justinmerrell Aug 28, 2023
955659e
Update test_http.py
justinmerrell Aug 28, 2023
96c206a
fix: job handling
justinmerrell Aug 28, 2023
800a29f
Update rp_http.py
justinmerrell Aug 28, 2023
79e8960
Update test_http.py
justinmerrell Aug 28, 2023
ad326e5
Update rp_http.py
justinmerrell Aug 28, 2023
9d12cb7
Update test_http.py
justinmerrell Aug 28, 2023
e430565
Update rp_http.py
justinmerrell Aug 28, 2023
fde8325
Update test_http.py
justinmerrell Aug 28, 2023
0610c41
Update test_http.py
justinmerrell Aug 28, 2023
58a6a8c
Update test_http.py
justinmerrell Aug 28, 2023
c18ba0c
Update test_http.py
justinmerrell Aug 28, 2023
0b2daa5
Update test_http.py
justinmerrell Aug 28, 2023
c852e53
Update test_http.py
justinmerrell Aug 28, 2023
ec11bfa
Update test_http.py
justinmerrell Aug 28, 2023
1d1d058
Update test_http.py
justinmerrell Aug 28, 2023
7a53bbe
Update rp_http.py
justinmerrell Aug 28, 2023
24124ef
fix: better error catching
justinmerrell Aug 28, 2023
9fcc7f1
Update test_http.py
justinmerrell Aug 28, 2023
79ac84f
Update test_http.py
justinmerrell Aug 28, 2023
262816b
linting
justinmerrell Aug 28, 2023
462caa9
asyncmock
justinmerrell Aug 29, 2023
ad11c63
Update test_http.py
justinmerrell Aug 29, 2023
e90aa1a
Update test_http.py
justinmerrell Aug 29, 2023
1696b02
Update test_http.py
justinmerrell Aug 29, 2023
abc3e41
Update rp_http.py
justinmerrell Aug 29, 2023
97adc52
Update test_http.py
justinmerrell Aug 29, 2023
b857fcd
Update test_http.py
justinmerrell Aug 29, 2023
2cda3c1
Update test_http.py
justinmerrell Aug 29, 2023
5175849
Update rp_http.py
justinmerrell Aug 29, 2023
5de00e2
Update test_http.py
justinmerrell Aug 29, 2023
184946f
wip: remove broad exception
justinmerrell Aug 29, 2023
48036af
Update test_http.py
justinmerrell Aug 29, 2023
e1e2738
Update test_http.py
justinmerrell Aug 29, 2023
93732f3
Update test_http.py
justinmerrell Aug 29, 2023
1761733
use aiohttp_retry
justinmerrell Aug 29, 2023
a9e8752
fix tests
justinmerrell Aug 29, 2023
b10bcf1
fix: expand tests
justinmerrell Aug 29, 2023
f2a6c63
Update rp_http.py
justinmerrell Aug 29, 2023
1a154d5
Update test_http.py
justinmerrell Aug 29, 2023
88a7a62
Update test_http.py
justinmerrell Aug 29, 2023
e8f9cf6
fix: tests
justinmerrell Aug 29, 2023
30328ae
Update test_http.py
justinmerrell Aug 29, 2023
8f09971
Update test_http.py
justinmerrell Aug 29, 2023
19f5d0e
Update rp_http.py
justinmerrell Aug 29, 2023
a184207
Update rp_http.py
justinmerrell Aug 29, 2023
b968017
Update test_http.py
justinmerrell Aug 29, 2023
8b55b10
fix: return status
justinmerrell Aug 29, 2023
295a02a
Update test_http.py
justinmerrell Aug 29, 2023
110f688
Update test_http.py
justinmerrell Aug 29, 2023
c9da53a
Update test_http.py
justinmerrell Aug 29, 2023
07d246c
Update test_http.py
justinmerrell Aug 29, 2023
244b4f5
Update test_http.py
justinmerrell Aug 29, 2023
aaec7ab
Update test_http.py
justinmerrell Aug 29, 2023
4fcaf00
Update test_http.py
justinmerrell Aug 29, 2023
ae4f42c
Update test_http.py
justinmerrell Aug 29, 2023
c92ff31
Update test_http.py
justinmerrell Aug 29, 2023
2112e68
Update test_http.py
justinmerrell Aug 29, 2023
95da9a0
Update test_http.py
justinmerrell Aug 29, 2023
86f3853
Update test_http.py
justinmerrell Aug 29, 2023
333ae27
Update test_http.py
justinmerrell Aug 29, 2023
3728851
Update test_http.py
justinmerrell Aug 29, 2023
b8484b6
Update test_http.py
justinmerrell Aug 29, 2023
3bb266a
fix: sending result
justinmerrell Aug 29, 2023
00066de
test cleanup
justinmerrell Aug 29, 2023
0e9b49b
fix: tests
justinmerrell Aug 29, 2023
b98b9c3
Update test_http.py
justinmerrell Aug 29, 2023
1854529
Update test_http.py
justinmerrell Aug 29, 2023
d7e425e
Update test_http.py
justinmerrell Aug 29, 2023
dd5451c
Update test_http.py
justinmerrell Aug 29, 2023
afd1cea
Update test_http.py
justinmerrell Aug 29, 2023
8bafa58
Update test_http.py
justinmerrell Aug 29, 2023
a4401b5
fix: remove retry
justinmerrell Aug 29, 2023
61ba04a
Update test_http.py
justinmerrell Aug 29, 2023
9a5a8fd
Update test_http.py
justinmerrell Aug 29, 2023
440ade2
Update test_http.py
justinmerrell Aug 29, 2023
90afc9d
Update test_http.py
justinmerrell Aug 29, 2023
c2ac9f8
Update test_http.py
justinmerrell Aug 29, 2023
07b7ad6
Update test_http.py
justinmerrell Aug 29, 2023
a9f37e8
Update test_http.py
justinmerrell Aug 29, 2023
a36d806
Update test_http.py
justinmerrell Aug 29, 2023
85345e0
Update test_http.py
justinmerrell Aug 29, 2023
89d7a4d
Update test_http.py
justinmerrell Aug 29, 2023
9fec432
Update test_http.py
justinmerrell Aug 29, 2023
e0bab4b
Update test_http.py
justinmerrell Aug 29, 2023
be51b8a
Update test_http.py
justinmerrell Aug 29, 2023
6d5371c
Update test_http.py
justinmerrell Aug 29, 2023
e5e6237
Update test_http.py
justinmerrell Aug 29, 2023
e98bdf2
Update test_http.py
justinmerrell Aug 29, 2023
0139463
Update test_http.py
justinmerrell Aug 29, 2023
be02fdd
Update test_http.py
justinmerrell Aug 29, 2023
8c87b07
Update test_http.py
justinmerrell Aug 29, 2023
7f3d5e7
Update test_http.py
justinmerrell Aug 29, 2023
846faee
Update test_http.py
justinmerrell Aug 29, 2023
a6e46d6
Update test_http.py
justinmerrell Aug 29, 2023
2b4b206
Update test_http.py
justinmerrell Aug 29, 2023
18057e0
Update test_http.py
justinmerrell Aug 29, 2023
1d559a2
Update test_http.py
justinmerrell Aug 29, 2023
caed616
Update test_http.py
justinmerrell Aug 29, 2023
6b90aba
Update test_http.py
justinmerrell Aug 29, 2023
0d467a8
Update test_http.py
justinmerrell Aug 29, 2023
255be4d
Update test_http.py
justinmerrell Aug 29, 2023
db91246
Update rp_http.py
justinmerrell Aug 29, 2023
52b9054
Update test_http.py
justinmerrell Aug 29, 2023
47d89f7
Update rp_http.py
justinmerrell Aug 29, 2023
f5f8f87
Update test_http.py
justinmerrell Aug 29, 2023
dd8a3fe
Update test_http.py
justinmerrell Aug 29, 2023
7c7c5da
teardown environ
justinmerrell Aug 29, 2023
f967623
Update CI-tests.yml
justinmerrell Aug 29, 2023
a6ceda7
Update rp_http.py
justinmerrell Aug 29, 2023
7587946
Update test_http.py
justinmerrell Aug 29, 2023
2f18fec
testing error
justinmerrell Aug 29, 2023
5603fb1
testing, remove type error
justinmerrell Aug 29, 2023
c67bbd8
try and GC
justinmerrell Aug 29, 2023
4a114fb
Update CI-tests.yml
justinmerrell Aug 29, 2023
e9ad6a8
Update CI-tests.yml
justinmerrell Aug 29, 2023
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
6 changes: 3 additions & 3 deletions .github/workflows/CI-pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ on:
branches-ignore:
- "main-ci"
- "release"
pull_request:
branches:
- main
# pull_request:
# branches:
# - main

workflow_dispatch:

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/CI-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ on:
- main-ci
- release

pull_request:
branches:
- main
# pull_request:
# branches:
# - main

workflow_dispatch:

Expand Down Expand Up @@ -38,4 +38,4 @@ jobs:

- name: Run Tests
run: |
pytest --timeout=120 --timeout_method=thread --cov=runpod --cov-report=xml --cov-report=term-missing --cov-fail-under=100
pytest --timeout=120 --timeout_method=thread --cov=runpod --cov-report=xml --cov-report=term-missing --cov-fail-under=100 -W error -p no:cacheprovider -p no:unraisableexception
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
aiohttp >= 3.8.4
aiohttp-retry >= 2.8.3

backoff == 2.2.1
boto3 >= 1.26.165
Expand Down
40 changes: 0 additions & 40 deletions runpod/serverless/modules/retry.py

This file was deleted.

86 changes: 45 additions & 41 deletions runpod/serverless/modules/rp_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,71 @@

import os
import json
import aiohttp
from aiohttp_retry import RetryClient, ExponentialRetry

from runpod.serverless.modules.rp_logger import RunPodLogger
from .worker_state import Jobs
from .retry import retry
from .worker_state import WORKER_ID
from .worker_state import Jobs, WORKER_ID

JOB_DONE_URL_TEMPLATE = str(os.environ.get('RUNPOD_WEBHOOK_POST_OUTPUT'))
JOB_DONE_URL_TEMPLATE = JOB_DONE_URL_TEMPLATE.replace('$RUNPOD_POD_ID', WORKER_ID)
JOB_DONE_URL_TEMPLATE = str(os.environ.get('RUNPOD_WEBHOOK_POST_OUTPUT', 'JOB_DONE_URL'))
JOB_DONE_URL = JOB_DONE_URL_TEMPLATE.replace('$RUNPOD_POD_ID', WORKER_ID)

JOB_STREAM_URL_TEMPLATE = str(os.environ.get('RUNPOD_WEBHOOK_POST_STREAM'))
JOB_STREAM_URL_TEMPLATE = JOB_STREAM_URL_TEMPLATE.replace('$RUNPOD_POD_ID', WORKER_ID)
JOB_STREAM_URL_TEMPLATE = str(os.environ.get('RUNPOD_WEBHOOK_POST_STREAM', 'JOB_STREAM_URL'))
JOB_STREAM_URL = JOB_STREAM_URL_TEMPLATE.replace('$RUNPOD_POD_ID', WORKER_ID)

log = RunPodLogger()
job_list = Jobs()


@retry(max_attempts=3, base_delay=1, max_delay=3)
async def transmit(session, job_data, url):
async def _transmit(client_session, url, job_data ):
"""
Wrapper for sending results.
Wrapper for transmitting results via POST.
"""
headers = {
"charset": "utf-8",
"Content-Type": "application/x-www-form-urlencoded"
}
retry_options = ExponentialRetry(attempts=3)
retry_client = RetryClient(client_session=client_session, retry_options=retry_options)

async with session.post(url,
data=job_data,
headers=headers,
raise_for_status=True) as resp:
await resp.text()
kwargs = {
"data": job_data,
"headers": {"charset": "utf-8", "Content-Type": "application/x-www-form-urlencoded"},
"raise_for_status": True
}

async with retry_client.post(url, **kwargs) as client_response:
await client_response.text()

async def send_result(session, job_data, job):
'''
Return the job results.
'''

async def _handle_result(session, job_data, job, url_template, log_message):
"""
A helper function to handle the result, either for sending or streaming.
"""
try:
job_data = json.dumps(job_data, ensure_ascii=False)
job_done_url = JOB_DONE_URL_TEMPLATE.replace('$ID', job['id'])
serialized_job_data = json.dumps(job_data, ensure_ascii=False)
url = url_template.replace('$ID', job['id'])

await transmit(session, job_data, job_done_url)
log.debug(f"{job['id']} | Results sent.")
await _transmit(session, url, serialized_job_data)
log.debug(f"{job['id']} | {log_message}")

job_list.remove_job(job["id"])
log.info(f'{job["id"]} | Finished')
except aiohttp.ClientResponseError as err:
log.error(f"{job['id']} | Client response error while transmitting job. | {err}")

except Exception as err: # pylint: disable=broad-except
except (TypeError, RuntimeError) as err:
log.error(f"Error while returning job result {job['id']}: {err}")

finally:
if url_template == JOB_DONE_URL:
job_list.remove_job(job["id"])
log.info(f'{job["id"]} | Finished')

async def stream_result(session, job_data, job):
'''
Return the stream job results.
'''
try:
job_data = json.dumps(job_data, ensure_ascii=False)
job_done_url = JOB_STREAM_URL_TEMPLATE.replace('$ID', job['id'])

await transmit(session, job_data, job_done_url)
log.debug(f"{job['id']} | Intermediate Results sent.")
async def send_result(session, job_data, job):
"""
Return the job results.
"""
await _handle_result(session, job_data, job, JOB_DONE_URL, "Results sent.")


except Exception as err: # pylint: disable=broad-except
log.error(f"Error while returning job result {job['id']}: {err}")
async def stream_result(session, job_data, job):
"""
Return the stream job results.
"""
await _handle_result(session, job_data, job, JOB_STREAM_URL, "Intermediate results sent.")
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ packages = find:
python_requires = >= 3.10
install_requires =
aiohttp >= 3.8.4
aiohttp-retry >= 2.8.3
backoff >= 2.2.1
boto3 >= 1.26.165
click >= 8.1.7
Expand Down
45 changes: 38 additions & 7 deletions tests/test_endpoint/test_asyncio_runner.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
''' Unit tests for the asyncio_runner module. '''
# pylint: disable=too-few-public-methods


import tracemalloc
import asyncio
import unittest
from unittest.mock import patch, MagicMock
from unittest import IsolatedAsyncioTestCase
import pytest

from runpod.endpoint.asyncio.asyncio_runner import Job, Endpoint

Expand All @@ -17,7 +15,6 @@
class TestJob(IsolatedAsyncioTestCase):
''' Tests the Job class. '''

@pytest.mark.asyncio
async def test_status(self):
'''
Tests Job.status
Expand All @@ -32,7 +29,6 @@ async def test_status(self):
status = await job.status()
assert status == "COMPLETED"

@pytest.mark.asyncio
async def test_output(self):
'''
Tests Job.output
Expand All @@ -57,7 +53,6 @@ async def json_side_effect():
output = await output_task
assert output == "OUTPUT"

@pytest.mark.asyncio
async def test_cancel(self):
'''
Tests Job.cancel
Expand All @@ -72,10 +67,35 @@ async def test_cancel(self):
cancel_result = await job.cancel()
assert cancel_result == {"result": "CANCELLED"}

class TestEndpoint:
async def test_output_in_progress_then_completed(self):
'''Tests Job.output when status is initially IN_PROGRESS and then changes to COMPLETED'''
with (
patch("runpod.endpoint.asyncio.asyncio_runner.asyncio.sleep") as mock_sleep,
patch("aiohttp.ClientSession") as mock_session
):
mock_resp = MagicMock()
responses = [
{"status": "IN_PROGRESS"},
{"status": "COMPLETED"},
{"output": "OUTPUT"}
]

async def json_side_effect():
if responses:
return responses.pop(0)
return {"status": "IN_PROGRESS"}

mock_resp.json = json_side_effect
mock_session.get.return_value.__aenter__.return_value = mock_resp

job = Job("endpoint_id", "job_id", mock_session)
output = await job.output()
assert output == "OUTPUT"
mock_sleep.assert_called_once_with(1)

class TestEndpoint(IsolatedAsyncioTestCase):
''' Unit tests for the Endpoint class. '''

@pytest.mark.asyncio
async def test_run(self):
'''
Tests Endpoint.run
Expand All @@ -90,6 +110,17 @@ async def test_run(self):
job = await endpoint.run({"input": "INPUT"})
assert job.job_id == "job_id"

class TestEndpointInitialization(unittest.TestCase):
'''Tests for the Endpoint class initialization.'''

def test_endpoint_initialization(self):
'''Tests initialization of Endpoint class.'''
with patch("aiohttp.ClientSession"):
endpoint = Endpoint("endpoint_id", MagicMock())
self.assertEqual(endpoint.endpoint_url, "https://api.runpod.ai/v2/endpoint_id/run")
self.assertIn("Content-Type", endpoint.headers)
self.assertIn("Authorization", endpoint.headers)

if __name__ == "__main__":
unittest.main()

Expand Down
Loading