示例#1
0
def test_reset_outputs(before, after, outputs):
    """Test that outputs are reset correctly on state changes."""
    tdef = TaskDef('foo', {}, 'live', '123', True)

    orig_status, orig_is_held = before
    new_status, new_is_held = after

    tstate = TaskState(tdef, '123', orig_status, orig_is_held)
    assert tstate.outputs.get_completed() == []
    tstate.reset(status=new_status, is_held=new_is_held)
    assert tstate.outputs.get_completed() == outputs
示例#2
0
def test_collate(xtrigger_mgr):
    """Test that collate properly tallies the totals of current xtriggers."""
    xtrigger_mgr.collate(itasks=[])
    assert not xtrigger_mgr.all_xtrig

    # add a xtrigger
    # that will cause all_xtrig to be populated
    get_name = SubFuncContext(label="get_name",
                              func_name="get_name",
                              func_args=[],
                              func_kwargs={})
    xtrigger_mgr.add_trig("get_name", get_name, 'fdir')
    get_name.out = "[\"True\", {\"name\": \"Yossarian\"}]"
    tdef = TaskDef(name="foo", rtcfg=None, run_mode="live", start_point=1)
    init()
    sequence = ISO8601Sequence('P1D', '20190101T00Z')
    tdef.xtrig_labels[sequence] = ["get_name"]
    start_point = ISO8601Point('2019')
    itask = TaskProxy(tdef, start_point, FlowLabelMgr().get_new_label())
    itask.state.xtriggers["get_name"] = get_name

    xtrigger_mgr.collate([itask])
    assert xtrigger_mgr.all_xtrig

    # add a clock xtrigger
    # that will cause both all_xclock to be populated but not all_xtrig
    wall_clock = SubFuncContext(label="wall_clock",
                                func_name="wall_clock",
                                func_args=[],
                                func_kwargs={})
    wall_clock.out = "[\"True\", \"1\"]"
    xtrigger_mgr.add_trig("wall_clock", wall_clock, "fdir")
    # create a task
    tdef = TaskDef(name="foo", rtcfg=None, run_mode="live", start_point=1)
    tdef.xtrig_labels[sequence] = ["wall_clock"]
    start_point = ISO8601Point('20000101T0000+05')
    # create task proxy
    itask = TaskProxy(tdef, start_point, FlowLabelMgr().get_new_label())

    xtrigger_mgr.collate([itask])
    assert not xtrigger_mgr.all_xtrig
def test_reset(state, is_held, should_reset):
    """Test that tasks do or don't have their state changed."""
    tdef = TaskDef('foo', {}, 'live', '123', '123')
    # create task state:
    #   * status: waiting
    #   * is_held: true
    tstate = TaskState(tdef, '123', TASK_STATUS_WAITING, True)
    assert tstate.reset(state, is_held) == should_reset
    if is_held is not None:
        assert tstate.is_held == is_held
    if state is not None:
        assert tstate.status == state
def test_state_comparison(state, is_held):
    """Test the __call__ method."""
    tdef = TaskDef('foo', {}, 'live', '123', '123')
    tstate = TaskState(tdef, '123', state, is_held)

    assert tstate(state, is_held=is_held)
    assert tstate(state)
    assert tstate(is_held=is_held)
    assert tstate(state, 'of', 'flux')
    assert tstate(state, 'of', 'flux', is_held=is_held)

    assert not tstate(state + 'x', is_held=not is_held)
    assert not tstate(state, is_held=not is_held)
    assert not tstate(state + 'x', is_held=is_held)
    assert not tstate(state + 'x')
    assert not tstate(is_held=not is_held)
    assert not tstate(state + 'x', 'of', 'flux')
