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>
21 from nepi.util.parallel import ParallelRun
26 class ParallelRunTestCase(unittest.TestCase):
27 def test_run_simple(self):
28 runner = ParallelRun(maxthreads = 4)
37 runner.put(inc, count)
41 self.assertEqual(count[0], 10)
43 def test_run_interrupt(self):
49 startt = datetime.datetime.now()
51 runner = ParallelRun(maxthreads = 4)
60 endt = datetime.datetime.now()
61 time_elapsed = (endt - startt).seconds
62 self.assertTrue( time_elapsed < 500)
64 def test_run_error(self):
73 runner = ParallelRun(maxthreads = 4)
77 runner.put(inc, count)
83 self.assertEqual(count[0], 4)
85 self.assertRaises(RuntimeError, runner.sync)
87 if __name__ == '__main__':