Beispiel #1
0
    def test_parallel_runner(self):
        tasks = []
        tasks.append(
            Task('KBParallelTestModule', 'do_something', 'dev', {'number': 1},
                 self.token))
        tasks.append(
            Task('KBParallelTestModule', 'do_something', 'dev', {'number': 2},
                 self.token))
        tasks.append(
            Task('KBParallelTestModule', 'do_something', 'dev', {'number': 3},
                 self.token))
        tasks.append(
            Task('KBParallelTestModule', 'do_something', 'dev', {'number': 4},
                 self.token))

        # Note: this test submits to the test endpoint NJS wrapper, so really runs things remotely
        n_local_tasks = 1
        n_njsw_tasks = 2
        plr = ParallelRunner(tasks, 2, n_local_tasks, n_njsw_tasks, 15,
                             self.callback_url, self.execution_engine_url)
        results = plr.run()

        self.assertEqual(
            results[0]['result_package']['result'][0]['new_number'], 100)
        self.assertEqual(
            results[1]['result_package']['result'][0]['new_number'], 200)
        self.assertEqual(
            results[2]['result_package']['result'][0]['new_number'], 300)
        self.assertEqual(
            results[3]['result_package']['result'][0]['new_number'], 400)
Beispiel #2
0
    def test_parallel_local_runner(self):
        tasks = []
        tasks.append(
            Task('KBParallelTestModule', 'do_something', 'dev', {'number': 1},
                 self.token))
        tasks.append(
            Task('KBParallelTestModule', 'do_something', 'dev', {'number': 2},
                 self.token))
        tasks.append(
            Task('KBParallelTestModule', 'do_something', 'dev', {'number': 3},
                 self.token))
        tasks.append(
            Task('KBParallelTestModule', 'do_something', 'dev', {'number': 4},
                 self.token))
        tasks.append(
            Task('KBParallelTestModule', 'do_something', 'dev', {'number': 5},
                 self.token))

        plr = ParallelLocalRunner(tasks, 2, 1, 15, self.callback_url)
        results = plr.run()

        self.assertEqual(
            results[0]['result_package']['result'][0]['new_number'], 100)
        self.assertEqual(
            results[1]['result_package']['result'][0]['new_number'], 200)
        self.assertEqual(
            results[2]['result_package']['result'][0]['new_number'], 300)
        self.assertEqual(
            results[3]['result_package']['result'][0]['new_number'], 400)
        self.assertEqual(
            results[4]['result_package']['result'][0]['new_number'], 500)
Beispiel #3
0
 def build_tasks(self, task_specs):
     tasks = []
     for t in task_specs:
         # @TODO - better error checking
         version = 'release'
         if 'version' in t:
             version = t['version']
         tasks.append(
             Task(t['module_name'], t['function_name'], version,
                  t['parameters'], self.token))
     return tasks
Beispiel #4
0
    def test_local_task_failure(self):
        t = Task('KBParallelTestModule', 'do_something', 'dev',
                 {'throw_error': 1}, self.token)
        t.start(self.callback_url, 'local')

        while not t.is_done():
            time.sleep(0.2)
        self.assertFalse(t.success())
        result_package = t.get_task_result_package()
        self.assertEqual(result_package['result_package']['result'], None)
        self.assertTrue(
            'doing as you wish' in result_package['result_package']['error'])
Beispiel #5
0
    def test_task(self):
        t = Task('KBParallelTestModule', 'do_something', 'dev', {'number': 5},
                 self.token)
        t.start(self.callback_url, 'local')

        while not t.is_done():
            time.sleep(0.2)

        self.assertTrue(t.success())
        result_package = t.get_task_result_package()
        self.assertEqual(
            result_package['result_package']['result'][0]['new_number'], 500)