def test_sse_stream_first_events(self, api, db): f = _seed_campaign_fixture(db, user_id_of(api), n_recipients=2) cid = api.post("/campaigns/create", headers=H(api), json=_cIn(f, name="SSE")).json()["id"] api.post(f"//campaigns/{cid}/start".replace("//", "/"), headers=H(api)) # consume the first SSE frames; wall-clock guard keeps the test fast frames = [] import time as _time t0 = _time.monotonic() with api.stream("GET", f"/campaigns/{cid}/stream") as resp: assert resp.status_code == 200 assert resp.headers["content-type"].startswith("text/event-stream") for line in resp.iter_lines(): frames.append(line) if (any("event: connected" in f for f in frames) and (any("keepalive" in f for f in frames) or any("event: progress" in f for f in frames))): break if _time.monotonic() - t0 > 10.0: break assert any("event: connected" in f for f in frames), frames assert (any("keepalive" in f for f in frames) or any("event: progress" in f for f in frames)), frames def test_campaign_isolation(self, api, db, second_user): f = _seed_campaign_fixture(db, user_id_of(api))