From ebbe77b8490ad235914c68c90585c111cd4a276e Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 5 Aug 2022 13:59:39 +0200 Subject: [PATCH] [IMP] runbot_merge: reorg test Test seems to fail from time to time with one of the PRs getting lost. Tried to move code around trying to investigate, can't repro anymore. Possibly a race condition because the `to_pr` call was performed too early, before the webhook had run (and thus before the PR object had been created on the odoo side). By moving the `to_pr` calls to after the cron run, we really ensure the webhooks will have run. Also update `to_pr` to ensure exactly one PR was retrieved, as currently nothing is checked so we might have gotten none (yet), which should be noticed early and clearly. In theory this also guards against multiple PRs, but PRs should be unique on (repo, number). --- mergebot_test_utils/utils.py | 4 +++- runbot_merge/tests/test_basic.py | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/mergebot_test_utils/utils.py b/mergebot_test_utils/utils.py index 4c50afb3..092a1241 100644 --- a/mergebot_test_utils/utils.py +++ b/mergebot_test_utils/utils.py @@ -126,10 +126,12 @@ def pr_page(page, pr): return html.fromstring(page(f'/{pr.repo.name}/pull/{pr.number}')) def to_pr(env, pr): - return env['runbot_merge.pull_requests'].search([ + pr = env['runbot_merge.pull_requests'].search([ ('repository.name', '=', pr.repo.name), ('number', '=', pr.number), ]) + assert len(pr) == 1, f"Expected to find {pr.repo.name}#{pr.number}, got {pr}." + return pr def part_of(label, pr_id, *, separator='\n\n'): """ Adds the "part-of" pseudo-header in the footer. diff --git a/runbot_merge/tests/test_basic.py b/runbot_merge/tests/test_basic.py index f039b606..5bf13012 100644 --- a/runbot_merge/tests/test_basic.py +++ b/runbot_merge/tests/test_basic.py @@ -2733,14 +2733,16 @@ class TestBatching(object): repo.make_ref('heads/master', m) pr1 = self._pr(repo, 'PR1', [{'a': 'AAA'}, {'b': 'BBB'}], user=config['role_user']['token'], reviewer=config['role_reviewer']['token']) - p_1 = to_pr(env, pr1) pr2 = self._pr(repo, 'PR2', [{'a': 'some content', 'c': 'CCC'}, {'d': 'DDD'}], user=config['role_user']['token'], reviewer=config['role_reviewer']['token']) - p_2 = to_pr(env, pr2) env.run_crons() + p_1 = to_pr(env, pr1) + p_2 = to_pr(env, pr2) st = env['runbot_merge.stagings'].search([]) + # both prs should be part of the staging assert st.mapped('batch_ids.prs') == p_1 | p_2 + # add CI failure with repo: repo.post_status('heads/staging.master', 'failure', 'ci/runbot')