def test_chained_health_interface():
  hi = ChainedStatusChecker([])
  assert hi.status is None

  hi = ChainedStatusChecker([Healthy()])
  assert hi.status is None

  si1 = EventHealth()
  si2 = EventHealth()
  chained_si = ChainedStatusChecker([si1, si2])

  for si in (si1, si2):
    assert not si.started.is_set()
  chained_si.start()
  for si in (si1, si2):
    assert si.started.is_set()

  assert chained_si.status is None
  reason = StatusResult('derp', ExitState.FAILED)
  si2.set_status(reason)
  assert chained_si.status == reason
  assert chained_si.status.reason == 'derp'
  assert chained_si.status.status == ExitState.FAILED

  for si in (si1, si2):
    assert not si.stopped.is_set()
  chained_si.stop()
  for si in (si1, si2):
    assert si.stopped.is_set()
Exemple #2
0
def test_chained_healthy_status_failed():
    hi = ChainedStatusChecker([EventHealth(TASK_FAILED)])
    assert hi.status is TASK_FAILED

    hi = ChainedStatusChecker([
        EventHealth(TASK_FAILED),
        EventHealth(TASK_FAILED),
        EventHealth(TASK_FAILED)
    ])
    assert hi.status is TASK_FAILED
Exemple #3
0
def test_chained_healthy_status_starting():
    hi = ChainedStatusChecker([EventHealth(TASK_STARTING)])
    assert hi.status is TASK_STARTING

    hi = ChainedStatusChecker([
        EventHealth(TASK_STARTING),
        EventHealth(TASK_STARTING),
        EventHealth(TASK_STARTING)
    ])
    assert hi.status is TASK_STARTING
Exemple #4
0
def test_chained_healthy_status_running():
    hi = ChainedStatusChecker([EventHealth(TASK_RUNNING)])
    assert hi.status is TASK_RUNNING

    hi = ChainedStatusChecker([
        EventHealth(TASK_RUNNING),
        EventHealth(TASK_RUNNING),
        EventHealth(TASK_RUNNING)
    ])
    assert hi.status is TASK_RUNNING
Exemple #5
0
def test_chained_status_starting_trumps_running_and_none():
    hi = ChainedStatusChecker(
        [EventHealth(),
         EventHealth(TASK_RUNNING),
         EventHealth(TASK_STARTING)])
    assert hi.status is TASK_STARTING

    hi = ChainedStatusChecker(
        [EventHealth(TASK_STARTING),
         EventHealth(TASK_RUNNING),
         EventHealth()])
    assert hi.status is TASK_STARTING
Exemple #6
0
def test_chained_health_interface():
    hi = ChainedStatusChecker([])
    assert hi.status is None

    hi = ChainedStatusChecker([Healthy()])
    assert hi.status is None

    si1 = EventHealth()
    si2 = EventHealth()
    chained_si = ChainedStatusChecker([si1, si2])

    for si in (si1, si2):
        assert not si.started.is_set()
    chained_si.start()
    for si in (si1, si2):
        assert si.started.is_set()

    assert chained_si.status is None
    reason = StatusResult('derp', TaskState.Value('TASK_FAILED'))
    si2.set_status(reason)
    assert chained_si.status == reason
    assert chained_si.status.reason == 'derp'
    assert TaskState.Name(chained_si.status.status) == 'TASK_FAILED'

    for si in (si1, si2):
        assert not si.stopped.is_set()
    chained_si.stop()
    for si in (si1, si2):
        assert si.stopped.is_set()
Exemple #7
0
def test_chained_status_failed_trumps_all():
    hi = ChainedStatusChecker([
        EventHealth(),
        EventHealth(TASK_RUNNING),
        EventHealth(TASK_STARTING),
        EventHealth(TASK_FAILED)
    ])
    assert hi.status is TASK_FAILED

    hi = ChainedStatusChecker([
        EventHealth(TASK_FAILED),
        EventHealth(TASK_STARTING),
        EventHealth(TASK_RUNNING),
        EventHealth()
    ])
    assert hi.status is TASK_FAILED
Exemple #8
0
def test_chained_status_starting_to_running_consensus():
    eh1 = EventHealth(TASK_STARTING)
    eh2 = EventHealth(TASK_STARTING)
    hi = ChainedStatusChecker([eh1, eh2])
    assert hi.status is TASK_STARTING

    eh1.set_status(TASK_RUNNING)
    assert hi.status is TASK_STARTING

    eh2.set_status(TASK_RUNNING)
    assert hi.status is TASK_RUNNING
Exemple #9
0
def test_chained_status_failed_is_terminal():
    eh = EventHealth(TASK_FAILED)
    hi = ChainedStatusChecker([eh])
    assert hi.status is TASK_FAILED

    eh.set_status(TASK_RUNNING)
    assert hi.status is TASK_FAILED

    eh.set_status(TASK_STARTING)
    assert hi.status is TASK_FAILED

    eh.set_status(None)
    assert hi.status is TASK_FAILED
Exemple #10
0
def test_chained_healthy_status_none():
    hi = ChainedStatusChecker([EventHealth()])
    assert hi.status is None

    hi = ChainedStatusChecker([EventHealth(), EventHealth(), EventHealth()])
    assert hi.status is None
Exemple #11
0
def test_chained_empty_checkers():
    hi = ChainedStatusChecker([])
    assert hi.status is None
Exemple #12
0
def test_chained_status_raises_unknown_status_result():
    hi = ChainedStatusChecker([EventHealth(1)])
    with pytest.raises(TypeError):
        hi.status