def test_housekeeping_with_xtrigger_satisfied(): """The housekeeping method makes sure only satisfied xtrigger function are kept.""" xtrigger_mgr = XtriggerManager(suite="sample_suite", user="******") xtrig = SubFuncContext(label="get_name", func_name="get_name", func_args=[], func_kwargs={}) xtrigger_mgr.add_trig("get_name", xtrig) xtrig.out = "[\"True\", {\"name\": \"Yossarian\"}]" tdef = TaskDef(name="foo", rtcfg=None, run_mode="live", start_point=1, spawn_ahead=False) tdef.xtrig_labels.add("get_name") start_point = ISO8601Point('20000101T0000+05') itask = TaskProxy(tdef=tdef, start_point=start_point) 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 # however, we have no xclock trigger satisfied assert not xtrigger_mgr.sat_xclock
def test_housekeeping_with_xclock_satisfied(): """The housekeeping method makes sure only satisfied xclock function are kept.""" xtrigger_mgr = XtriggerManager(suite="sample_suite", user="******") # the clock xtrigger xtrig = SubFuncContext(label="wall_clock", func_name="wall_clock", func_args=[], func_kwargs={}) xtrig.out = "[\"True\", \"1\"]" xtrigger_mgr.add_clock("wall_clock", xtrig) # create a task tdef = TaskDef(name="foo", rtcfg=None, run_mode="live", start_point=1, spawn_ahead=False) tdef.xclock_label = "wall_clock" # cycle point for task proxy # TODO: we need to call init, before we can use ISO8601 points in Cylc, # why? init() start_point = ISO8601Point('20000101T0000+05') # create task proxy itask = TaskProxy(tdef=tdef, start_point=start_point) itask.state.xclock = "wall_clock", False # satisfied? # satisfy xclock xtrigger_mgr.satisfy_xclock(itask) # tally xtrigger_mgr.collate([itask]) assert xtrigger_mgr.sat_xclock xtrigger_mgr.housekeep() # here we still have the same number as before assert xtrigger_mgr.sat_xclock
def test_housekeeping_nothing_satisfied(): """The housekeeping method makes sure only satisfied xtrigger function are kept.""" xtrigger_mgr = XtriggerManager(suite="sample_suite", user="******") row = "get_name", "{\"name\": \"function\"}" # now XtriggerManager#sat_xtrigger will contain the get_name xtrigger xtrigger_mgr.load_xtrigger_for_restart(row_idx=0, row=row) # but we have nothing in the XtriggerManager#all_xclock, which means # nothing was satisfied yet xtrigger_mgr.all_xclock.clear() assert xtrigger_mgr.sat_xtrig xtrigger_mgr.housekeep() assert not xtrigger_mgr.sat_xtrig