Example #1
0
 def setUp(self) -> None:
     self.event_loop: AbstractEventLoop = asyncio.get_event_loop()
     self.decider: ReplayDecider = Mock()
     self.decider.get_and_increment_next_id = MagicMock(return_value="0")
     self.decider.event_loop = Mock()
     self.future = self.event_loop.create_future()
     self.decider.event_loop.create_future = MagicMock(
         return_value=self.future)
     self.itask = ITask(decider=self.decider)
Example #2
0
 def get_version(change_id: str, min_supported: int, max_supported: int):
     from cadence.decision_loop import ITask
     from cadence.decision_loop import DecisionContext
     task: ITask = ITask.current()
     decision_context: DecisionContext = task.decider.decision_context
     return decision_context.get_version(change_id, min_supported,
                                         max_supported)
Example #3
0
 def new_activity_stub(activities_cls):
     from cadence.decision_loop import ITask
     task: ITask = ITask.current()
     assert task
     cls = activities_cls()
     cls._decision_context = task.decider.decision_context
     return cls
Example #4
0
 def new_activity_stub(activities_cls, retry_parameters: RetryParameters = None):
     from cadence.decision_loop import ITask
     task: ITask = ITask.current()
     assert task
     cls = activities_cls()
     cls._decision_context = task.decider.decision_context
     cls._retry_parameters = retry_parameters
     return cls
Example #5
0
class TestAwaitTill(TestCase):
    def setUp(self) -> None:
        self.event_loop: AbstractEventLoop = asyncio.get_event_loop()
        self.decider: ReplayDecider = Mock()
        self.decider.get_and_increment_next_id = MagicMock(return_value="0")
        self.decider.event_loop = Mock()
        self.future = self.event_loop.create_future()
        self.decider.event_loop.create_future = MagicMock(
            return_value=self.future)
        self.itask = ITask(decider=self.decider)

    def tearDown(self) -> None:
        self.task.cancel()

    def test_await_till(self):
        self.task = self.event_loop.create_task(
            self.itask.await_till(lambda *args: None))
        run_once(self.event_loop)
        assert self.itask.awaited

    def test_await_till_no_progress(self):
        self.task = self.event_loop.create_task(
            self.itask.await_till(lambda *args: None))
        run_once(self.event_loop)
        assert self.itask.awaited
        run_once(self.event_loop)
        assert self.itask.awaited

    def test_unblock(self):
        blocked = True

        def check_blocked():
            nonlocal blocked
            return not blocked

        self.task = self.event_loop.create_task(
            self.itask.await_till(check_blocked))
        run_once(self.event_loop)
        blocked = False
        self.itask.unblock()
        run_once(self.event_loop)
        assert not self.itask.awaited
Example #6
0
 def get_logger(name):
     from cadence.decision_loop import ITask
     task: ITask = ITask.current()
     return task.decider.decision_context.get_logger(name)
Example #7
0
 def new_random() -> random.Random:
     from cadence.decision_loop import ITask
     task: ITask = ITask.current()
     return task.decider.decision_context.new_random()
Example #8
0
 def random_uuid() -> uuid.UUID:
     from cadence.decision_loop import ITask
     task: ITask = ITask.current()
     return task.decider.decision_context.random_uuid()
Example #9
0
 def now() -> datetime.datetime:
     from cadence.decision_loop import ITask
     task: ITask = ITask.current()
     now_in_ms = task.decider.decision_context.current_time_millis()
     return datetime.datetime.fromtimestamp(now_in_ms / 1000)
Example #10
0
 def current_time_millis() -> int:
     from cadence.decision_loop import ITask
     task: ITask = ITask.current()
     return task.decider.decision_context.current_time_millis()
Example #11
0
 async def sleep(seconds: int):
     from cadence.decision_loop import ITask
     task: ITask = ITask.current()
     await task.decider.decision_context.schedule_timer(seconds)
Example #12
0
 async def await_till(c: Callable, timeout_seconds: int = 0) -> bool:
     from cadence.decision_loop import ITask
     task: ITask = ITask.current()
     assert task
     return await task.await_till(c, timeout_seconds)
Example #13
0
 def interceptor(*args, **kwargs):
     from cadence.decision_loop import ITask
     task: ITask = ITask.current()
     if not task.decider.decision_context.is_replaying():
         return fn(*args, **kwargs)
Example #14
0
 def get_execution_id():
     from cadence.decision_loop import ITask
     task: ITask = ITask.current()
     return task.decider.execution_id
Example #15
0
 def get_workflow_id():
     from cadence.decision_loop import ITask
     task: ITask = ITask.current()
     return task.decider.workflow_id