1
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2026-04-25 09:40:48 +02:00
This commit is contained in:
2026-04-20 16:36:47 +02:00
parent 92d4519853
commit 5271db1ca6
2 changed files with 7 additions and 118 deletions
+3 -34
View File
@@ -24,46 +24,15 @@ conda create -q -n test-environment "python=${python_version}"
conda activate test-environment
cd bec
source ./bin/install_bec_dev.sh -t
source ./bin/install_bec_dev.sh
cd ..
python -m pip install -e ./ophyd_devices -e .[dev,pyside6] -e ./bec_testing_plugin
benchmark_tmp_dir="$(mktemp -d)"
export BEC_SERVICE_CONFIG="$benchmark_tmp_dir/services_config.yaml"
ready_file="$benchmark_tmp_dir/ready"
supervisor_log="$benchmark_tmp_dir/bec-benchmark-services.log"
python .github/scripts/start_bec_benchmark_services.py \
--files-path "$benchmark_tmp_dir" \
--services-config "$BEC_SERVICE_CONFIG" \
--ready-file "$ready_file" \
> "$supervisor_log" 2>&1 &
supervisor_pid=$!
redis-server --daemonize yes --port 6379
cleanup_benchmark_services() {
if kill -0 "$supervisor_pid" >/dev/null 2>&1; then
kill "$supervisor_pid"
wait "$supervisor_pid" || true
fi
rm -rf "$benchmark_tmp_dir"
}
trap cleanup_benchmark_services EXIT
bec-server start --config "$BEC_SERVICE_CONFIG"
deadline=$((SECONDS + 30))
while [ ! -f "$ready_file" ]; do
if ! kill -0 "$supervisor_pid" >/dev/null 2>&1; then
cat "$supervisor_log" >&2 || true
echo "BEC benchmark service supervisor exited before becoming ready" >&2
exit 1
fi
if [ "$SECONDS" -ge "$deadline" ]; then
cat "$supervisor_log" >&2 || true
echo "Timed out waiting for BEC benchmark services" >&2
exit 1
fi
sleep 0.2
done
cat "$supervisor_log"
echo "BEC_SERVICE_CONFIG=$BEC_SERVICE_CONFIG" >> "$GITHUB_ENV"
@@ -4,60 +4,11 @@
from __future__ import annotations
import argparse
import shutil
import subprocess
import time
from pathlib import Path
import bec_lib
from bec_ipython_client import BECIPythonClient
from bec_lib.redis_connector import RedisConnector
from bec_lib.service_config import ServiceConfig, ServiceConfigModel
from redis import Redis
def _wait_for_redis(host: str, port: int) -> None:
client = Redis(host=host, port=port)
deadline = time.monotonic() + 10
while time.monotonic() < deadline:
try:
if client.ping():
return
except Exception:
time.sleep(0.1)
raise RuntimeError(f"Redis did not start on {host}:{port}")
def _start_redis(files_path: Path, host: str, port: int) -> subprocess.Popen:
redis_server = shutil.which("redis-server")
if redis_server is None:
raise RuntimeError("redis-server executable not found")
return subprocess.Popen(
[
redis_server,
"--bind",
host,
"--port",
str(port),
"--save",
"",
"--appendonly",
"no",
"--dir",
str(files_path),
]
)
def _write_configs(files_path: Path, services_config: Path, host: str, port: int) -> None:
bec_lib_path = Path(bec_lib.__file__).resolve().parent
shutil.copyfile(bec_lib_path / "tests" / "test_config.yaml", files_path / "test_config.yaml")
service_config = ServiceConfigModel(
redis={"host": host, "port": port}, file_writer={"base_path": str(files_path)}
)
services_config.write_text(service_config.model_dump_json(indent=4), encoding="utf-8")
from bec_lib.service_config import ServiceConfig
def _load_demo_config(services_config: Path) -> None:
@@ -70,44 +21,13 @@ def _load_demo_config(services_config: Path) -> None:
bec._client._reset_singleton()
def main() -> int:
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--files-path", required=True, type=Path)
parser.add_argument("--services-config", required=True, type=Path)
parser.add_argument("--ready-file", required=True, type=Path)
args = parser.parse_args()
host = "127.0.0.1"
port = 6379
args.files_path.mkdir(parents=True, exist_ok=True)
_write_configs(args.files_path, args.services_config, host, port)
redis_process = _start_redis(args.files_path, host, port)
processes = None
service_handler = None
try:
_wait_for_redis(host, port)
from bec_server.bec_server_utils.service_handler import ServiceHandler
service_handler = ServiceHandler(
bec_path=args.files_path, config_path=args.services_config, interface="subprocess"
)
processes = service_handler.start()
_load_demo_config(args.services_config)
args.ready_file.write_text("ready\n", encoding="utf-8")
print("BEC benchmark services are ready", flush=True)
finally:
if service_handler is not None and processes is not None:
service_handler.stop(processes)
redis_process.terminate()
try:
redis_process.wait(timeout=10)
except subprocess.TimeoutExpired:
redis_process.kill()
return 0
_load_demo_config(args.services_config)
if __name__ == "__main__":
raise SystemExit(main())
main()