Beispiel #1
0
    def test___call__(monkeypatch):
        estimator = estimators.StaticEstimator(duration=5)
        trigger_time = parse('2017/10/05T11:11:11Z')

        message = Message(trigger_time, 15, 1, 2)
        assert estimator(message) == trigger_time + timedelta(seconds=5)

        trigger_time = trigger_time + timedelta(seconds=1)
        message = Message(trigger_time, 17, 1, 2)
        assert estimator(message) == trigger_time + timedelta(seconds=5)
Beispiel #2
0
        def with_factor():
            estimator = estimators.SimpleEstimator(factor=10)

            trigger_time = parse('2017/10/05T11:11:11Z')
            message = Message(trigger_time, 10, 1, 2)
            assert estimator(message) == None

            trigger_time = trigger_time + timedelta(seconds=1)
            message = Message(trigger_time, 15, 1, 2)
            assert estimator(message) == trigger_time + timedelta(seconds=50)

            trigger_time = trigger_time + timedelta(seconds=2)
            message = Message(trigger_time, 17, 1, 2)
            assert estimator(message) == trigger_time + timedelta(seconds=35)
Beispiel #3
0
        def normal_case():
            estimator = estimators.SimpleEstimator()

            trigger_time = parse('2017/10/05T11:11:11Z')
            message = Message(trigger_time, 10, 1, 2)
            assert estimator(message) == None

            trigger_time = trigger_time + timedelta(seconds=1)
            message = Message(trigger_time, 15, 1, 2)
            assert estimator(message) == trigger_time + timedelta(seconds=7.5)

            trigger_time = trigger_time + timedelta(seconds=2)
            message = Message(trigger_time, 17, 1, 2)
            assert estimator(message) == trigger_time + timedelta(seconds=5.25)
    def test___call__(monkeypatch, kill_mock):
        kill_mock.return_value = None
        pid = os.getpid()
        mysignal = 'hoge'
        action = actions.Abort(pid, signal=mysignal)
        now = datetime.now(tz.tzutc())
        message = Message(now, 10, 1, 2)

        action(now, now, message)
        kill_mock.assert_called_once_with(pid, mysignal)
    def test__get_message(monkeypatch):
        action = actions.MessageAction(tzinfo='Asia/Tokyo')
        tick_time = parse('2017/10/10T02:03:04Z')
        estimated_trigger_time = parse('2017/05/10T03:04:05Z')
        trigger_time = parse('2017/10/05T11:11:11Z')
        message = Message(trigger_time, 10, 1, 2)

        expected_message = "Next trigger didn't come " \
                           "before the estimated time 2017-05-10T12:04:05+09:00 "\
                           "since 2017-10-05T20:11:11+09:00 at (epoch: 1, iteration: 2)."
        assert action._get_message(tick_time, estimated_trigger_time, message) == expected_message
    def test___call__(monkeypatch):
        url = 'url'
        channel = 'channel'
        action = actions.SlackWebhookNotification(url, channel, tzinfo='Asia/Tokyo')
        tick_time = parse('2017/10/10T02:03:04Z')
        estimated_trigger_time = parse('2017/05/10T03:04:05Z')
        trigger_time = parse('2017/10/05T11:11:11Z')
        message = Message(trigger_time, 10, 1, 2)

        with mock.patch.object(action._slack, 'notify') as slack_mock:
            slack_mock.return_value = None
            action(tick_time, estimated_trigger_time, message)
            expected_message = "Next trigger didn't come " \
                               "before the estimated time 2017-05-10T12:04:05+09:00 "\
                               "since 2017-10-05T20:11:11+09:00 at (epoch: 1, iteration: 2)."
            slack_mock.assert_called_once_with(channel=channel, text=expected_message)
    def test___call__(monkeypatch):
        action = actions.WarningMessage()
        now = datetime.now(tz.tzutc())
        message = Message(now, 10, 1, 2)

        action(now, now, message)