Commit 2760de6d authored by Jameson Rollins's avatar Jameson Rollins

require per-state opt-in for same-state redirect

The same-state redirect (when there is a request for the current executing
state that causes it to redirect back to the top of the state and reexecute
the main method) is somewhat unintuitive and has caused problems:

#18

This change requires that an edge exist from a state to itself in order
for a same-state redirect to take place place, e.g.:

edge = [('STATE', 'STATE')]

A new test was added for this change.
parent 21e988cc
......@@ -316,7 +316,8 @@ guardian version: {}
self.raise_redirect()
elif self.single_shot:
pass
elif inedge == outedge == False:
# same-state redirect only if state has edge to itself
elif inedge == outedge == False and self.system.graph.has_edge(self['STATE'], self['STATE']):
self.log.info("same state request redirect")
self.raise_redirect()
......
......@@ -43,10 +43,22 @@ class E(GuardState):
def run(self):
ezca['D'] = 3
class F(GuardState):
def main(self):
ezca['C'] = 1
def run(self):
if ezca['C'] == 1:
return False
ezca['C'] = 2
return True
edges = [
('INIT', 'A'),
('A', 'B'),
('B', 'C'),
('B', 'D'),
('D', 'E'),
('B', 'F'),
('F', 'F'),
]
......@@ -315,6 +315,56 @@ T1:GRD-TEST_STATUS..ENTER..
T1:GRD-TEST_STATUS..MAIN..
T1:GRD-TEST_STATUS..RUN..
T1:GRD-TEST_STATUS..DONE..
T1:TEST-A..0..
T1:TEST-B..0..
T1:TEST-C..0..
T1:TEST-A..1..
T1:TEST-A..0..
T1:TEST-B..1..
T1:TEST-C..1..
T1:TEST-C..3..
T1:TEST-C..2..
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "same-state redirect"
testioc ${IFO}:TEST- &
guardian --name=TEST TEST_redirect &
wait_node_ready TEST
cawait T1:GRD-TEST_STATUS DONE
camonitor -tn -F. T1:GRD-TEST_{STATE,REQUEST,STATUS} >OUTPUT_grd &
camonitor -tn -F. T1:TEST-{A,B,C} >OUTPUT_ezca &
sleep .2
caput T1:GRD-TEST_REQUEST F
cawait T1:TEST-C 1
caput T1:TEST-C 3
cawait T1:GRD-TEST_STATUS DONE
caput T1:GRD-TEST_REQUEST F
sleep .2
cawait T1:GRD-TEST_STATUS RUN
kill_jobs
cat OUTPUT_{grd,ezca} | uniq >OUTPUT
cat <<EOF >EXPECTED
T1:GRD-TEST_STATE..INIT..
T1:GRD-TEST_REQUEST..NONE..
T1:GRD-TEST_STATUS..DONE..
T1:GRD-TEST_REQUEST..F..
T1:GRD-TEST_STATUS..EDGE..
T1:GRD-TEST_STATE..A..
T1:GRD-TEST_STATUS..ENTER..
T1:GRD-TEST_STATUS..MAIN..
T1:GRD-TEST_STATUS..RUN..
T1:GRD-TEST_STATUS..EDGE..
T1:GRD-TEST_STATE..B..
T1:GRD-TEST_STATUS..ENTER..
T1:GRD-TEST_STATUS..MAIN..
T1:GRD-TEST_STATUS..RUN..
T1:GRD-TEST_STATUS..EDGE..
T1:GRD-TEST_STATE..F..
T1:GRD-TEST_STATUS..ENTER..
T1:GRD-TEST_STATUS..MAIN..
T1:GRD-TEST_STATUS..RUN..
T1:GRD-TEST_STATUS..DONE..
T1:GRD-TEST_STATUS..REDIRECT..
T1:GRD-TEST_STATUS..ENTER..
T1:GRD-TEST_STATUS..MAIN..
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment