Run tests: execution options follow the configured schedulers; the queued-cancel test cancels whichever run Dagster left queued and checks none of its steps ran
This commit is contained in:
+10
-2
@@ -1,5 +1,6 @@
|
||||
"""Run shaping and the API's Dagster-backed run and execution routes."""
|
||||
|
||||
import os
|
||||
import time
|
||||
|
||||
import pytest
|
||||
@@ -209,11 +210,18 @@ def test_run_requests_validate_the_execution_choice(api_with_dagster_address):
|
||||
def test_execution_options_and_health(api):
|
||||
options = _ok(api.get("/execution/options"))
|
||||
assert options["default_mode"] == "sync"
|
||||
assert options["schedulers"] == []
|
||||
configured = [s for s in os.environ.get("DASK_SCHEDULERS", "").split(",") if s]
|
||||
assert options["schedulers"] == configured # compose and CI name the test scheduler
|
||||
health = _ok(api.get("/execution/health", params={"mode": "local"}))
|
||||
assert health["reachable"] is True
|
||||
assert health["workers"] >= 1
|
||||
assert api.get("/execution/health", params={"mode": "remote"}).status_code == 422
|
||||
if configured:
|
||||
remote = {"mode": "remote", "scheduler": configured[0]}
|
||||
health = _ok(api.get("/execution/health", params=remote))
|
||||
assert health["reachable"] is True
|
||||
assert health["workers"] == int(os.environ.get("DASK_EXPECTED_WORKERS", "1"))
|
||||
else:
|
||||
assert api.get("/execution/health", params={"mode": "remote"}).status_code == 422
|
||||
assert api.get("/execution/health?mode=sync&reference=..%2Fx").status_code == 422
|
||||
|
||||
|
||||
|
||||
@@ -91,12 +91,24 @@ def test_cancelling_an_ingest_run_leaves_no_silver_or_gold(api, platform):
|
||||
@pytest.mark.parametrize("platform", ["sqlite"], indirect=True)
|
||||
def test_cancelling_a_queued_run_never_starts_it(api, platform):
|
||||
load(api, "cacu")
|
||||
first, second = _submit(api), _submit(api)
|
||||
if _get_run(api, second)["state"] != "queued":
|
||||
pytest.skip("the second run was not queued")
|
||||
ok(api.post(f"/runs/{second}/cancel"))
|
||||
assert _wait_cancelled(api, second)["started"] is None
|
||||
wait_for(api, first, 300)
|
||||
runs = [_submit(api), _submit(api)]
|
||||
# Dagster launches one of the two (its queue sorts by priority, not by submission order);
|
||||
# the other waits behind the `writes` limit: cancel that one, whichever it is.
|
||||
deadline = time.monotonic() + 120
|
||||
while True:
|
||||
states = {run_id: _get_run(api, run_id)["state"] for run_id in runs}
|
||||
running = [r for r, state in states.items() if state == "running"]
|
||||
queued = [r for r, state in states.items() if state == "queued"]
|
||||
if len(running) == 1 and len(queued) == 1:
|
||||
break
|
||||
if any(state in TERMINAL for state in states.values()):
|
||||
pytest.skip(f"a run ended before the other was seen queued: {states}")
|
||||
assert time.monotonic() < deadline, states
|
||||
time.sleep(0.5)
|
||||
ok(api.post(f"/runs/{queued[0]}/cancel"))
|
||||
# Dagster stamps a start time on a queued run it cancels; what matters is that nothing ran
|
||||
assert _wait_cancelled(api, queued[0])["steps"] == []
|
||||
wait_for(api, running[0], 300)
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="needs killing the run worker; checked by hand")
|
||||
|
||||
Reference in New Issue
Block a user