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 as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
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.
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/>.
19 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
22 from nepi.execution.ec import ExperimentController, ECState
23 from nepi.execution.scheduler import TaskStatus
29 class ExecuteControllersTestCase(unittest.TestCase):
30 def test_schedule_print(self):
34 ec = ExperimentController()
36 tid = ec.schedule("0s", myfunc, track=True)
39 task = ec.get_task(tid)
40 if task.status != TaskStatus.NEW:
45 self.assertEquals('hola!', task.result)
49 def test_schedule_date(self):
51 return datetime.datetime.now()
53 ec = ExperimentController()
55 schedule_time = datetime.datetime.now()
57 tid = ec.schedule("4s", get_time, track=True)
60 task = ec.get_task(tid)
61 if task.status != TaskStatus.NEW:
66 execution_time = task.result
67 delta = execution_time - schedule_time
68 self.assertTrue(delta > datetime.timedelta(seconds=4))
69 self.assertTrue(delta < datetime.timedelta(seconds=5))
73 def test_schedule_exception(self):
75 raise RuntimeError, "NOT A REAL ERROR. JUST TESTING!"
77 ec = ExperimentController()
78 ec.schedule("2s", raise_error)
80 while ec.ecstate not in [ECState.FAILED, ECState.TERMINATED]:
83 self.assertEquals(ec.ecstate, ECState.FAILED)
87 if __name__ == '__main__':