Esempio n. 1
0
def test_task_lost():
    dt = p1(max_failures=2, min_duration=1)

    # regular success behavior
    p = TaskPlanner(empty_task(processes=[dt(name='d1')]))
    assert p.runnable_at(timestamp=0) == _('d1')
    p.set_running('d1')
    p.add_success('d1', timestamp=0)
    assert p.min_wait(timestamp=0) == TaskPlanner.INFINITY

    # regular failure behavior
    p = TaskPlanner(empty_task(processes=[dt(name='d1')]))
    assert p.runnable_at(timestamp=0) == _('d1')
    p.set_running('d1')
    p.add_failure('d1', timestamp=1)
    assert approx_equal(p.min_wait(timestamp=1), 1)
    p.set_running('d1')
    p.add_failure('d1', timestamp=3)
    assert p.min_wait(timestamp=3) == TaskPlanner.INFINITY

    # lost behavior
    p = TaskPlanner(empty_task(processes=[dt(name='d1')]))
    assert p.runnable_at(timestamp=0) == _('d1')
    p.set_running('d1')
    p.add_failure('d1', timestamp=1)
    assert approx_equal(p.min_wait(timestamp=1), 1)
    p.set_running('d1')
    p.lost('d1', timestamp=2)
    assert approx_equal(p.min_wait(timestamp=2), 1)
    p.set_running('d1')
    p.add_failure('d1', timestamp=3)
    assert p.min_wait(timestamp=3) == TaskPlanner.INFINITY
Esempio n. 2
0
def test_task_waits():
    dt = p1(daemon=True, max_failures=0)
    p = TaskPlanner(
        empty_task(processes=[
            dt(name='d3', min_duration=3),
            dt(name='d5', min_duration=5),
            dt(name='d7', min_duration=7)
        ]))
    assert p.runnable_at(timestamp=0) == _('d3', 'd5', 'd7')
    assert p.min_wait(timestamp=0) == 0

    p.set_running('d3')
    p.add_success('d3', timestamp=0)
    assert p.runnable_at(timestamp=0) == _('d5', 'd7')
    assert p.waiting_at(timestamp=0) == _('d3')
    assert approx_equal(p.get_wait('d3', timestamp=0), 3)
    assert approx_equal(p.min_wait(timestamp=0), 0)
    assert approx_equal(p.min_wait(timestamp=1), 0)
    assert p.waiting_at(timestamp=3) == empty
    assert p.runnable_at(timestamp=3) == _('d3', 'd5', 'd7')

    p.set_running('d3')
    p.set_running('d7')
    p.add_success('d7', timestamp=1)
    assert approx_equal(p.min_wait(timestamp=2), 0)
    p.set_running('d5')
    assert approx_equal(p.min_wait(timestamp=2), 6)
    p.add_success('d5', timestamp=2)
    p.add_success('d3', timestamp=2)
    assert approx_equal(p.min_wait(timestamp=3), 2)
    assert p.runnable_at(timestamp=2) == empty
    assert p.runnable_at(timestamp=5) == _('d3')
    assert p.runnable_at(timestamp=7) == _('d3', 'd5')
    assert p.runnable_at(timestamp=8) == _('d3', 'd5', 'd7')
def test_task_lost():
  dt = p1(max_failures=2, min_duration=1)

  # regular success behavior
  p = TaskPlanner(empty_task(processes = [dt(name='d1')]))
  assert p.runnable_at(timestamp=0) == _('d1')
  p.set_running('d1')
  p.add_success('d1', timestamp=0)
  assert p.min_wait(timestamp=0) == TaskPlanner.INFINITY

  # regular failure behavior
  p = TaskPlanner(empty_task(processes = [dt(name='d1')]))
  assert p.runnable_at(timestamp=0) == _('d1')
  p.set_running('d1')
  p.add_failure('d1', timestamp=1)
  assert approx_equal(p.min_wait(timestamp=1), 1)
  p.set_running('d1')
  p.add_failure('d1', timestamp=3)
  assert p.min_wait(timestamp=3) == TaskPlanner.INFINITY

  # lost behavior
  p = TaskPlanner(empty_task(processes = [dt(name='d1')]))
  assert p.runnable_at(timestamp=0) == _('d1')
  p.set_running('d1')
  p.add_failure('d1', timestamp=1)
  assert approx_equal(p.min_wait(timestamp=1), 1)
  p.set_running('d1')
  p.lost('d1')
  assert approx_equal(p.min_wait(timestamp=1), 1)
  p.set_running('d1')
  p.add_failure('d1', timestamp=3)
  assert p.min_wait(timestamp=3) == TaskPlanner.INFINITY
