Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
test: jcloud integration tests for basic app
Browse files Browse the repository at this point in the history
  • Loading branch information
zac-li committed May 10, 2023
1 parent 33ac64c commit 303eb86
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/integration/jcloud/test_app_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


@pytest.mark.asyncio
async def test_http_route_timeout():
async def test_timeout():
timeout = 60
async with deploy_jcloud_app(timeout=timeout) as app_id:
_test_http_route(app_id, timeout)
Expand Down
43 changes: 43 additions & 0 deletions tests/integration/jcloud/test_basic_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import json

import pytest
import requests
import websockets

from ..helper import deploy_jcloud_app


@pytest.mark.asyncio
async def test_basic_app():
async with deploy_jcloud_app() as app_id:
_test_http_route(app_id)
await _test_ws_route(app_id)


def _test_http_route(app_id):
headers = {
"accept": "application/json",
"Content-Type": "application/json",
}
data = {"interval": 1, "envs": {}}

response = requests.post(
f"https://{app_id}.wolf.jina.ai/sync_http", headers=headers, json=data
)

response_data = response.json()

assert response.status_code == 200
assert response_data["result"] == "Hello, world!"


async def _test_ws_route(app_id):
async with websockets.connect(f"wss://{app_id}.wolf.jina.ai/sync_ws") as websocket:
await websocket.send(json.dumps({"interval": 1}))

received_messages = []
for _ in range(5):
message = await websocket.recv()
received_messages.append(message)

assert received_messages == ["0", "1", "2", "3", "4"]

0 comments on commit 303eb86

Please sign in to comment.