Something went wrong. Try again.
prefect server in zig
Something went wrong. Try again.
3.9 kB · 77 lines
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778#!/usr/bin/env -S uv run --no-project --script# /// script# requires-python = ">=3.12"# dependencies = ["httpx==0.28.1", "redis==8.1.0"]# ///import argparseimport jsonimport osfrom pathlib import Pathfrom uuid import uuid4
import httpxfrom redis import Redis
parser = argparse.ArgumentParser()parser.add_argument("--url", required=True)parser.add_argument("--expected-failure-status", type=int, choices=[204, 500], required=True)parser.add_argument("--output", type=Path, required=True)parser.add_argument("--redis-port", type=int, required=True, help="Dedicated disposable Redis used by the local server; its snapshot stream is deliberately corrupted")args = parser.parse_args()assert args.url.startswith("http://127.0.0.1:"), "Use an isolated local server"stream = "work-pool-worker-channel-snapshots"redis = Redis(host="127.0.0.1", port=args.redis_port)credential = os.environ.get("PREFECT_API_AUTH_STRING")auth = tuple(credential.split(":", 1)) if credential else Nonename = "invalidation-failure-" + uuid4().hexresult = {"url": args.url, "redis_port": args.redis_port, "pool": name, "requests": []}with httpx.Client(base_url=args.url.rstrip("/"), auth=auth, timeout=30) as client: def call(method, path, **kwargs): response = client.request(method, path, **kwargs) result["requests"].append({"method": method, "path": path, "status": response.status_code, "body": response.text}) return response
try: created = call("POST", "/work_pools/", json={"name": name, "type": "process"}) assert created.status_code == 201, created.text redis.delete(stream) redis.set(stream, "not-a-stream") failed = call("PATCH", f"/work_pools/{name}", json={"concurrency_limit": 21}) assert failed.status_code == args.expected_failure_status, failed.text persisted = call("GET", f"/work_pools/{name}") assert persisted.status_code == 200 assert persisted.json()["concurrency_limit"] == 21 assert redis.get(stream) == b"not-a-stream" redis.delete(stream) retried = call("PATCH", f"/work_pools/{name}", json={"concurrency_limit": 22}) assert retried.status_code == 204, retried.text messages = redis.xrange(stream) assert len(messages) == 1 result["notification"] = json.loads(messages[0][1][b"data"]) assert result["notification"] == {"work_pool_id": created.json()["id"], "reason": "work_pool_updated"} queue_path = f"/work_pools/{name}/queues/" for method, path, body, baseline_status in [ ("POST", queue_path, {"name": "failure-queue", "priority": 2}, 201), ("PATCH", queue_path + "failure-queue", {"concurrency_limit": 7}, 204), ("DELETE", queue_path + "failure-queue", None, 204), ("DELETE", f"/work_pools/{name}", None, 204), ]: redis.delete(stream) redis.set(stream, "not-a-stream") response = call(method, path, **({"json": body} if body is not None else {})) expected = 500 if args.expected_failure_status == 500 else baseline_status assert response.status_code == expected, response.text assert redis.get(stream) == b"not-a-stream" read_path = queue_path + "failure-queue" if method == "POST" else path persisted = call("GET", read_path) assert persisted.status_code == (404 if method == "DELETE" else 200), persisted.text if method == "PATCH": assert persisted.json()["concurrency_limit"] == 7 redis.delete(stream) result["passed"] = True finally: redis.delete(stream) call("DELETE", f"/work_pools/{name}") redis.delete(stream) redis.close() args.output.write_text(json.dumps(result, indent=2) + "\n")