MCPcopy Create free account
hub / github.com/modelscope/modelscope / parallel_run_case_in_env

Function parallel_run_case_in_env

tests/run.py:290–343  ·  view source on GitHub ↗
(env_name, env, test_suite_env_map, isolated_cases,
                             result_dir, parallel)

Source from the content-addressed store, hash-verified

288
289
290def parallel_run_case_in_env(env_name, env, test_suite_env_map, isolated_cases,
291 result_dir, parallel):
292 logger.info('Running case in env: %s' % env_name)
293 # install requirements and deps # run_config['envs'][env]
294 if 'requirements' in env:
295 install_requirements(env['requirements'])
296 if 'dependencies' in env:
297 install_packages(env['dependencies'])
298 # case worker processes
299 worker_processes = [None] * parallel
300 for test_suite_file in isolated_cases: # run case in subprocess
301 if test_suite_file in test_suite_env_map and test_suite_env_map[
302 test_suite_file] == env_name:
303 cmd = [
304 'python',
305 'tests/run.py',
306 '--pattern',
307 test_suite_file,
308 '--result_dir',
309 result_dir,
310 ]
311 worker_idx = wait_for_free_worker(worker_processes)
312 worker_process = async_run_command_with_popen(cmd, worker_idx)
313 os.set_blocking(worker_process.stdout.fileno(), False)
314 worker_processes[worker_idx] = worker_process
315 else:
316 pass # case not in run list.
317
318 # run remain cases in a process.
319 remain_suite_files = []
320 for k, v in test_suite_env_map.items():
321 if k not in isolated_cases and v == env_name:
322 remain_suite_files.append(k)
323 if len(remain_suite_files) == 0:
324 wait_for_workers(worker_processes)
325 return
326 # roughly split case in parallel
327 part_count = math.ceil(len(remain_suite_files) / parallel)
328 suites_chunks = [
329 remain_suite_files[x:x + part_count]
330 for x in range(0, len(remain_suite_files), part_count)
331 ]
332 for suites_chunk in suites_chunks:
333 worker_idx = wait_for_free_worker(worker_processes)
334 cmd = [
335 'python', 'tests/run.py', '--result_dir', result_dir, '--suites'
336 ]
337 for suite in suites_chunk:
338 cmd.append(suite)
339 worker_process = async_run_command_with_popen(cmd, worker_idx)
340 os.set_blocking(worker_process.stdout.fileno(), False)
341 worker_processes[worker_idx] = worker_process
342
343 wait_for_workers(worker_processes)
344
345
346def run_case_in_env(env_name, env, test_suite_env_map, isolated_cases,

Callers

nothing calls this directly

Calls 8

install_requirementsFunction · 0.85
install_packagesFunction · 0.85
wait_for_free_workerFunction · 0.85
wait_for_workersFunction · 0.85
infoMethod · 0.80
itemsMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…