def test_30_minutes_and_0_hour_tick_after_1800_seconds(self): seconds_clock = SynchronizingClock(max_ticks=3600) minutes_clock = SynchronizingClock() hours_clock = SynchronizingClock() minutes_stopwatch_actor = StopwatchActor( logical_name='seconds_to_minutes', clock=seconds_clock, parent_clock=minutes_clock, granularity=60) hours_stopwatch_actor = StopwatchActor(logical_name='minutes_to_hours', clock=minutes_clock, parent_clock=hours_clock, granularity=60) minutes_stopwatch_actor.start() hours_stopwatch_actor.start() for second in range(0, 1800): seconds_clock.tick() seconds_clock.shutdown() # Ensure final ticks are released to parent clock before testing state. minutes_stopwatch_actor.initiate_shutdown() hours_stopwatch_actor.initiate_shutdown() minutes_stopwatch_actor.wait_for_shutdown() hours_stopwatch_actor.wait_for_shutdown() self.assertEqual(1800, seconds_clock.current_tick) self.assertEqual(30, minutes_clock.current_tick) self.assertEqual(0, hours_clock.current_tick)
def test_one_minute_tick_after_60_seconds(self): seconds_clock = SynchronizingClock(max_ticks=60) minutes_clock = SynchronizingClock() seconds_clock.add_tick_listener( InterClockSynchronization(minutes_clock, granularity=60)) while minutes_clock.current_tick < 1: seconds_clock.tick() self.assertEqual(60, seconds_clock.current_tick) self.assertEqual(1, minutes_clock.current_tick)
def setUp(self): self.is_64bits = sys.maxsize > 2**32 self.clock = SynchronizingClock(max_ticks=1000) self.development_team = Cast(self.clock) self.development_team.add_member('alice') self.product_backlog = Queue() self.product_backlog.put(UserStory(0, 3, 1)) self.product_backlog.put(UserStory(1, 5, 2)) self.product_backlog.put(UserStory(2, 7, 3)) self.random = SystemRandom(1) self.plan = TestDrivenDevelopmentPlan(self.product_backlog, self.random) self.centralised_vcs_server = CentralisedVCSServer(SoftwareSystem()) self.software_project = SoftwareProject(self.clock, self.development_team, self.plan, self.centralised_vcs_server, self.random)
def test_ticks_until_stopped(self): self.clock = SynchronizingClock() self.clock.tick() self.clock.tick() self.clock.issue_ticks = False self.clock.tick() self.assertEqual(self.clock.current_tick, 2)
def __init__(self, specification, plan_spec, number_of_developers, number_of_clock_ticks, number_of_projects, number_of_traces, max_trace_length, random): self.number_of_traces = number_of_traces self.max_trace_length = max_trace_length self.software_projects = list() for seed in range(0, number_of_projects): clock = SynchronizingClock(number_of_clock_ticks) development_team = Cast() for logical_name in range(0, number_of_developers): development_team.add_member(TaskQueueActor( logical_name, clock)) centralised_vcs_server = CentralisedVCSServer(SoftwareSystem()) plan = plan_spec(specification, centralised_vcs_server, random) software_project = SoftwareProject(clock, development_team, plan, random) self.software_projects.append(software_project) self.simulation_duration = -1
def test_for_handling_imprecision(self): seconds_clock = SynchronizingClock(max_ticks=3600) minutes_clock = SynchronizingClock() hours_clock = SynchronizingClock() seconds_clock.add_tick_listener( InterClockSynchronization(minutes_clock, granularity=60)) minutes_clock.add_tick_listener( InterClockSynchronization( hours_clock, granularity=60, precision=lambda granularity: granularity - 5)) while hours_clock.current_tick < 1: seconds_clock.tick() self.assertEqual(3300, seconds_clock.current_tick) self.assertEqual(55, minutes_clock.current_tick) self.assertEqual(1, hours_clock.current_tick)
def test_one_minute_tick_after_60_seconds(self): seconds_clock = SynchronizingClock(max_ticks=60) minutes_clock = SynchronizingClock() stopwatch_actor = StopwatchActor(logical_name='seconds_to_minutes', clock=seconds_clock, parent_clock=minutes_clock, granularity=60) stopwatch_actor.start() for second in range(0, 60): seconds_clock.tick() seconds_clock.tick() # Ensure final tick is released to parent clock before testing state. stopwatch_actor.shutdown() self.assertEqual(60, seconds_clock.current_tick) self.assertEqual(1, minutes_clock.current_tick)
def test_synchronization(self): self.clock = SynchronizingClock(max_ticks=2) self.tick_listener = Mock() self.clock.add_tick_listener(self.tick_listener) self.clock.tick() self.tick_listener.wait_for_tick.assert_called_once_with() self.tick_listener.notify_new_tick.assert_called_once_with()
def test_non_blocking_for_actors(self): seconds_clock = SynchronizingClock(max_ticks=3600) minutes_clock = SynchronizingClock() hours_clock = SynchronizingClock() seconds_clock.add_tick_listener(InterClockSynchronization(minutes_clock, granularity=60)) minutes_clock.add_tick_listener(InterClockSynchronization(hours_clock, granularity=60)) actor = TaskQueueActor(0, minutes_clock) example_workflow = ExampleWorkflow() actor.allocate_task(example_workflow.task_a, example_workflow) actor.initiate_shutdown() actor.start() while hours_clock.current_tick < 1: seconds_clock.tick() self.assertEqual(actor.last_task.finish_tick, 2) self.assertEqual(3600, seconds_clock.current_tick) self.assertEqual(60, minutes_clock.current_tick) self.assertEqual(1, hours_clock.current_tick)
def setUp(self): self.is_64bits = sys.maxsize > 2 ** 32 self.clock = SynchronizingClock(max_ticks=100000) self.development_team = Cast(self.clock) self.development_team.add_member('manager') self.development_team.add_member('alice') self.specification = [UserStory(0, 3, 1), UserStory(1, 5, 2), UserStory(2, 7, 3)] self.random = SystemRandom(1) self.plan = WaterfallDevelopmentPlan(self.specification, self.random) self.centralised_vcs_server = CentralisedVCSServer(SoftwareSystem()) self.project = SoftwareProject( self.clock, self.development_team, self.plan, self.centralised_vcs_server, self.random)
def setUp(self): self.clock = SynchronizingClock(max_ticks=1) self.cast = Cast()
def setUp(self): self.clock = SynchronizingClock(max_ticks=4) self.actor = TaskQueueActor(0, self.clock) self.idling = Idling() self.example_workflow = ExampleWorkflow(self.idling)
import grpc import do_work_pb2_grpc import do_work from concurrent import futures from theatre_ag import Cast, Episode, SynchronizingClock, TaskQueueActor, default_cost from wait_for_tick_workflow import WaitForTickWorkflow from improv import Improv clock = SynchronizingClock(max_ticks=10) cast = Cast() tick_listening_actor = TaskQueueActor('tick_listener',clock) cast.add_member(tick_listening_actor) improv = Improv(clock, cast) wait_for_tick_workflow = WaitForTickWorkflow(improv) tick_listening_actor.allocate_task(wait_for_tick_workflow.the_main_entry_point) improv.perform() service = do_work.Service(improv) grpc_server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) do_work_pb2_grpc.add_SimulateServiceServicer_to_server(service, grpc_server) grpc_server.add_insecure_port('[::]:9000') grpc_server.start() grpc_server.wait_for_termination()
def setUp(self): self.clock = SynchronizingClock(max_ticks=2)