| # Copyright 2021 The Fuchsia 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 PB.recipe_modules.fuchsia.gerrit_auto_submit.tests.full import InputProperties |
| |
| DEPS = [ |
| "fuchsia/builder_state", |
| "fuchsia/gerrit_auto_submit", |
| "fuchsia/tree_status", |
| "recipe_engine/json", |
| "recipe_engine/properties", |
| ] |
| |
| PROPERTIES = InputProperties |
| |
| |
| def RunSteps(api, props): |
| api.gerrit_auto_submit( |
| opts=props.gerrit_auto_submit_options, |
| dry_run=props.dry_run, |
| ) |
| |
| |
| def GenTests(api): |
| previous_state_retryable = { |
| "fuchsia-review.googlesource.com": { |
| "27cc4558b5a3d3387dd11ee2df7a117e7e581825": { |
| "last_action_time_secs": 1336913500, |
| "attempts": 1, |
| }, |
| "27cc4558b5a3d3387dd11ee2df7a117e7e581822": { |
| "last_action_time_secs": 1336913700, |
| "attempts": 1, |
| }, |
| }, |
| } |
| yield ( |
| api.test("state_retryable") |
| + api.gerrit_auto_submit.options() |
| + api.builder_state(previous_state_retryable) |
| + api.gerrit_auto_submit.changes_query_test_data() |
| + api.gerrit_auto_submit.change_detail_messages(3) |
| + api.gerrit_auto_submit.changes_submitted_together_test_data() |
| + api.gerrit_auto_submit.mergeable_test_data() |
| + api.gerrit_auto_submit.cq_success() |
| ) |
| |
| previous_state_attempts = { |
| "fuchsia-review.googlesource.com": { |
| "27cc4558b5a3d3387dd11ee2df7a117e7e581822": { |
| "last_action_time_secs": 1336913700, |
| "attempts": 5, |
| }, |
| }, |
| } |
| yield ( |
| api.test("state_too_many_attempts") |
| + api.gerrit_auto_submit.options() |
| + api.builder_state(previous_state_attempts) |
| + api.gerrit_auto_submit.changes_query_test_data() |
| + api.gerrit_auto_submit.changes_submitted_together_test_data() |
| ) |
| |
| yield ( |
| api.test("state_too_many_attempts_comments") |
| + api.gerrit_auto_submit.options() |
| + api.gerrit_auto_submit.changes_query_test_data() |
| + api.gerrit_auto_submit.change_detail_messages(5) |
| ) |
| |
| # If the tree is closed we should wait to retry changes. |
| yield ( |
| api.test("state_tree_closed") |
| + api.gerrit_auto_submit.options( |
| api.gerrit_auto_submit.host_config(tree_name="fuchsia") |
| ) |
| + api.builder_state(previous_state_retryable) |
| + api.tree_status.get(state="OPEN") |
| + api.tree_status.get( |
| state="CLOSED", tree_name="fuchsia", step_name="get current tree status (2)" |
| ) |
| + api.gerrit_auto_submit.changes_query_test_data() |
| + api.gerrit_auto_submit.changes_submitted_together_test_data() |
| ) |
| |
| yield ( |
| api.test("no_changes") |
| + api.gerrit_auto_submit.options() |
| + api.step_data("get eligible.get changes", api.json.output([])) |
| ) |
| yield ( |
| api.test("changes_submitted_together") |
| + api.gerrit_auto_submit.options() |
| + api.gerrit_auto_submit.changes_query_test_data() |
| + api.gerrit_auto_submit.changes_submitted_together_test_data( |
| other_change_count=1 |
| ) |
| ) |
| yield ( |
| api.test("unmergeable") |
| + api.gerrit_auto_submit.options() |
| + api.gerrit_auto_submit.changes_query_test_data() |
| + api.gerrit_auto_submit.changes_submitted_together_test_data() |
| + api.gerrit_auto_submit.mergeable_test_data(mergeable=False) |
| ) |
| yield ( |
| api.test("unmergeable_nontrivial_merge_conflict") |
| + api.gerrit_auto_submit.options() |
| + api.gerrit_auto_submit.changes_query_test_data() |
| + api.gerrit_auto_submit.changes_submitted_together_test_data() |
| + api.gerrit_auto_submit.mergeable_test_data(mergeable=False) |
| + api.gerrit_auto_submit.rebase_test_data(success=False) |
| ) |
| |
| yield ( |
| api.test("dry_run_multiple") |
| + api.gerrit_auto_submit.options( |
| api.gerrit_auto_submit.host_config( |
| gerrit_host="fuchsia-review.googlesource.com" |
| ), |
| api.gerrit_auto_submit.host_config( |
| gerrit_host="test-review.googlesource.com" |
| ), |
| max_attempts=4, |
| ) |
| + api.properties(dry_run=True) |
| + api.gerrit_auto_submit.changes_query_test_data(gerrit_host="fuchsia") |
| + api.gerrit_auto_submit.changes_query_test_data(gerrit_host="test") |
| + api.gerrit_auto_submit.changes_submitted_together_test_data( |
| gerrit_host="fuchsia" |
| ) |
| + api.gerrit_auto_submit.changes_submitted_together_test_data( |
| gerrit_host="test" |
| ) |
| ) |
| |
| yield ( |
| api.test("multiple_iterations") |
| + api.gerrit_auto_submit.options( |
| api.gerrit_auto_submit.host_config( |
| gerrit_host="fuchsia-review.googlesource.com" |
| ), |
| repeat_duration_seconds=10, |
| ) |
| + api.gerrit_auto_submit.changes_query_test_data(iteration=0) |
| + api.gerrit_auto_submit.changes_submitted_together_test_data(iteration=0) |
| + api.gerrit_auto_submit.mergeable_test_data(iteration=0) |
| + api.gerrit_auto_submit.changes_query_test_data(iteration=1) |
| + api.gerrit_auto_submit.changes_submitted_together_test_data(iteration=1) |
| # There will be more iterations, but since we don't provide any mock |
| # data the queries will not return any more changes. |
| ) |