def test_do_math_async(self): job1 = remotable_module.remote_async_do_math('localhost:5001', 15, 20) job2 = remotable_module.remote_async_do_math('localhost:5002', 7, 5) job3 = remotable_module.remote_async_do_math('localhost:5003', 2, 3) job4 = remotable_module.remote_async_do_math('localhost:5004', 133, 289) job1.start() job2.start() job3.start() job4.start() while not job1.finished() and not job2.finished() and not job3.finished() and not job4.finished(): time.sleep(.25) ret1 = job1.join() ret2 = job2.join() ret3 = job3.join() ret4 = job4.join() self.assertEqual(ret1, 15 * 20) self.assertEqual(ret2, 7 * 5) self.assertEqual(ret3, 2 * 3) self.assertEqual(ret4, 133 * 289)
def test_do_math_async(self): job1 = remotable_module.remote_async_do_math('localhost:5001', 15, 20) job2 = remotable_module.remote_async_do_math('localhost:5002', 7, 5) job3 = remotable_module.remote_async_do_math('localhost:5003', 2, 3) job4 = remotable_module.remote_async_do_math('localhost:5004', 133, 289) job1.start() job2.start() job3.start() job4.start() while not job1.finished() and not job2.finished( ) and not job3.finished() and not job4.finished(): time.sleep(.25) ret1 = job1.join() ret2 = job2.join() ret3 = job3.join() ret4 = job4.join() self.assertEqual(ret1, 15 * 20) self.assertEqual(ret2, 7 * 5) self.assertEqual(ret3, 2 * 3) self.assertEqual(ret4, 133 * 289)
def test_logging__remote_module_async_func(self): job = remotable_module.remote_async_do_math('localhost:5001', 2, 3) job.start() ret = job.join() self.assertEqual(ret, 6) with open(self.logger_path) as fin: all_lines = fin.readlines() self.assertEqual(all_lines[0].strip(), 'Creating job "{0}" on target "{1}" with args: {2} and kwargs: {3}'.format( 'do_math', 'localhost:5001', (2, 3), {})) self.assertIsNotNone(r'Starting "do_math\(.*\)" on "localhost:5001"', all_lines[1].strip()) self.assertEqual(all_lines[2].strip(), 'Joining "{0}" on "{1}"'.format('do_math', 'localhost:5001')) self.assertEqual(all_lines[3].strip(), '"{0}" on target "{1}" returned {2}'.format( 'do_math', 'localhost:5001', 6))