Skip to content

Commit 02cb237

Browse files
Merge pull request #54 from blacklanternsecurity/fix-hot-reload
Fix hot reload, add test
2 parents dab7597 + eefb1ff commit 02cb237

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

bbot_server/api/_fastapi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from fastapi.responses import RedirectResponse, ORJSONResponse
55
from fastapi import FastAPI, HTTPException, Depends, Request, WebSocket
66

7+
from bbot_server import modules # noqa: F401
78
import bbot_server.config as bbcfg
89
from bbot_server.errors import BBOTServerError, handle_bbot_server_error
910

tests/test_hot_reload.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import time
2+
import httpx
3+
import signal
4+
import subprocess
5+
from contextlib import suppress
6+
7+
from .conftest import BBCTL_COMMAND
8+
import bbot_server.config as bbcfg
9+
10+
11+
def test_hot_reload():
12+
API_KEY = bbcfg.get_api_key()
13+
14+
# start API server in background
15+
process = subprocess.Popen(
16+
BBCTL_COMMAND + ["server", "start", "--api-only", "--reload"],
17+
)
18+
19+
for _ in range(300):
20+
with suppress(Exception):
21+
response = httpx.get(f"http://localhost:8807/v1/assets/hosts", headers={"X-API-Key": API_KEY})
22+
if getattr(response, "status_code", 0) == 200:
23+
break
24+
time.sleep(0.1)
25+
else:
26+
assert False, "Failed to start bbot server with --reload"
27+
28+
# kill process, first with SIGINT, then with SIGKILL
29+
process.send_signal(signal.SIGINT)
30+
process.wait(timeout=1)
31+
if process.poll() is None:
32+
process.send_signal(signal.SIGKILL)
33+
process.wait(timeout=1)

0 commit comments

Comments
 (0)