mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[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).
This commit is contained in:
parent
c85735870a
commit
ebbe77b849
@ -126,10 +126,12 @@ def pr_page(page, pr):
|
|||||||
return html.fromstring(page(f'/{pr.repo.name}/pull/{pr.number}'))
|
return html.fromstring(page(f'/{pr.repo.name}/pull/{pr.number}'))
|
||||||
|
|
||||||
def to_pr(env, pr):
|
def to_pr(env, pr):
|
||||||
return env['runbot_merge.pull_requests'].search([
|
pr = env['runbot_merge.pull_requests'].search([
|
||||||
('repository.name', '=', pr.repo.name),
|
('repository.name', '=', pr.repo.name),
|
||||||
('number', '=', pr.number),
|
('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'):
|
def part_of(label, pr_id, *, separator='\n\n'):
|
||||||
""" Adds the "part-of" pseudo-header in the footer.
|
""" Adds the "part-of" pseudo-header in the footer.
|
||||||
|
@ -2733,14 +2733,16 @@ class TestBatching(object):
|
|||||||
repo.make_ref('heads/master', m)
|
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'])
|
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'])
|
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()
|
env.run_crons()
|
||||||
|
|
||||||
|
p_1 = to_pr(env, pr1)
|
||||||
|
p_2 = to_pr(env, pr2)
|
||||||
st = env['runbot_merge.stagings'].search([])
|
st = env['runbot_merge.stagings'].search([])
|
||||||
|
|
||||||
# both prs should be part of the staging
|
# both prs should be part of the staging
|
||||||
assert st.mapped('batch_ids.prs') == p_1 | p_2
|
assert st.mapped('batch_ids.prs') == p_1 | p_2
|
||||||
|
|
||||||
# add CI failure
|
# add CI failure
|
||||||
with repo:
|
with repo:
|
||||||
repo.post_status('heads/staging.master', 'failure', 'ci/runbot')
|
repo.post_status('heads/staging.master', 'failure', 'ci/runbot')
|
||||||
|
Loading…
Reference in New Issue
Block a user