示例#5
0
 def test_reset_state(self):
     """Test instantiation and simple resets."""
     point = ISO8601Point('2020')
     taskdef = TaskDef('who-cares', {}, 'live', point, False)
     taskstate = TaskState(taskdef, point, TASK_STATUS_WAITING, None)
     self.assertIsNone(
         taskstate.reset_state(TASK_STATUS_WAITING),
         'same status returns None',
     )
     self.assertEqual(
         taskstate.reset_state(TASK_STATUS_SUCCEEDED),
         (TASK_STATUS_WAITING, None),
         'different status returns previous (status, hold_swap)',
     )
     self.assertEqual(
         (taskstate.status, taskstate.hold_swap),
         (TASK_STATUS_SUCCEEDED, None),
         'reset status OK',
     )
示例#6
0
 def test_reset_state_respect_hold_swap(self):
     point = ISO8601Point('2020')
     taskdef = TaskDef('who-cares', {}, 'live', point, False)
     taskstate = TaskState(taskdef, point, TASK_STATUS_HELD,
                           TASK_STATUS_RETRYING)
     self.assertIsNone(
         taskstate.reset_state(TASK_STATUS_RETRYING,
                               respect_hold_swap=True),
         'same status returns None',
     )
     self.assertEqual(
         taskstate.reset_state(TASK_STATUS_SUCCEEDED,
                               respect_hold_swap=True),
         (TASK_STATUS_HELD, TASK_STATUS_RETRYING),
         'different status returns previous (status, hold_swap)',
     )
     self.assertEqual(
         (taskstate.status, taskstate.hold_swap),
         (TASK_STATUS_SUCCEEDED, None),
         'reset status OK',
     )
示例#7
0
def test_housekeeping_with_xtrigger_satisfied(xtrigger_mgr):
    """The housekeeping method makes sure only satisfied xtrigger function
    are kept."""
    xtrig = SubFuncContext(label="get_name",
                           func_name="get_name",
                           func_args=[],
                           func_kwargs={})
    xtrigger_mgr.add_trig("get_name", xtrig, 'fdir')
    xtrig.out = "[\"True\", {\"name\": \"Yossarian\"}]"
    tdef = TaskDef(name="foo", rtcfg=None, run_mode="live", start_point=1)
    init()
    sequence = ISO8601Sequence('P1D', '2019')
    tdef.xtrig_labels[sequence] = ["get_name"]
    start_point = ISO8601Point('2019')
    itask = TaskProxy(tdef, start_point, FlowLabelMgr().get_new_label())
    xtrigger_mgr.collate([itask])
    # pretend the function has been activated
    xtrigger_mgr.active.append(xtrig.get_signature())
    xtrigger_mgr.callback(xtrig)
    assert xtrigger_mgr.sat_xtrig
    xtrigger_mgr.housekeep()
    # here we still have the same number as before
    assert xtrigger_mgr.sat_xtrig
示例#8
0
def test_satisfy_xtrigger():
    """Test satisfy_xtriggers"""
    # the XtriggerManager instance
    xtrigger_mgr = XtriggerManager(
        suite="sample_suite",
        user="******",
        proc_pool=MockedProcPool(),
        broadcast_mgr=MockedBroadcastMgr(suite_db_mgr=None))
    # the echo1 xtrig (not satisfied)
    echo1_xtrig = SubFuncContext(label="echo1",
                                 func_name="echo1",
                                 func_args=[],
                                 func_kwargs={})
    echo1_xtrig.out = "[\"True\", {\"name\": \"herminia\"}]"
    xtrigger_mgr.add_trig("echo1", echo1_xtrig)
    # the echo2 xtrig (satisfied through callback later)
    echo2_xtrig = SubFuncContext(label="echo2",
                                 func_name="echo2",
                                 func_args=[],
                                 func_kwargs={})
    echo2_xtrig.out = "[\"True\", {\"name\": \"herminia\"}]"
    xtrigger_mgr.add_trig("echo2", echo2_xtrig)
    # create a task
    tdef = TaskDef(name="foo",
                   rtcfg=None,
                   run_mode="live",
                   start_point=1,
                   spawn_ahead=False)
    tdef.xtrig_labels.add("echo1")
    tdef.xtrig_labels.add("echo2")
    # cycle point for task proxy
    init()
    start_point = ISO8601Point('20000101T0000+05')
    # create task proxy
    itask = TaskProxy(tdef=tdef, start_point=start_point)

    # we start with no satisfied xtriggers, and nothing active
    assert len(xtrigger_mgr.sat_xtrig) == 0
    assert len(xtrigger_mgr.active) == 0

    # after calling satisfy_xtriggers the first time, we get two active
    xtrigger_mgr.satisfy_xtriggers(itask)
    assert len(xtrigger_mgr.sat_xtrig) == 0
    assert len(xtrigger_mgr.active) == 2

    # calling satisfy_xtriggers again does not change anything
    xtrigger_mgr.satisfy_xtriggers(itask)
    assert len(xtrigger_mgr.sat_xtrig) == 0
    assert len(xtrigger_mgr.active) == 2

    # now we call callback manually as the proc_pool we passed is a mock
    # then both should be satisfied
    xtrigger_mgr.callback(echo1_xtrig)
    xtrigger_mgr.callback(echo2_xtrig)
    # so both were satisfied, and nothing is active
    assert len(xtrigger_mgr.sat_xtrig) == 2
    assert len(xtrigger_mgr.active) == 0

    # calling satisfy_xtriggers again still does not change anything
    xtrigger_mgr.satisfy_xtriggers(itask)
    assert len(xtrigger_mgr.sat_xtrig) == 2
    assert len(xtrigger_mgr.active) == 0
