From 7eeee997355abcc41645f99c11d07238782b814d Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 4 Jul 2022 15:12:50 +0200 Subject: [PATCH] [FIX] runbot_merge: avoid race condition in tests Because the searching of the PR occurs *right* after the PR was created on the server, despite the additional operations (status, approval) it's apparently possible for the lookup of the new PR to occur about the same time the PR is being created, kinda, maybe? On DS it triggers very reliably for every PR but the first. By moving the retrieval after the repo timeout & we've run the crons, we near guarantee the PRs are visible (it's possible for things to fail on grounds of github reliability, but then they'd have failed *even more* before). --- runbot_merge/tests/test_multirepo.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/runbot_merge/tests/test_multirepo.py b/runbot_merge/tests/test_multirepo.py index 461ed0cb..ddb7a404 100644 --- a/runbot_merge/tests/test_multirepo.py +++ b/runbot_merge/tests/test_multirepo.py @@ -684,12 +684,16 @@ class TestMultiBatches: make_branch(repo_b, 'master', 'initial', {'b': 'b0'}) prs = [( - a and to_pr(env, make_pr(repo_a, 'batch{}'.format(i), [{'a{}'.format(i): 'a{}'.format(i)}], user=config['role_user']['token'], reviewer=config['role_reviewer']['token'],)), - b and to_pr(env, make_pr(repo_b, 'batch{}'.format(i), [{'b{}'.format(i): 'b{}'.format(i)}], user=config['role_user']['token'], reviewer=config['role_reviewer']['token'],)) + a and make_pr(repo_a, 'batch{}'.format(i), [{'a{}'.format(i): 'a{}'.format(i)}], user=config['role_user']['token'], reviewer=config['role_reviewer']['token']), + b and make_pr(repo_b, 'batch{}'.format(i), [{'b{}'.format(i): 'b{}'.format(i)}], user=config['role_user']['token'], reviewer=config['role_reviewer']['token']), ) for i, (a, b) in enumerate([(1, 1), (0, 1), (1, 1), (1, 1), (1, 0)]) ] env.run_crons() + prs = [ + (a and to_pr(env, a), b and to_pr(env, b)) + for (a, b) in prs + ] st = env['runbot_merge.stagings'].search([]) assert st @@ -713,12 +717,16 @@ class TestMultiBatches: make_branch(repo_b, 'master', 'initial', {'b': 'b0'}) prs = [( - a and to_pr(env, make_pr(repo_a, 'batch{}'.format(i), [{'a{}'.format(i): 'a{}'.format(i)}], user=config['role_user']['token'], reviewer=config['role_reviewer']['token'],)), - b and to_pr(env, make_pr(repo_b, 'batch{}'.format(i), [{'b{}'.format(i): 'b{}'.format(i)}], user=config['role_user']['token'], reviewer=config['role_reviewer']['token'],)) + a and make_pr(repo_a, 'batch{}'.format(i), [{'a{}'.format(i): 'a{}'.format(i)}], user=config['role_user']['token'], reviewer=config['role_reviewer']['token']), + b and make_pr(repo_b, 'batch{}'.format(i), [{'b{}'.format(i): 'b{}'.format(i)}], user=config['role_user']['token'], reviewer=config['role_reviewer']['token']), ) for i, (a, b) in enumerate([(1, 1), (0, 1), (1, 1), (1, 1), (1, 0)]) ] env.run_crons() + prs = [ + (a and to_pr(env, a), b and to_pr(env, b)) + for (a, b) in prs + ] st0 = env['runbot_merge.stagings'].search([]) assert len(st0.batch_ids) == 5