def test_task_waits():
  dt = p1(daemon=True, max_failures=0)
  p = TaskPlanner(empty_task(processes=[dt(name='d3', min_duration=3),
                                        dt(name='d5', min_duration=5),
                                        dt(name='d7', min_duration=7)]))
  assert p.runnable_at(timestamp=0) == _('d3', 'd5', 'd7')
  assert p.min_wait(timestamp=0) == 0

  p.set_running('d3')
  p.add_success('d3', timestamp=0)
  assert p.runnable_at(timestamp=0) == _('d5', 'd7')
  assert p.waiting_at(timestamp=0) == _('d3')
  assert approx_equal(p.get_wait('d3', timestamp=0), 3)
  assert approx_equal(p.min_wait(timestamp=0), 0)
  assert approx_equal(p.min_wait(timestamp=1), 0)
  assert p.waiting_at(timestamp=3) == empty
  assert p.runnable_at(timestamp=3) == _('d3', 'd5', 'd7')

  p.set_running('d3')
  p.set_running('d7')
  p.add_success('d7', timestamp=1)
  assert approx_equal(p.min_wait(timestamp=2), 0)
  p.set_running('d5')
  assert approx_equal(p.min_wait(timestamp=2), 6)
  p.add_success('d5', timestamp=2)
  p.add_success('d3', timestamp=2)
  assert approx_equal(p.min_wait(timestamp=3), 2)
  assert p.runnable_at(timestamp=2) == empty
  assert p.runnable_at(timestamp=5) == _('d3')
  assert p.runnable_at(timestamp=7) == _('d3', 'd5')
  assert p.runnable_at(timestamp=8) == _('d3', 'd5', 'd7')
Esempio n. 5
0
def test_task_fails():
    dt = p1(max_failures=1, min_duration=1)
    p = TaskPlanner(empty_task(processes=[dt(name='d1'), dt(name='d2')]))
    assert p.runnable_at(timestamp=0) == _('d1', 'd2')
    p.set_running('d1')
    p.set_running('d2')
    assert p.runnable_at(timestamp=0) == empty
    p.add_failure('d1', timestamp=0)
    p.add_failure('d2', timestamp=0)
    assert p.runnable_at(timestamp=0) == empty
    assert p.min_wait(timestamp=0) == TaskPlanner.INFINITY

    p = TaskPlanner(empty_task(processes=[dt(name='d1'), dt(name='d2')]))
    assert p.runnable_at(timestamp=0) == _('d1', 'd2')
    p.set_running('d1')
    p.set_failed('d1')
    assert p.runnable_at(timestamp=0) == _('d2')
    p.set_running('d2')
    assert p.runnable_at(timestamp=0) == empty
    p.add_failure('d2', timestamp=0)
    assert p.runnable_at(timestamp=0) == empty
    assert p.min_wait(timestamp=0) == TaskPlanner.INFINITY

    # test max_failures=0 && daemon==True ==> retries forever
    p = TaskPlanner(
        empty_task(processes=[dt(name='d1', max_failures=0, daemon=True)]))
    for k in range(10):
        p.set_running('d1')
        assert 'd1' in p.running
        assert 'd1' not in p.failed
        p.add_failure('d1')
        assert 'd1' not in p.running
        assert 'd1' not in p.failed
        p.set_running('d1')
        assert 'd1' in p.running
        assert 'd1' not in p.failed
        p.add_success('d1')
        assert 'd1' not in p.running
        assert 'd1' not in p.failed
        assert 'd1' not in p.finished

    p = TaskPlanner(empty_task(processes=[dt(name='d1', max_failures=0)]))
    p.set_running('d1')
    assert 'd1' in p.running
    assert 'd1' not in p.failed
    p.add_failure('d1')
    assert 'd1' not in p.running
    assert 'd1' not in p.failed
    p.set_running('d1')
    assert 'd1' in p.running
    assert 'd1' not in p.failed
    p.add_success('d1')
    assert 'd1' not in p.running
    assert 'd1' not in p.failed
    assert 'd1' in p.finished