示例#9
0
def test__call_xtriggers_async(xtrigger_mgr):
    """Test _call_xtriggers_async"""
    xtrigger_mgr.validate_xtrigger = lambda *a, **k: True  # Ignore validation
    # the echo1 xtrig (not satisfied)
    echo1_xtrig = SubFuncContext(
        label="echo1",
        func_name="echo1",
        func_args=[],
        func_kwargs={}
    )

    echo1_xtrig.out = "[\"True\", {\"name\": \"herminia\"}]"
    xtrigger_mgr.add_trig("echo1", echo1_xtrig, "fdir")
    # the echo2 xtrig (satisfied through callback later)
    echo2_xtrig = SubFuncContext(
        label="echo2",
        func_name="echo2",
        func_args=[],
        func_kwargs={}
    )
    echo2_xtrig.out = "[\"True\", {\"name\": \"herminia\"}]"
    xtrigger_mgr.add_trig("echo2", echo2_xtrig, "fdir")
    # create a task
    tdef = TaskDef(
        name="foo",
        rtcfg=None,
        run_mode="live",
        start_point=1,
        initial_point=1
    )
    init()
    sequence = ISO8601Sequence('P1D', '2000')
    tdef.xtrig_labels[sequence] = ["echo1", "echo2"]
    # cycle point for task proxy
    init()
    start_point = ISO8601Point('2019')
    # create task proxy
    itask = TaskProxy(tdef, start_point)

    # we start with no satisfied xtriggers, and nothing active
    assert len(xtrigger_mgr.sat_xtrig) == 0
    assert len(xtrigger_mgr.active) == 0

    # after calling the first time, we get two active
    xtrigger_mgr.call_xtriggers_async(itask)
    assert len(xtrigger_mgr.sat_xtrig) == 0
    assert len(xtrigger_mgr.active) == 2

    # calling again does not change anything
    xtrigger_mgr.call_xtriggers_async(itask)
    assert len(xtrigger_mgr.sat_xtrig) == 0
    assert len(xtrigger_mgr.active) == 2

    # now we call callback manually as the proc_pool we passed is a mock
    # then both should be satisfied
    xtrigger_mgr.callback(echo1_xtrig)
    xtrigger_mgr.callback(echo2_xtrig)
    # so both were satisfied, and nothing is active
    assert len(xtrigger_mgr.sat_xtrig) == 2
    assert len(xtrigger_mgr.active) == 0

    # calling satisfy_xtriggers again still does not change anything
    xtrigger_mgr.call_xtriggers_async(itask)
    assert len(xtrigger_mgr.sat_xtrig) == 2
    assert len(xtrigger_mgr.active) == 0