3 # NEPI, a framework to manage network experiments
4 # Copyright (C) 2013 INRIA
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 2 as
8 # published by the Free Software Foundation;
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 from nepi.execution.scheduler import HeapScheduler, Task, TaskStatus
21 from nepi.util.timefuncs import tnow, stabsformat
25 class SchedulerTestCase(unittest.TestCase):
26 def test_task_order(self):
36 scheduler = HeapScheduler()
39 t2 = stabsformat("2s")
40 t3 = stabsformat("3s")
42 tsk1 = Task(t1, first)
43 tsk2 = Task(t2, second)
44 tsk3 = Task(t3, third)
46 # schedule the tasks in disorder
47 scheduler.schedule(tsk2)
48 scheduler.schedule(tsk3)
49 scheduler.schedule(tsk1)
51 # Make sure tasks are retrieved in teh correct order
52 tsk = scheduler.next()
53 self.assertEqual(tsk.callback(), 1)
55 tsk = scheduler.next()
56 self.assertEqual(tsk.callback(), 2)
58 tsk = scheduler.next()
59 self.assertEqual(tsk.callback(), 3)
62 if __name__ == '__main__':