From 4d2824af525da24fb5fc37e10c8e49dae39f83ed Mon Sep 17 00:00:00 2001 From: Andrii Shyshkalov Date: Fri, 6 Mar 2020 18:43:28 +0000 Subject: [PATCH] Improve tests for api.tryserver. R=yiwzhang Bug: 1056725 Change-Id: Id09e1a243e7071b5dc5715d156063e4b08230e84 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2080764 Reviewed-by: Yiwei Zhang Reviewed-by: Edward Lesmes Commit-Queue: Andrii Shyshkalov Auto-Submit: Andrii Shyshkalov --- recipes/README.recipes.md | 14 +++++--- .../tests/gerrit_change_fetch_ref.py | 34 ------------------- .../tests/gerrit_change_fetch_ref_timeout.py | 29 ++++++++++++++++ .../tests/gerrit_change_target_ref.py | 32 +++++++++++++++++ 4 files changed, 71 insertions(+), 38 deletions(-) delete mode 100644 recipes/recipe_modules/tryserver/tests/gerrit_change_fetch_ref.py create mode 100644 recipes/recipe_modules/tryserver/tests/gerrit_change_fetch_ref_timeout.py create mode 100644 recipes/recipe_modules/tryserver/tests/gerrit_change_target_ref.py diff --git a/recipes/README.recipes.md b/recipes/README.recipes.md index 75b648667..77d402df6 100644 --- a/recipes/README.recipes.md +++ b/recipes/README.recipes.md @@ -41,7 +41,8 @@ * [presubmit:tests/execute](#recipes-presubmit_tests_execute) * [presubmit:tests/prepare](#recipes-presubmit_tests_prepare) * [tryserver:examples/full](#recipes-tryserver_examples_full) - * [tryserver:tests/gerrit_change_fetch_ref](#recipes-tryserver_tests_gerrit_change_fetch_ref) + * [tryserver:tests/gerrit_change_fetch_ref_timeout](#recipes-tryserver_tests_gerrit_change_fetch_ref_timeout) + * [tryserver:tests/gerrit_change_target_ref](#recipes-tryserver_tests_gerrit_change_target_ref) * [windows_sdk:examples/full](#recipes-windows_sdk_examples_full) ## Recipe Modules @@ -1046,11 +1047,16 @@ Move things around in a loop! [DEPS](/recipes/recipe_modules/tryserver/examples/full.py#5): [gerrit](#recipe_modules-gerrit), [tryserver](#recipe_modules-tryserver), [recipe\_engine/buildbucket][recipe_engine/recipe_modules/buildbucket], [recipe\_engine/json][recipe_engine/recipe_modules/json], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/platform][recipe_engine/recipe_modules/platform], [recipe\_engine/properties][recipe_engine/recipe_modules/properties], [recipe\_engine/python][recipe_engine/recipe_modules/python], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/step][recipe_engine/recipe_modules/step] — **def [RunSteps](/recipes/recipe_modules/tryserver/examples/full.py#19)(api):** -### *recipes* / [tryserver:tests/gerrit\_change\_fetch\_ref](/recipes/recipe_modules/tryserver/tests/gerrit_change_fetch_ref.py) +### *recipes* / [tryserver:tests/gerrit\_change\_fetch\_ref\_timeout](/recipes/recipe_modules/tryserver/tests/gerrit_change_fetch_ref_timeout.py) -[DEPS](/recipes/recipe_modules/tryserver/tests/gerrit_change_fetch_ref.py#7): [gerrit](#recipe_modules-gerrit), [tryserver](#recipe_modules-tryserver), [recipe\_engine/buildbucket][recipe_engine/recipe_modules/buildbucket], [recipe\_engine/properties][recipe_engine/recipe_modules/properties] +[DEPS](/recipes/recipe_modules/tryserver/tests/gerrit_change_fetch_ref_timeout.py#7): [gerrit](#recipe_modules-gerrit), [tryserver](#recipe_modules-tryserver), [recipe\_engine/buildbucket][recipe_engine/recipe_modules/buildbucket], [recipe\_engine/properties][recipe_engine/recipe_modules/properties] -— **def [RunSteps](/recipes/recipe_modules/tryserver/tests/gerrit_change_fetch_ref.py#15)(api):** +— **def [RunSteps](/recipes/recipe_modules/tryserver/tests/gerrit_change_fetch_ref_timeout.py#15)(api):** +### *recipes* / [tryserver:tests/gerrit\_change\_target\_ref](/recipes/recipe_modules/tryserver/tests/gerrit_change_target_ref.py) + +[DEPS](/recipes/recipe_modules/tryserver/tests/gerrit_change_target_ref.py#7): [gerrit](#recipe_modules-gerrit), [tryserver](#recipe_modules-tryserver), [recipe\_engine/buildbucket][recipe_engine/recipe_modules/buildbucket], [recipe\_engine/properties][recipe_engine/recipe_modules/properties], [recipe\_engine/step][recipe_engine/recipe_modules/step] + +— **def [RunSteps](/recipes/recipe_modules/tryserver/tests/gerrit_change_target_ref.py#16)(api):** ### *recipes* / [windows\_sdk:examples/full](/recipes/recipe_modules/windows_sdk/examples/full.py) [DEPS](/recipes/recipe_modules/windows_sdk/examples/full.py#5): [windows\_sdk](#recipe_modules-windows_sdk), [recipe\_engine/platform][recipe_engine/recipe_modules/platform], [recipe\_engine/properties][recipe_engine/recipe_modules/properties], [recipe\_engine/step][recipe_engine/recipe_modules/step] diff --git a/recipes/recipe_modules/tryserver/tests/gerrit_change_fetch_ref.py b/recipes/recipe_modules/tryserver/tests/gerrit_change_fetch_ref.py deleted file mode 100644 index 56e5c85a7..000000000 --- a/recipes/recipe_modules/tryserver/tests/gerrit_change_fetch_ref.py +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright 2019 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -from recipe_engine import post_process - -DEPS = [ - 'gerrit', - 'recipe_engine/buildbucket', - 'recipe_engine/properties', - 'tryserver', -] - - -def RunSteps(api): - api.tryserver.gerrit_change_fetch_ref - - -def GenTests(api): - yield ( - api.test('timeout') + - api.buildbucket.try_build( - 'chromium', - 'linux', - git_repo='https://chromium.googlesource.com/chromium/src', - change_number=91827, - patch_set=1) + - api.properties(target_ref='refs/heads/master') + - api.tryserver.gerrit_change_target_ref('refs/heads/master') + - api.override_step_data('gerrit fetch current CL info', - times_out_after=1200) + - api.post_process(post_process.StatusException) + - api.post_process(post_process.DropExpectation) - ) diff --git a/recipes/recipe_modules/tryserver/tests/gerrit_change_fetch_ref_timeout.py b/recipes/recipe_modules/tryserver/tests/gerrit_change_fetch_ref_timeout.py new file mode 100644 index 000000000..5f6210725 --- /dev/null +++ b/recipes/recipe_modules/tryserver/tests/gerrit_change_fetch_ref_timeout.py @@ -0,0 +1,29 @@ +# Copyright 2019 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +from recipe_engine import post_process + +DEPS = [ + 'gerrit', + 'recipe_engine/buildbucket', + 'recipe_engine/properties', + 'tryserver', +] + + +def RunSteps(api): + api.tryserver.gerrit_change_fetch_ref + + +def GenTests(api): + yield (api.test('timeout') + api.buildbucket.try_build( + 'chromium', + 'linux', + git_repo='https://chromium.googlesource.com/chromium/src', + change_number=91827, + patch_set=1) + api.tryserver.gerrit_change_target_ref('refs/heads/master') + + api.override_step_data( + 'gerrit fetch current CL info', times_out_after=1200) + + api.post_process(post_process.StatusException) + api.post_process( + post_process.DropExpectation)) diff --git a/recipes/recipe_modules/tryserver/tests/gerrit_change_target_ref.py b/recipes/recipe_modules/tryserver/tests/gerrit_change_target_ref.py new file mode 100644 index 000000000..4878e200e --- /dev/null +++ b/recipes/recipe_modules/tryserver/tests/gerrit_change_target_ref.py @@ -0,0 +1,32 @@ +# Copyright 2019 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +from recipe_engine import post_process + +DEPS = [ + 'gerrit', + 'recipe_engine/buildbucket', + 'recipe_engine/properties', + 'recipe_engine/step', + 'tryserver', +] + + +def RunSteps(api): + api.step(name=api.tryserver.gerrit_change_target_ref or 'None!', cmd=None) + + +def GenTests(api): + yield api.test( + 'works', + api.buildbucket.try_build( + 'chromium', + 'linux', + git_repo='https://chromium.googlesource.com/chromium/src', + change_number=91827, + patch_set=1), + api.tryserver.gerrit_change_target_ref('refs/branch-heads/custom'), + api.post_check( + lambda check, steps: check('refs/branch-heads/custom' in steps)), + api.post_process(post_process.DropExpectation))