-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deployment getting stuck at finalizing the build phase (#461)
* Add metric measuring unfinished deployments * Use raw ASGI middlewares * Set interactive mode to docker compose containers * set request timeout to 1h * Add server sent events test with Fastapi & httpx * Move httpx to racetrack commons * Use server sent events to keep connection alive * Move SSE client and server to commons * Add changelog notice
- Loading branch information
1 parent
342a9f8
commit 5cfdd90
Showing
14 changed files
with
429 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
httpx==0.24.0 | ||
markdown==3.4.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import asyncio | ||
|
||
import backoff | ||
import httpx | ||
from fastapi import FastAPI | ||
from fastapi.responses import StreamingResponse | ||
|
||
from racetrack_client.log.logs import configure_logs | ||
from racetrack_commons.api.asgi.asgi_server import serve_asgi_in_background | ||
from racetrack_commons.socket import free_tcp_port | ||
|
||
|
||
def test_server_sent_events(): | ||
app = FastAPI() | ||
|
||
def sse_generator(): | ||
for num in range(3): | ||
yield f'data: {{"progress": {num}}}\n\n' | ||
|
||
@app.get("/sse") | ||
def sse_endpoint(): | ||
return StreamingResponse(sse_generator(), media_type="text/event-stream") | ||
|
||
@app.get("/ready") | ||
def ready_endpoint(): | ||
return | ||
|
||
async def test_async(): | ||
configure_logs() | ||
port = free_tcp_port() | ||
with serve_asgi_in_background(app, port): | ||
_wait_until_server_ready(port) | ||
_test_sse_client_get(port) | ||
_test_sse_client_stream(port) | ||
|
||
asyncio.run(test_async()) | ||
|
||
|
||
def _test_sse_client_get(port: int): | ||
response = httpx.get(f'http://127.0.0.1:{port}/sse') | ||
assert response.status_code == 200 | ||
assert response.text == '''data: {"progress": 0} | ||
data: {"progress": 1} | ||
data: {"progress": 2} | ||
''' | ||
|
||
|
||
def _test_sse_client_stream(port: int): | ||
lines = [] | ||
with httpx.Client(timeout=10) as client: | ||
with client.stream('GET', f'http://127.0.0.1:{port}/sse') as stream_response: | ||
for line in stream_response.iter_lines(): | ||
lines.append(line) | ||
|
||
assert lines == [ | ||
'data: {"progress": 0}', | ||
'', | ||
'data: {"progress": 1}', | ||
'', | ||
'data: {"progress": 2}', | ||
'', | ||
] | ||
stream_response.raise_for_status() | ||
assert stream_response.status_code == 200 | ||
|
||
|
||
@backoff.on_exception(backoff.fibo, httpx.RequestError, max_time=5, jitter=None) | ||
def _wait_until_server_ready(port: int): | ||
response = httpx.get(f'http://127.0.0.1:{port}/ready') | ||
assert response.status_code == 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.