53 lines
2.3 KiB
Python
53 lines
2.3 KiB
Python
|
|
"""Prepared dispatch uses native JSON arrays on production MySQL."""
|
||
|
|
|
||
|
|
from sqlalchemy import event
|
||
|
|
from sqlalchemy.dialects import mysql
|
||
|
|
|
||
|
|
from app.models import Job
|
||
|
|
from test_jobs import submit
|
||
|
|
|
||
|
|
|
||
|
|
async def test_prepared_fifo_uses_native_json_and_preserves_payload_and_holds(system):
|
||
|
|
jobs = []
|
||
|
|
for prompt in ("empty", "window", "manual", "window-manual"):
|
||
|
|
jobs.append((await submit(system, task_type="video.generate", input={"prompt": prompt}))[0])
|
||
|
|
async with system.app.state.db.session() as session:
|
||
|
|
for result, holds in zip(jobs, ([], ["window"], ["manual"], ["window", "manual"])):
|
||
|
|
job = await session.get(Job, result["id"])
|
||
|
|
job.hold_reasons = holds
|
||
|
|
# A payload prepared on Linux before local handoff is immutable.
|
||
|
|
job.upstream_payload = {
|
||
|
|
"task_type": "video.generate",
|
||
|
|
"input": {
|
||
|
|
"prompt": job.input_json["prompt"],
|
||
|
|
"image_path": "/workspace/inputs/old-owned.png",
|
||
|
|
},
|
||
|
|
"parameters": {},
|
||
|
|
"timeout_seconds": 3600,
|
||
|
|
}
|
||
|
|
await session.commit()
|
||
|
|
|
||
|
|
queries = []
|
||
|
|
|
||
|
|
def record_query(connection, statement, multiparams, params, options):
|
||
|
|
compiled = statement.compile(dialect=mysql.dialect())
|
||
|
|
sql = str(compiled)
|
||
|
|
if sql.startswith("SELECT") and "hold_reasons =" in sql:
|
||
|
|
queries.append(sql)
|
||
|
|
|
||
|
|
engine = system.app.state.db.engine.sync_engine
|
||
|
|
event.listen(engine, "before_execute", record_query)
|
||
|
|
try:
|
||
|
|
await system.app.state.coordinator.run_once(force=True)
|
||
|
|
finally:
|
||
|
|
event.remove(engine, "before_execute", record_query)
|
||
|
|
assert queries, "Exercise the actual FIFO ready query, including persisted ready payloads"
|
||
|
|
# A bare VARCHAR parameter containing [] compares as a JSON string on
|
||
|
|
# MySQL, so it cannot match a JSON array column. Both sides must be JSON.
|
||
|
|
assert all(query.count("hold_reasons = json_array(") == 2 for query in queries)
|
||
|
|
payloads = [payload for _, payload in system.provider.submitted_payloads]
|
||
|
|
assert [payload["input"]["prompt"] for payload in payloads] == ["empty", "window"]
|
||
|
|
assert all(
|
||
|
|
payload["input"]["image_path"] == "/workspace/inputs/old-owned.png" for payload in payloads
|
||
|
|
)
|