def test_touching_requests(): print('Test touching requests: Two agents', now) sch_man = ScheduleManager(60, now=now) ag1 = ('Agent1', 'Task1', ([ 'campus/building/rtu1', parse('2013-11-27 12:00:00'), parse('2013-11-27 12:30:00') ], ), PRIORITY_HIGH, now) ag2 = ('Agent2', 'Task2', ([ 'campus/building/rtu1', parse('2013-11-27 12:30:00'), parse('2013-11-27 13:00:00') ], ), PRIORITY_HIGH, now) result1, event_time1 = verify_add_task(sch_man, *ag1) success1, data1, info_string1 = result1 assert all((success1, not data1, not info_string1, event_time1 == parse('2013-11-27 12:00:00'))) result2, event_time2 = verify_add_task(sch_man, *ag2) success2, data2, info_string2 = result2 assert all((success2, not data2, not info_string2, event_time2 == parse('2013-11-27 12:00:00'))) state = sch_man.get_schedule_state(now + timedelta(minutes=30)) assert state == { 'campus/building/rtu1': DeviceState('Agent1', 'Task1', 1800.0) } state = sch_man.get_schedule_state(now + timedelta(minutes=60)) assert state == { 'campus/building/rtu1': DeviceState('Agent2', 'Task2', 1800.0) }
def test_conflict_override_success_running_agent(): print('Test conflicting requests: Agent2 overrides running Agent1', now) sch_man = ScheduleManager(60, now=now) ag1 = ('Agent1', 'Task1', ([ 'campus/building/rtu1', parse('2013-11-27 12:00:00'), parse('2013-11-27 12:35:00') ], ), PRIORITY_LOW_PREEMPT, now) now2 = now + timedelta(minutes=45) ag2 = ('Agent2', 'Task2', ([ 'campus/building/rtu1', parse('2013-11-27 12:05:00'), parse('2013-11-27 13:00:00') ], ), PRIORITY_HIGH, now2) result1, event_time1 = verify_add_task(sch_man, *ag1) success1, data1, info_string1 = result1 assert all((success1, not data1, not info_string1, event_time1 == parse('2013-11-27 12:00:00'))) result2, event_time2 = verify_add_task(sch_man, *ag2) success2, data2, info_string2 = result2 assert success2 assert data2 == {('Agent1', 'Task1')} assert info_string2 == '' assert event_time2 == parse('2013-11-27 12:16:00') state = sch_man.get_schedule_state(now2 + timedelta(seconds=30)) assert state == { 'campus/building/rtu1': DeviceState('Agent1', 'Task1', 30.0) } state = sch_man.get_schedule_state(now2 + timedelta(seconds=60)) assert state == { 'campus/building/rtu1': DeviceState('Agent2', 'Task2', 2640.0) }
def test_two_devices(): print('Basic Test: Two devices', now) sch_man = ScheduleManager(60, now=now) ag = ('Agent1', 'Task1', ([ 'campus/building/rtu1', parse('2013-11-27 12:00:00'), parse('2013-11-27 13:00:00') ], [ 'campus/building/rtu2', parse('2013-11-27 12:00:00'), parse('2013-11-27 13:00:00') ]), PRIORITY_HIGH, now) result1, event_time1 = verify_add_task(sch_man, *ag) success, data, info_string = result1 assert all((success, not data, not info_string, event_time1 == parse('2013-11-27 12:00:00'))) state = sch_man.get_schedule_state(now + timedelta(minutes=30)) assert state == { 'campus/building/rtu1': DeviceState('Agent1', 'Task1', 3600.0), 'campus/building/rtu2': DeviceState('Agent1', 'Task1', 3600.0) } state = sch_man.get_schedule_state(now + timedelta(minutes=60)) assert state == { 'campus/building/rtu1': DeviceState('Agent1', 'Task1', 1800.0), 'campus/building/rtu2': DeviceState('Agent1', 'Task1', 1800.0) }
now = datetime(year=2013, month=11, day=27, hour=11, minute=30) print_test_header('Basic Test', now) sch_man = ScheduleManager(timedelta(seconds=60), now=now) ag = ('Agent1', (['/campus/building/rtu1','2013-11-27 12:00:00','2013-11-27 13:00:00'],), PRIORITY_HIGH, now) result1 = test_add_task(sch_man, *ag) event_time1, preempted1, state1 = result1.data assert all((result1.success, not preempted1, not state1, event_time1 == parse('2013-11-27 12:00:00'))) state = sch_man.get_schedule_state(now + timedelta(minutes=30)) assert state == {'/campus/building/rtu1': DeviceState('Agent1', result1.task_id, 3600.0)} state = sch_man.get_schedule_state(now + timedelta(minutes=60)) assert state == {'/campus/building/rtu1': DeviceState('Agent1', result1.task_id, 1800.0)} print_test_header('Basic Test: Two devices', now) sch_man = ScheduleManager(timedelta(seconds=60), now=now) ag = ('Agent1', (['/campus/building/rtu1','2013-11-27 12:00:00','2013-11-27 13:00:00'], ['/campus/building/rtu2','2013-11-27 12:00:00','2013-11-27 13:00:00']), PRIORITY_HIGH, now) result1 = test_add_task(sch_man, *ag) event_time1, preempted1, state1 = result1.data assert all((result1.success, not preempted1, not state1, event_time1 == parse('2013-11-27 12:00:00')))
print_test_header('Basic Test', now) sch_man = ScheduleManager(60, now=now) ag = ('Agent1', 'Task1', ([ 'campus/building/rtu1', '2013-11-27 12:00:00', '2013-11-27 13:00:00' ], ), PRIORITY_HIGH, now) result1, event_time1 = test_add_task(sch_man, *ag) success, data, info_string = result1 # success1, data1, info_string1 = result1 assert all((success, not data, not info_string, event_time1 == parse('2013-11-27 12:00:00'))) # dict: {'campus/building/rtu1': DeviceState(agent_id='Agent1', task_id='Task1', time_remaining=3600.0)} state = sch_man.get_schedule_state(now + timedelta(minutes=30)) assert state == { 'campus/building/rtu1': DeviceState('Agent1', 'Task1', 3600.0) } state = sch_man.get_schedule_state(now + timedelta(minutes=60)) assert state == { 'campus/building/rtu1': DeviceState('Agent1', 'Task1', 1800.0) } print_test_header('Basic Test: Two devices', now) sch_man = ScheduleManager(60, now=now) ag = ('Agent1', 'Task1', ([ 'campus/building/rtu1', '2013-11-27 12:00:00', '2013-11-27 13:00:00' ], ['campus/building/rtu2', '2013-11-27 12:00:00', '2013-11-27 13:00:00']), PRIORITY_HIGH, now) result1, event_time1 = test_add_task(sch_man, *ag) success, data, info_string = result1 assert all((success, not data, not info_string,