15 """Run tests using docker images in Google Container Registry per matrix."""
17 from __future__
import print_function
22 import multiprocessing
32 python_util_dir = os.path.abspath(
33 os.path.join(os.path.dirname(__file__),
'../run_tests/python_utils'))
34 sys.path.append(python_util_dir)
38 import upload_test_results
40 _TEST_TIMEOUT_SECONDS = 60
41 _PULL_IMAGE_TIMEOUT_SECONDS = 15 * 60
42 _MAX_PARALLEL_DOWNLOADS = 6
43 _LANGUAGES = list(client_matrix.LANG_RUNTIME_MATRIX.keys())
48 for release_dict
in list(client_matrix.LANG_RELEASE_MATRIX.values())
49 for release
in list(release_dict.keys()))))
51 argp = argparse.ArgumentParser(description=
'Run interop tests.')
52 argp.add_argument(
'-j',
'--jobs', default=multiprocessing.cpu_count(), type=int)
53 argp.add_argument(
'--gcr_path',
54 default=
'gcr.io/grpc-testing',
55 help=
'Path of docker images in Google Container Registry')
56 argp.add_argument(
'--release',
58 choices=[
'all'] + _RELEASES,
59 help=
'Release tags to test. When testing all '
60 'releases defined in client_matrix.py, use "all".')
61 argp.add_argument(
'-l',
63 choices=[
'all'] + sorted(_LANGUAGES),
66 help=
'Languages to test')
70 help=
'keep the created local images after finishing the tests.')
71 argp.add_argument(
'--report_file',
73 help=
'The result file to create.')
74 argp.add_argument(
'--allow_flakes',
78 help=(
'Allow flaky tests to show as passing (re-runs failed '
79 'tests up to five times)'))
80 argp.add_argument(
'--bq_result_table',
84 help=
'Upload test results to a specified BQ table.')
87 argp.add_argument(
'--server_host',
88 default=
'74.125.206.210',
91 help=
'The gateway to backend services.')
95 """Find docker images for a language across releases and runtimes.
97 Returns dictionary of list of (<tag>, <image-full-path>) keyed by runtime.
99 if release_arg ==
'all':
105 jobset.message(
'SKIPPED',
106 'release %s for %s is not defined' %
110 releases = [release_arg]
116 image_name =
'%s/grpc_interop_%s:%s' % (image_path_prefix, runtime,
118 image_tuple = (tag, image_name)
120 if runtime
not in images:
122 images[runtime].append(image_tuple)
127 """Read test cases from a bash-like file and return a list of commands"""
129 release_info = client_matrix.LANG_RELEASE_MATRIX[lang].
get(release)
131 testcases_file = release_info.testcases_file
132 if not testcases_file:
134 testcases_file =
'%s__master' % lang
138 if lang ==
'csharp' and runtime ==
'csharpcoreclr':
139 testcases_file = testcases_file.replace(
'csharp_',
'csharpcoreclr_')
141 testcases_filepath = os.path.join(os.path.dirname(__file__),
'testcases',
144 with open(testcases_filepath)
as f:
145 for line
in f.readlines():
146 line = re.sub(
'\\#.*$',
'', line)
148 if line
and not line.startswith(
'echo'):
155 jobset.message(
'START',
'Cleanup docker image %s' % image, do_newline=
True)
156 dockerjob.remove_image(image, skip_nonexistent=
True)
159 args = argp.parse_args()
164 """Returns the list of test cases from testcase files per lang/release."""
168 for line
in testcase_lines:
169 print(
"Creating jobspec with cmdline '{}'".
format(line))
174 m = re.search(
r'--test_case=(\w+)', line)
175 testcase_name = m.group(1)
if m
else 'unknown_test'
178 if '--server_host_override=' in line:
180 r'--server_host_override=((.*).sandbox.googleapis.com)', line)
182 m = re.search(
r'--server_host=((.*).sandbox.googleapis.com)', line)
183 server = m.group(1)
if m
else 'unknown_server'
184 server_short = m.group(2)
if m
else 'unknown_server'
187 assert '--server_host=' in line
188 line = re.sub(
r'--server_host=[^ ]*',
189 r'--server_host=%s' % args.server_host, line)
193 if args.server_host != server
and not '--server_host_override=' in line:
194 line = re.sub(
r'(--server_host=[^ ]*)',
195 r'\1 --server_host_override=%s' % server, line)
197 spec = jobset.JobSpec(cmdline=line,
198 shortname=
'%s:%s:%s:%s' %
199 (suite_name, lang, server_short, testcase_name),
200 timeout_seconds=_TEST_TIMEOUT_SECONDS,
202 flake_retries=5
if args.allow_flakes
else 0)
203 job_spec_list.append(spec)
208 """Pull an image for a given language form the image registry."""
210 'time gcloud docker -- pull %s && time docker run --rm=true %s /bin/true'
213 return jobset.JobSpec(cmdline=cmdline,
214 shortname=
'pull_image_{}'.
format(image),
215 timeout_seconds=_PULL_IMAGE_TIMEOUT_SECONDS,
220 def _test_release(lang, runtime, release, image, xml_report_tree, skip_tests):
221 total_num_failures = 0
222 suite_name =
'%s__%s_%s' % (lang, runtime, release)
226 if not job_spec_list:
227 jobset.message(
'FAILED',
'No test cases were found.', do_newline=
True)
228 total_num_failures += 1
230 num_failures, resultset = jobset.run(job_spec_list,
231 newline_on_success=
True,
232 add_env={
'docker_image': image},
234 skip_jobs=skip_tests)
235 if args.bq_result_table
and resultset:
236 upload_test_results.upload_interop_results_to_bq(
237 resultset, args.bq_result_table)
239 jobset.message(
'FAILED',
'Tests were skipped', do_newline=
True)
240 total_num_failures += 1
242 total_num_failures += num_failures
244 report_utils.append_junit_xml_results(xml_report_tree, resultset,
245 'grpc_interop_matrix', suite_name,
247 return total_num_failures
251 """Find and run all test cases for a language.
253 images is a list of (<release-tag>, <image-full-path>) tuple.
256 total_num_failures = 0
258 max_pull_jobs =
min(args.jobs, _MAX_PARALLEL_DOWNLOADS)
259 max_chunk_size = max_pull_jobs
260 chunk_count = (
len(images) + max_chunk_size) // max_chunk_size
262 for chunk_index
in range(chunk_count):
263 chunk_start = chunk_index * max_chunk_size
264 chunk_size =
min(max_chunk_size,
len(images) - chunk_start)
265 chunk_end = chunk_start + chunk_size
268 for release, image
in images[chunk_start:chunk_end]:
273 pull_failures, _ = jobset.run(pull_specs,
274 newline_on_success=
True,
275 maxjobs=max_pull_jobs)
279 'Image download failed. Skipping tests for language "%s"' %
283 for release, image
in images[chunk_start:chunk_end]:
284 total_num_failures +=
_test_release(lang, runtime, release, image,
285 xml_report_tree, skip_tests)
287 for _, image
in images[chunk_start:chunk_end]:
289 if not total_num_failures:
290 jobset.message(
'SUCCESS',
291 'All {} tests passed'.
format(lang),
294 jobset.message(
'FAILED',
295 'Some {} tests failed'.
format(lang),
298 return total_num_failures
301 languages = args.language
if args.language != [
'all']
else _LANGUAGES
302 total_num_failures = 0
303 _xml_report_tree = report_utils.new_junit_xml_tree()
304 for lang
in languages:
306 for runtime
in sorted(docker_images.keys()):
308 docker_images[runtime],
311 report_utils.create_xml_report_file(_xml_report_tree, args.report_file)
313 if total_num_failures: