Skip to content

Commit

Permalink
Add simple test for SyncExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasst committed Feb 15, 2024
1 parent 06fa221 commit 6776d7c
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions tests/test_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@
from freezefrog import FreezeTime

from tasktiger import Task, Worker

from .tasks import long_task_ok, wait_for_long_task
from tasktiger.executor import SyncExecutor

from .tasks import (
exception_task,
long_task_killed,
long_task_ok,
simple_task,
wait_for_long_task,
)
from .test_base import BaseTestCase
from .utils import external_worker

Expand Down Expand Up @@ -144,3 +151,30 @@ def test_queue_system_lock(self):
worker.max_workers_per_queue = 2
worker.run(once=True, force_once=True)
self._ensure_queues(queued={"a": 1})


class TestSyncExecutorWorker:
def test_success(self, tiger, ensure_queues):
worker = Worker(tiger, executor_class=SyncExecutor)
worker.run(once=True, force_once=True)

task = Task(tiger, simple_task)
task.delay()
task = Task(tiger, simple_task)
task.delay()
ensure_queues(queued={"default": 2})

worker.run(once=True)
ensure_queues()

def test_handles_exception(self, tiger, ensure_queues):
Task(tiger, exception_task).delay()
worker = Worker(tiger, executor_class=SyncExecutor)
worker.run(once=True, force_once=True)
ensure_queues(error={"default": 1})

def test_handles_timeout(self, tiger, ensure_queues):
Task(tiger, long_task_killed).delay()
worker = Worker(tiger, executor_class=SyncExecutor)
worker.run(once=True, force_once=True)
ensure_queues(error={"default": 1})

0 comments on commit 6776d7c

Please sign in to comment.