def test_task_fails():
  dt = p1(max_failures=1, min_duration=1)
  p = TaskPlanner(empty_task(processes = [dt(name='d1'), dt(name='d2')]))
  assert p.runnable_at(timestamp=0) == _('d1', 'd2')
  p.set_running('d1')
  p.set_running('d2')
  assert p.runnable_at(timestamp=0) == empty
  p.add_failure('d1', timestamp=0)
  p.add_failure('d2', timestamp=0)
  assert p.runnable_at(timestamp=0) == empty
  assert p.min_wait(timestamp=0) == TaskPlanner.INFINITY

  p = TaskPlanner(empty_task(processes = [dt(name='d1'), dt(name='d2')]))
  assert p.runnable_at(timestamp=0) == _('d1', 'd2')
  p.set_running('d1')
  p.set_failed('d1')
  assert p.runnable_at(timestamp=0) == _('d2')
  p.set_running('d2')
  assert p.runnable_at(timestamp=0) == empty
  p.add_failure('d2', timestamp=0)
  assert p.runnable_at(timestamp=0) == empty
  assert p.min_wait(timestamp=0) == TaskPlanner.INFINITY

  # test max_failures=0 && daemon==True ==> retries forever
  p = TaskPlanner(empty_task(processes = [dt(name='d1', max_failures=0, daemon=True)]))
  for k in range(10):
    p.set_running('d1')
    assert 'd1' in p.running
    assert 'd1' not in p.failed
    p.add_failure('d1')
    assert 'd1' not in p.running
    assert 'd1' not in p.failed
    p.set_running('d1')
    assert 'd1' in p.running
    assert 'd1' not in p.failed
    p.add_success('d1')
    assert 'd1' not in p.running
    assert 'd1' not in p.failed
    assert 'd1' not in p.finished

  p = TaskPlanner(empty_task(processes = [dt(name='d1', max_failures=0)]))
  p.set_running('d1')
  assert 'd1' in p.running
  assert 'd1' not in p.failed
  p.add_failure('d1')
  assert 'd1' not in p.running
  assert 'd1' not in p.failed
  p.set_running('d1')
  assert 'd1' in p.running
  assert 'd1' not in p.failed
  p.add_success('d1')
  assert 'd1' not in p.running
  assert 'd1' not in p.failed
  assert 'd1' in p.finished
Esempio n. 7
0
def test_task_daemon_duration():
    p = TaskPlanner(
        empty_task(
            processes=[p1(daemon=True, max_failures=2, min_duration=10)]))
    assert 'p1' in p.runnable
    p.set_running('p1')
    p.add_success('p1', timestamp=5)
    assert 'p1' not in p.runnable_at(timestamp=5)
    assert 'p1' not in p.runnable_at(timestamp=10)
    assert 'p1' in p.runnable_at(timestamp=15)
    assert 'p1' in p.runnable_at(timestamp=20)
    p.set_running('p1')
    p.add_failure('p1', timestamp=10)
    assert 'p1' not in p.runnable_at(timestamp=10)
    assert 'p1' not in p.runnable_at(timestamp=15)
    assert 'p1' in p.runnable_at(timestamp=20)
    assert 'p1' in p.runnable_at(timestamp=25)
    p.set_running('p1')
    p.add_failure('p1', timestamp=15)
    assert 'p1' not in p.runnable_at(timestamp=15)
    assert 'p1' not in p.runnable_at(timestamp=20)
    assert 'p1' not in p.runnable_at(
        timestamp=25)  # task past maximum failure limit
    assert 'p1' not in p.runnable_at(timestamp=30)
def test_task_daemon_duration():
  p = TaskPlanner(empty_task(processes=[p1(daemon=True, max_failures=2, min_duration=10)]))
  assert 'p1' in p.runnable
  p.set_running('p1')
  p.add_success('p1', timestamp=5)
  assert 'p1' not in p.runnable_at(timestamp=5)
  assert 'p1' not in p.runnable_at(timestamp=10)
  assert 'p1' in p.runnable_at(timestamp=15)
  assert 'p1' in p.runnable_at(timestamp=20)
  p.set_running('p1')
  p.add_failure('p1', timestamp=10)
  assert 'p1' not in p.runnable_at(timestamp=10)
  assert 'p1' not in p.runnable_at(timestamp=15)
  assert 'p1' in p.runnable_at(timestamp=20)
  assert 'p1' in p.runnable_at(timestamp=25)
  p.set_running('p1')
  p.add_failure('p1', timestamp=15)
  assert 'p1' not in p.runnable_at(timestamp=15)
  assert 'p1' not in p.runnable_at(timestamp=20)
  assert 'p1' not in p.runnable_at(timestamp=25)  # task past maximum failure limit
  assert 'p1' not in p.runnable_at(timestamp=30)