66191e26cd960ef5ecef4ea83931b88b9037d1ab
[nepi.git] / test / execution / scheduler.py
1 #!/usr/bin/env python
2 #
3 #    NEPI, a framework to manage network experiments
4 #    Copyright (C) 2013 INRIA
5 #
6 #    This program is free software: you can redistribute it and/or modify
7 #    it under the terms of the GNU General Public License as published by
8 #    the Free Software Foundation, either version 3 of the License, or
9 #    (at your option) any later version.
10 #
11 #    This program is distributed in the hope that it will be useful,
12 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #    GNU General Public License for more details.
15 #
16 #    You should have received a copy of the GNU General Public License
17 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20
21 from nepi.execution.scheduler import HeapScheduler, Task, TaskStatus
22 from nepi.util.timefuncs import tnow, stabsformat
23
24 import unittest
25
26 class SchedulerTestCase(unittest.TestCase):
27     def test_task_order(self):
28         def first():
29             return 1
30
31         def second():
32             return 2
33
34         def third():
35             return 3
36
37         scheduler = HeapScheduler()
38         
39         t1 = tnow()
40         t2 = stabsformat("2s")
41         t3 = stabsformat("3s")
42     
43         tsk1 = Task(t1, first)
44         tsk2 = Task(t2, second)
45         tsk3 = Task(t3, third)
46
47         # schedule the tasks in disorder
48         scheduler.schedule(tsk2)
49         scheduler.schedule(tsk3)
50         scheduler.schedule(tsk1)
51
52         # Make sure tasks are retrieved in teh correct order
53         tsk = scheduler.next()
54         self.assertEquals(tsk.callback(), 1)
55         
56         tsk = scheduler.next()
57         self.assertEquals(tsk.callback(), 2)
58         
59         tsk = scheduler.next()
60         self.assertEquals(tsk.callback(), 3)
61
62
63 if __name__ == '__main__':
64     unittest.main()
65