Skip to content

Commit

Permalink
fixed external data test, added comment
Browse files Browse the repository at this point in the history
  • Loading branch information
ankithu committed Oct 3, 2023
1 parent 640f6a6 commit 3247732
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions test/util/state_lib/test_external_data.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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()
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()

0 comments on commit 3247732

Please sign in to comment.