#!/usr/bin/env python # # NEPI, a framework to manage network experiments # Copyright (C) 2013 INRIA # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation; # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # Author: Alina Quereilhac from nepi.execution.scheduler import HeapScheduler, Task, TaskStatus from nepi.util.timefuncs import tnow, stabsformat import unittest from six import next class SchedulerTestCase(unittest.TestCase): def test_task_order(self): def first(): return 1 def second(): return 2 def third(): return 3 scheduler = HeapScheduler() t1 = tnow() t2 = stabsformat("2s") t3 = stabsformat("3s") tsk1 = Task(t1, first) tsk2 = Task(t2, second) tsk3 = Task(t3, third) # schedule the tasks in disorder scheduler.schedule(tsk2) scheduler.schedule(tsk3) scheduler.schedule(tsk1) # Make sure tasks are retrieved in teh correct order tsk = next(scheduler) self.assertEqual(tsk.callback(), 1) tsk = next(scheduler) self.assertEqual(tsk.callback(), 2) tsk = next(scheduler) self.assertEqual(tsk.callback(), 3) if __name__ == '__main__': unittest.main()