def test_task_failed_predecessor_does_not_make_process_runnable():
  p = TaskPlanner(empty_task(processes=[p1, p2], constraints=[{'order': ['p1', 'p2']}]))
  p.set_running('p1')
  p.add_success('p1')
  assert 'p2' in p.runnable
  assert not p.is_complete()

  p = TaskPlanner(empty_task(processes=[p1, p2], constraints=[{'order': ['p1', 'p2']}]))
  p.set_running('p1')
  p.add_failure('p1')
  assert 'p2' not in p.runnable
  assert not p.is_complete()
def test_task_failed_predecessor_does_not_make_process_runnable():
  p = TaskPlanner(empty_task(processes=[p1, p2], constraints=[{'order': ['p1', 'p2']}]))
  p.set_running('p1')
  p.add_success('p1')
  assert 'p2' in p.runnable
  assert not p.is_complete()

  p = TaskPlanner(empty_task(processes=[p1, p2], constraints=[{'order': ['p1', 'p2']}]))
  p.set_running('p1')
  p.add_failure('p1')
  assert 'p2' not in p.runnable
  assert not p.is_complete()
Exemplo n.º 3
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
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
Exemplo 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
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)
Exemplo n.º 9
0
def test_task_finish_with_daemons():
    # Daemon is still restricted to the failure limit
    p = TaskPlanner(empty_task(processes=[p1(daemon=True)]))
    assert not p.is_complete()
    p.set_running('p1')
    assert not p.is_complete()
    p.add_failure('p1')
    assert p.is_complete()

    # Resilient to two failures
    p = TaskPlanner(empty_task(processes=[p1(daemon=True, max_failures=2)]))
    assert not p.is_complete()
    p.set_running('p1')
    assert not p.is_complete()
    p.add_failure('p1')
    assert not p.is_complete()
    p.set_running('p1')
    assert not p.is_complete()
    p.add_failure('p1')
    assert p.is_complete()

    # Can swallow successes
    p = TaskPlanner(empty_task(processes=[p1(daemon=True, max_failures=2)]))
    assert not p.is_complete()
    p.set_running('p1')
    assert not p.is_complete()
    p.add_failure('p1')
    assert not p.is_complete()
    p.set_running('p1')
    assert not p.is_complete()
    p.add_success('p1')
    assert not p.is_complete()
    p.set_running('p1')
    assert not p.is_complete()
    p.add_failure('p1')
    assert p.is_complete()
def test_task_finish_with_daemons():
  # Daemon is still restricted to the failure limit
  p = TaskPlanner(empty_task(processes=[p1(daemon=True)]))
  assert not p.is_complete()
  p.set_running('p1')
  assert not p.is_complete()
  p.add_failure('p1')
  assert p.is_complete()

  # Resilient to two failures
  p = TaskPlanner(empty_task(processes=[p1(daemon=True, max_failures=2)]))
  assert not p.is_complete()
  p.set_running('p1')
  assert not p.is_complete()
  p.add_failure('p1')
  assert not p.is_complete()
  p.set_running('p1')
  assert not p.is_complete()
  p.add_failure('p1')
  assert p.is_complete()

  # Can swallow successes
  p = TaskPlanner(empty_task(processes=[p1(daemon=True, max_failures=2)]))
  assert not p.is_complete()
  p.set_running('p1')
  assert not p.is_complete()
  p.add_failure('p1')
  assert not p.is_complete()
  p.set_running('p1')
  assert not p.is_complete()
  p.add_success('p1')
  assert not p.is_complete()
  p.set_running('p1')
  assert not p.is_complete()
  p.add_failure('p1')
  assert p.is_complete()
Exemplo n.º 11
0
def test_task_finish_with_ephemerals():
    pure_ephemeral = empty_task(processes=[p1(ephemeral=True)])
    p = TaskPlanner(pure_ephemeral)
    assert p.is_complete()
    p.set_running('p1')
    assert p.is_complete()
    p.add_failure('p1')
    assert p.is_complete()
    assert not p.failed
    assert p.finished == _('p1')

    with_ephemeral = empty_task(processes=[p1, p2(ephemeral=True)])
    p = TaskPlanner(with_ephemeral)
    assert not p.is_complete()
    assert p.runnable == _('p1', 'p2')
    p.set_running('p1')
    assert not p.is_complete()
    p.add_failure('p1')
    assert p.is_complete()
    p.set_running('p2')
    assert p.is_complete()
    p.add_failure('p2')
    assert p.is_complete()
    assert p.failed == _('p1')
def test_task_finish_with_ephemerals():
  pure_ephemeral = empty_task(processes=[p1(ephemeral=True)])
  p = TaskPlanner(pure_ephemeral)
  assert p.is_complete()
  p.set_running('p1')
  assert p.is_complete()
  p.add_failure('p1')
  assert p.is_complete()
  assert not p.failed
  assert p.finished == _('p1')

  with_ephemeral = empty_task(processes=[p1, p2(ephemeral=True)])
  p = TaskPlanner(with_ephemeral)
  assert not p.is_complete()
  assert p.runnable == _('p1', 'p2')
  p.set_running('p1')
  assert not p.is_complete()
  p.add_failure('p1')
  assert p.is_complete()
  p.set_running('p2')
  assert p.is_complete()
  p.add_failure('p2')
  assert p.is_complete()
  assert p.failed == _('p1')