Exemplo n.º 1
0
def test_timer_cancel_delegates_to_wrapped_timer():
    background_timer = ThreadingTimer(30.0, lambda x: x)
    background_timer.cancel = Mock()
    under_test = Timer(background_timer, "abc123")

    under_test.cancel()

    background_timer.cancel.assert_called_once()
Exemplo n.º 2
0
def test_timer_aliveness_delegates_to_wrapped_timer():
    background_timer = ThreadingTimer(30.0, lambda x: x)
    background_timer.is_alive = Mock()
    under_test = Timer(background_timer, "abc123")

    under_test.is_alive()

    background_timer.is_alive.assert_called_once()
Exemplo n.º 3
0
def test_start_timer_fails_if_timer_already_started():
    wfe = make_workflow_execution()
    existing_timer = Mock(spec=ThreadingTimer)
    existing_timer.is_alive.return_value = True
    wfe._timers["abc123"] = Timer(existing_timer, 1)
    START_TIMER_EVENT_ATTRIBUTES = {"startToFireTimeout": "10", "timerId": "abc123"}

    wfe.start_timer(123, START_TIMER_EVENT_ATTRIBUTES)

    last_event = wfe.events()[-1]
    last_event.event_type.should.equal("StartTimerFailed")
    last_event.event_attributes["cause"].should.equal("TIMER_ID_ALREADY_IN_USE")
    last_event.event_attributes["timerId"].should.equal("abc123")
    last_event.event_attributes["decisionTaskCompletedEventId"].should.equal(123)
Exemplo n.º 4
0
def test_cancel_timer():
    wfe = make_workflow_execution()
    existing_timer = Mock(spec=ThreadingTimer)
    existing_timer.is_alive.return_value = True
    wfe._timers["abc123"] = Timer(existing_timer, 1)

    wfe.cancel_timer(123, "abc123")

    last_event = wfe.events()[-1]
    last_event.event_type.should.equal("TimerCancelled")
    last_event.event_attributes["startedEventId"].should.equal(1)
    last_event.event_attributes["timerId"].should.equal("abc123")
    last_event.event_attributes["decisionTaskCompletedEventId"].should.equal(123)
    existing_timer.cancel.assert_called_once()
    assert not wfe._timers.get("abc123")
Exemplo n.º 5
0
def test_timer_creation():
    background_timer = ThreadingTimer(30.0, lambda x: x)
    under_test = Timer(background_timer, "abc123")

    assert under_test.background_timer == background_timer
    assert under_test.started_event_id == "abc123"