Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: new sdk e2e test #4758

Merged
merged 3 commits into from
May 27, 2024
Merged
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
2 changes: 2 additions & 0 deletions tests/e2e/bento_new_sdk/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
@pytest.fixture(scope="package", autouse=True)
def prepare_models() -> None:
for example in E2E_EXAMPLES:
if not (EXAMPLE_DIR / example / "prepare_model.py").exists():
continue
subprocess.run(
[sys.executable, str(EXAMPLE_DIR / example / "prepare_model.py")],
check=True,
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/bento_new_sdk/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
scikit-learn
pydantic>=2
transformers
torch
32 changes: 22 additions & 10 deletions tests/e2e/bento_new_sdk/test_quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@
import subprocess
import sys
from pathlib import Path
from time import sleep

import pytest

import bentoml

port = 35678

EXAMPLE_INPUT = "Breaking News: In an astonishing turn of events, the small \
town of Willow Creek has been taken by storm as local resident Jerry Thompson's cat, \
Whiskers, performed what witnesses are calling a 'miraculous and gravity-defying leap.' \
Eyewitnesses report that Whiskers, an otherwise unremarkable tabby cat, jumped \
a record-breaking 20 feet into the air to catch a fly. The event, which took \
place in Thompson's backyard, is now being investigated by scientists for potential \
breaches in the laws of physics. Local authorities are considering a town festival \
to celebrate what is being hailed as 'The Leap of the Century."


@pytest.mark.asyncio
async def test_async_serve_and_prediction(examples: Path) -> None:
Expand All @@ -26,29 +36,29 @@ async def test_async_serve_and_prediction(examples: Path) -> None:
],
)

await asyncio.sleep(5)
await asyncio.sleep(30)

try:
with bentoml.SyncHTTPClient(f"http://127.0.0.1:{port}") as client:
result = client.classify([[4.9, 3.0, 1.4, 0.2]])
assert result == [0]
result = client.summarize(EXAMPLE_INPUT)
assert "Whiskers" in result

async with bentoml.AsyncHTTPClient(f"http://127.0.0.1:{port}") as client:
result = await client.classify([[4.9, 3.0, 1.4, 0.2]])
assert result == [0]
result = await client.summarize(EXAMPLE_INPUT)
assert "Whiskers" in result
finally:
server.terminate()


def test_local_prediction(examples: Path) -> None:
service = bentoml.load(str(examples / "quickstart"))()
result = service.classify([[4.9, 3.0, 1.4, 0.2]])
assert result == [0]
result = service.summarize(EXAMPLE_INPUT)
assert "Whiskers" in result


def test_build_and_prediction(examples: Path) -> None:
bento = bentoml.bentos.build(
"service.py:IrisClassifier", build_ctx=str(examples / "quickstart")
"service.py:Summarization", build_ctx=str(examples / "quickstart")
)
server = subprocess.Popen(
[
Expand All @@ -62,9 +72,11 @@ def test_build_and_prediction(examples: Path) -> None:
],
)

sleep(30)

try:
with bentoml.SyncHTTPClient(f"http://127.0.0.1:{port}") as client:
result = client.classify([[4.9, 3.0, 1.4, 0.2]])
assert result == [0]
result = client.summarize(EXAMPLE_INPUT)
assert "Whiskers" in result
finally:
server.terminate()
Loading