From 3247732a117377547bcfcb32119d1e66b42b46f8 Mon Sep 17 00:00:00 2001 From: Ankith Udupa Date: Mon, 2 Oct 2023 23:36:00 -0400 Subject: [PATCH] fixed external data test, added comment --- test/util/state_lib/test_external_data.py | 31 ++++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/test/util/state_lib/test_external_data.py b/test/util/state_lib/test_external_data.py index 7be90ccef..aea64d1af 100644 --- a/test/util/state_lib/test_external_data.py +++ b/test/util/state_lib/test_external_data.py @@ -1,10 +1,16 @@ -from ..lib.state_machine import StateMachine -from ..lib.state import State, ExitState +from util.state_lib.state_machine import StateMachine +from util.state_lib.state import State, ExitState import random from threading import Thread, Lock import time +''' +Test multi-threaded program that has an external thread that feeds a resource that the +Context object queries. Not a unit-test but run manually to ensure relatively predicatble +behavior +''' + class Context: def __init__(self): self.stateCapture = ExternalStateCapture() @@ -61,13 +67,14 @@ def on_loop(self, context): def on_exit(self, context): print("Stopped") -sm = StateMachine(WaitingState()) -sm.add_transition(WaitingState(), RunningState()) -sm.add_transition(RunningState(), WaitingState()) -sm.add_transition(RunningState(), RunningState()) -sm.add_transition(WaitingState(), WaitingState()) -context = Context() -sm.set_context(context) -thread = Thread(target=context.stateCapture.random_loop) -thread.start() -sm.run() \ No newline at end of file +if __name__ == "__main__": + sm = StateMachine(WaitingState()) + sm.add_transition(WaitingState(), RunningState()) + sm.add_transition(RunningState(), WaitingState()) + sm.add_transition(RunningState(), RunningState()) + sm.add_transition(WaitingState(), WaitingState()) + context = Context() + sm.set_context(context) + thread = Thread(target=context.stateCapture.random_loop) + thread.start() + sm.run() \ No newline at end of file