test_scheduler_block_mode_predry.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. """With drying set to block the queue, a job scheduled for later may still have
  2. its printer pre-dried.
  3. The block refused a new drying cycle on any printer with a pending job, and a
  4. scheduled job is one, so queue-only drying -- whose purpose is drying ahead of
  5. scheduled prints -- never dried anything in this mode. A job waiting for its
  6. start time is not held up by a cycle meant to end before then; if the cycle is
  7. still running when it is due, the hold applies as usual.
  8. """
  9. from datetime import datetime, timedelta
  10. import pytest
  11. from backend.app.models.print_queue import PrintQueueItem
  12. from backend.app.services.print_scheduler import PrintScheduler
  13. from backend.tests.unit.test_scheduler_model_job_drying_c5 import _considered_for_drying
  14. from backend.tests.unit.test_scheduler_pinned_waiting_reason_3074 import (
  15. _add_item,
  16. _set,
  17. ctx, # noqa: F401 - fixture
  18. )
  19. async def _schedule(ctx, item_id: int, delta: timedelta) -> None:
  20. async with ctx.session_maker() as db:
  21. item = await db.get(PrintQueueItem, item_id)
  22. item.scheduled_time = datetime.utcnow() + delta
  23. await db.commit()
  24. @pytest.mark.asyncio
  25. async def test_a_job_scheduled_for_later_lets_its_printer_pre_dry(ctx):
  26. await _set(ctx, "queue_drying_enabled", "true")
  27. await _set(ctx, "queue_drying_block", "true")
  28. item_id = await _add_item(ctx, printer_id=1)
  29. await _schedule(ctx, item_id, timedelta(hours=2))
  30. assert await _considered_for_drying(ctx, PrintScheduler()) == {1}
  31. @pytest.mark.asyncio
  32. async def test_a_job_that_could_start_now_still_blocks_a_new_cycle(ctx):
  33. await _set(ctx, "ambient_drying_enabled", "true")
  34. await _set(ctx, "queue_drying_block", "true")
  35. await _add_item(ctx, printer_id=1)
  36. assert await _considered_for_drying(ctx, PrintScheduler()) == set()
  37. @pytest.mark.asyncio
  38. async def test_a_job_whose_time_has_come_blocks_too(ctx):
  39. await _set(ctx, "ambient_drying_enabled", "true")
  40. await _set(ctx, "queue_drying_block", "true")
  41. item_id = await _add_item(ctx, printer_id=1)
  42. await _schedule(ctx, item_id, timedelta(minutes=-5))
  43. assert await _considered_for_drying(ctx, PrintScheduler()) == set()