Commit f55b012d authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Made many assertions on GitLab branches asynchronous

The PostReceive process has always been asynchronous, but
until now, it was fast enough that we could in practice
ignore that in these tests.

GitLab 13.12 made us realize that because of its rate limiting
branches API cache. These changes are not enough to make the
tests pass with this cache enabled (default 10s timeout is too
short), but they should improve the tests reliability anyway.
parent f03651e1ef3a
from .utils.hg import LocalRepo
from .utils.project import (
branch_title,
)
def test_push_bookmarks_default_branch(test_project, tmpdir):
......@@ -58,11 +61,14 @@ def test_push_bookmarks_default_branch(test_project, tmpdir):
# it's also necessary to force-push
repo.hg('push', '-f', '-B', 'book2', url)
branches = test_project.api_branches()
assert set(branches) == {'branch/default', 'book1', 'book2'}
assert branches['branch/default']['commit']['title'] == 'Commit 2'
assert branches['book1']['commit']['title'] == 'Commit 1'
assert branches['book2']['commit']['title'] == 'Commit 2'
test_project.wait_assert_api_branches(
lambda branches: (
set(branches) == {'branch/default', 'book1', 'book2'}
and branches['branch/default']['commit']['title'] == 'Commit 2'
and branches['book1']['commit']['title'] == 'Commit 1'
and branches['book2']['commit']['title'] == 'Commit 2'
)
)
def test_push_bookmarks_non_default_branch(test_project, tmpdir):
......@@ -100,8 +106,9 @@ def test_push_bookmarks_non_default_branch(test_project, tmpdir):
# hg branch 'other' has no non bookmarked head, therefore the GitLab
# branch 'branch/other' has been replaced by the bookmark.
branches = test_project.api_branches()
assert set(branches) == {'branch/default', 'book1'}
branches = test_project.wait_assert_api_branches(
lambda branches: set(branches) == {'branch/default', 'book1'},
)
assert branches['branch/default']['commit']['title'] == 'Commit on default'
assert branches['book1']['commit']['title'] == 'Commit 1'
......@@ -129,8 +136,9 @@ def test_push_bookmarks_non_default_branch(test_project, tmpdir):
repo.hg('push', '-f', '-B', 'book2', url)
# New bookmark is listed in GitLab branch, 'branch/other' isn't
branches = test_project.api_branches()
assert set(branches) == {'branch/default', 'book1', 'book2'}
branches = test_project.wait_assert_api_branches(
lambda branches: set(branches) == {'branch/default', 'book1', 'book2'},
)
assert branches['book1']['commit']['title'] == 'Commit 1'
assert branches['book2']['commit']['title'] == 'Commit 2'
......@@ -143,9 +151,10 @@ def test_push_bookmarks_non_default_branch(test_project, tmpdir):
assert repo.hg('bookmarks', '-l', 'book1', '-T', '{rev}').strip() == '2'
repo.hg('push', '-f', '-r', '.', url)
branches = test_project.api_branches()
assert set(branches) == {'branch/default', 'branch/other',
'book1', 'book2'}
branches = test_project.wait_assert_api_branches(
lambda branches: set(branches) == {'branch/default', 'branch/other',
'book1', 'book2'},
)
assert branches['book1']['commit']['title'] == 'Commit 1'
assert branches['book2']['commit']['title'] == 'Commit 2'
assert branches['branch/other']['commit']['title'] == 'Not bookmarked'
......@@ -188,16 +197,19 @@ def test_implicit_move(test_project, tmpdir):
repo.hg('push', url)
# yet, it moved
assert test_project.api_branch_titles()['book'] == 'Commit 2'
test_project.wait_assert_api_branches(
lambda branches: branch_title(branches, 'book') == 'Commit 2',
)
# bookmark removal is possible and it restores the shadowed branch
repo.hg('bookmark', '-d', 'book')
out = repo.hg('push', '-B', 'book', url, expected_return_code=1)
assert 'deleting remote bookmark book' in out
assert test_project.api_branch_titles() == {
'branch/default': 'Commit on default',
'branch/other': 'Commit 2',
}
test_project.wait_assert_api_branch_titles(
{'branch/default': 'Commit on default',
'branch/other': 'Commit 2',
},
)
# now imagine a bookmark slides to the head of a branch
# first, prepare it
......@@ -216,7 +228,7 @@ def test_implicit_move(test_project, tmpdir):
'branch/other': 'Commit 2',
}
assert test_project.api_branch_titles() == gl_branches
test_project.wait_assert_api_branch_titles(gl_branches)
if test_project.hg_native:
# additional test to check that sliding to the head of
......@@ -226,8 +238,10 @@ def test_implicit_move(test_project, tmpdir):
assert test_project.api_default_branch() == 'branch/default'
repo.hg('bookmark', '--force', '-r', 'default', 'sliding')
repo.hg('push', '-B', 'sliding', url, expected_return_code=1)
assert test_project.api_branch_titles() == {
'branch/default': 'Commit on default',
'branch/other': 'Commit 2',
'sliding': 'Commit on default',
}
test_project.wait_assert_api_branch_titles(
{
'branch/default': 'Commit on default',
'branch/other': 'Commit 2',
'sliding': 'Commit on default'
},
)
......@@ -29,9 +29,7 @@ def test_push_branch_then_close(test_project, tmpdir):
repo.hg('commit', '-m', "Closing branch `other`", '--close-branch')
repo.hg('push')
assert test_project.api_branch_titles() == {
'branch/default': 'Commit 1',
}
test_project.wait_assert_api_branch_titles({'branch/default': 'Commit 1'})
def test_close_default_branch(test_project, tmpdir):
......@@ -123,10 +121,10 @@ def test_compat_closed_branch(test_project, tmpdir):
print(repo.graphlog())
repo.hg('push')
assert test_project.api_branch_titles() == {
test_project.wait_assert_api_branch_titles({
'branch/default': 'Commit 1',
'branch/other': 'Closing branch `other`',
}
})
test_project.extend_hgrc('hg-git.prune-newly-closed-branches=yes')
......@@ -135,16 +133,16 @@ def test_compat_closed_branch(test_project, tmpdir):
repo.hg('commit', '-m', "More work 1")
repo.hg('push')
assert test_project.api_branch_titles() == {
test_project.wait_assert_api_branch_titles({
'branch/default': 'More work 1',
'branch/other': 'Closing branch `other`',
}
})
test_project.extend_hgrc('hg-git.prune-previously-closed-branches=yes')
repo_path.join('foo').write("even more work on default branch")
repo.hg('commit', '-m', "More work 2")
repo.hg('push')
assert test_project.api_branch_titles() == {
test_project.wait_assert_api_branch_titles({
'branch/default': 'More work 2',
}
})
......@@ -60,7 +60,7 @@ def test_basic(git_project, tmpdir):
content="Important instructions",
branch='master',
commit_message='README')
assert git_project.api_branch_titles() == {'master': 'README'}
git_project.wait_assert_api_branch_titles({'master': 'README'})
repo.git('pull', ssh_cmd=ssh_cmd)
assert repo_path.join('README.txt').read() == "Important instructions"
# later on we'll check the full log.
......@@ -77,7 +77,7 @@ def test_basic(git_project, tmpdir):
clone.git('commit', '-m', 'Commit in clone')
clone.git('push')
assert git_project.api_branch_titles() == {'master': 'Commit in clone'}
git_project.wait_assert_api_branch_titles({'master': 'Commit in clone'})
# Pulling new commit in original repo (over SSH) for correctness assertion
repo.git('pull', ssh_cmd=ssh_cmd)
......@@ -300,9 +300,7 @@ def test_export_import(git_project, tmpdir):
) as imported:
assert imported.vcs_type == git_project.vcs_type
assert imported.api_branch_titles() == {
'master': 'Commit 0',
}
imported.wait_assert_api_branch_titles({'master': 'Commit 0'})
clone = GitRepo.clone(imported.owner_basic_auth_url,
tmpdir / 'imported-clone')
assert clone.sha('master') == repo.sha('master')
......@@ -562,22 +562,22 @@ def test_mergerequest_api_fast_forward_required(test_project, tmpdir):
repo.path.join('whale').write("A lion would be puzzled to see a whale")
repo.hg('commit', '-Am', "Whale")
repo.hg('push')
assert test_project.api_branch_titles() == {
test_project.wait_assert_api_branch_titles({
'branch/default': 'Même une antilope !',
'topic/sea/whale': 'Whale',
}
})
mr_id = test_project.api_create_merge_request(source='topic/sea/whale',
target='branch/default')
api_accept_merge_request(test_project, mr_id, check_merged=False)
# Ideally we should have had an error, but that's not the case as of
# this writing. In the meanwhile, nothing has changed
# this writing. Meanwhile, nothing has changed
assert test_project.api_branch_titles() == {
test_project.wait_assert_api_branch_titles({
'branch/default': 'Même une antilope !',
'topic/sea/whale': 'Whale',
}
})
repo.hg('pull')
log = repo.hg('log', '-T', '{rev}:{topic}:{phase}\n')
# unchanged revnos proves that Heptapod didn't do anything funky
......@@ -616,10 +616,10 @@ def test_mergerequest_api_semi_linear(test_project, tmpdir):
repo.path.join('whale').write("A lion would be puzzled to see a whale")
repo.hg('commit', '-Am', "Whale")
repo.hg('push')
assert test_project.api_branch_titles() == {
test_project.wait_assert_api_branch_titles({
'branch/default': merge_desc,
'topic/sea/whale': 'Whale',
}
})
mr_id = test_project.api_create_merge_request(source='topic/sea/whale',
target='branch/default')
......
......@@ -33,13 +33,15 @@ def test_push_multiple_heads_merge(test_project, tmpdir):
repo.hg('push', '-f', owner_url)
branches = test_project.api_branches()
assert len(branches) == 3
heads_titles = {'Head 1', 'Head 2'}
assert branches['branch/default']['commit']['title'] in heads_titles
assert set(info['commit']['title']
for name, info in branches.items()
if name.startswith('wild/')) == heads_titles
test_project.wait_assert_api_branches(
lambda branches: (
len(branches) == 3
and branches['branch/default']['commit']['title'] in heads_titles
and set(info['commit']['title']
for name, info in branches.items()
if name.startswith('wild/')) == heads_titles
))
# and let's get back to the normal case by merging those heads
merge_msg = "Merging wild heads"
......@@ -47,9 +49,12 @@ def test_push_multiple_heads_merge(test_project, tmpdir):
repo.hg('commit', '-m', merge_msg)
repo.hg('push', owner_url)
branches = test_project.api_branches()
assert len(branches) == 1
assert branches['branch/default']['commit']['title'] == merge_msg
test_project.wait_assert_api_branches(
lambda branches: (
len(branches) == 1
and branches['branch/default']['commit']['title'] == merge_msg
)
)
def test_push_multiple_heads_with_branch(test_project, tmpdir):
......@@ -129,8 +134,9 @@ def test_push_multiple_heads_switch_branch(test_project, tmpdir):
repo.hg('commit', '-m', 'On other')
repo.hg('push', '--new-branch')
branches = test_project.api_branches()
assert len(branches) == 4
branches = test_project.wait_assert_api_branches(
lambda branches: len(branches) == 4
)
heads_titles = {'Head 1', 'Head 2'}
assert branches['branch/default']['commit']['title'] in heads_titles
assert branches['branch/other']['commit']['title'] == 'On other'
......@@ -147,10 +153,14 @@ def test_push_multiple_heads_switch_branch(test_project, tmpdir):
print(repo.graphlog())
repo.hg('push')
branches = test_project.api_branches()
assert set(b for b in branches if not b.startswith('wild/')) == {
'branch/default', 'branch/other', 'topic/default/zzetop'}
branches = test_project.wait_assert_api_branches(
lambda branches: set(b for b in branches
if not b.startswith('wild/')
) == {'branch/default',
'branch/other',
'topic/default/zzetop'
},
)
assert set(info['commit']['title']
for name, info in branches.items()
if name.startswith('wild/')) == heads_titles
......@@ -207,9 +217,12 @@ def test_push_multiple_closed_heads(test_project, tmpdir):
repo.hg('commit', '-Am', 'follow-up')
repo.hg('push', '-r', '.')
branches = test_project.api_branches()
assert len(branches) == 1
assert branches['branch/default']['commit']['title'] == 'follow-up'
test_project.wait_assert_api_branches(
lambda branches: (
len(branches) == 1
and branches['branch/default']['commit']['title'] == 'follow-up'
)
)
def test_push_multiple_heads_topic_merge(test_project, tmpdir):
......@@ -261,7 +274,8 @@ def test_push_multiple_heads_topic_merge(test_project, tmpdir):
repo.hg('commit', '-m', merge_msg)
repo.hg('push', owner_url)
branches = test_project.api_branches()
assert set(branches) == {'branch/default', 'topic/default/zz'}
branches = test_project.wait_assert_api_branches(
lambda branches: set(branches) == {'branch/default',
'topic/default/zz'})
assert branches['topic/default/zz']['commit']['title'] == merge_msg
assert branches['branch/default']['commit']['title'] == 'Commit 0'
......@@ -12,23 +12,37 @@ from .utils import (
from .test_push import prepare_simple_repo
def dict_same_value(d, key1, key2):
return d.get(key1) == d.get(key2)
def gl_branch_has_hg_sha(all_branches, branch):
return dict_same_value(all_branches[branch]['commit'], 'id', 'hg_id')
@needs.sql
@needs.hg_git # test starts from a hg_git project
def test_commit_page_fallback(test_project, tmpdir):
# this tests is expected to become flaky because of stronger
# server side caching of branches or something.
proj = test_project
prepare_simple_repo(proj, tmpdir.join('repo'))
commit = proj.api_branches()['topic/default/zetop']['commit']
topic = 'topic/default/zetop'
# make sure test stays relevant
branches = proj.wait_assert_api_branches(
lambda branches: not gl_branch_has_hg_sha(branches, topic))
commit = branches[topic]['commit']
git_sha, hg_sha = commit['id'], commit['hg_id']
assert git_sha != hg_sha # make sure test stays relevant
# cannot change vcs_type from API, and that's a good thing.
# That it makes these tests not work on remote Heptapod instances
# is a minor inconvenience.
proj.heptapod.psql(
"UPDATE projects SET vcs_type='hg' WHERE id=%d" % proj.id)
native_commit = proj.api_branches()['topic/default/zetop']['commit']
assert native_commit['id'] == hg_sha
proj.wait_assert_api_branches(
lambda branches: gl_branch_has_hg_sha(branches, topic))
webdriver = proj.owner_webdriver
webdriver.get('/'.join((proj.url, '-', 'commit', git_sha)))
......
......@@ -557,7 +557,7 @@ def test_internal_force_push_default_branch(test_project, tmpdir):
repo.hg('amend', '-m', "Amended")
repo.hg('push', url)
assert test_project.api_branch_titles() == {'branch/default': 'Amended'}
test_project.wait_assert_api_branch_titles({'branch/default': 'Amended'})
clone = LocalRepo.clone(url, tmpdir.join('repo2'))
log = clone.hg('log', '-T', '{desc}:{phase}\n')
......
......@@ -8,6 +8,7 @@ import requests
from .utils.hg import LocalRepo
from .utils.project import (
branch_title,
ProjectAccess,
)
......@@ -61,7 +62,9 @@ def test_create_file_on_existing_gitlab_branch(public_project, tmpdir, topic):
content="foo2",
commit_message="Foo TTW",
)
assert proj.api_branch_titles()[gitlab_branch] == 'Foo TTW'
assert proj.wait_assert_api_branches(
lambda branches: branch_title(branches, gitlab_branch) == 'Foo TTW',
)
clone.hg('pull', url, '-u')
assert clone_path.join('foo').read() == "foo2"
......@@ -71,7 +74,10 @@ def test_create_file_on_existing_gitlab_branch(public_project, tmpdir, topic):
branch=gitlab_branch,
commit_message="Bye, you fool",
)
assert proj.api_branch_titles()[gitlab_branch] == 'Bye, you fool'
proj.wait_assert_api_branches(
lambda branches: branch_title(branches,
gitlab_branch) == 'Bye, you fool',
)
clone.hg('pull', url, '-u')
assert not clone_path.join('foo').exists()
......
......@@ -126,11 +126,13 @@ def test_topic_rename(test_project, tmpdir):
repo.hg('topic', '-r', '.', 'newtopname')
repo.hg('push', url)
branches = test_project.api_branches()
assert set(branches) == {'branch/default', 'topic/default/newtopname'}
assert branches['branch/default']['commit']['title'] == 'Commit 0'
assert (branches['topic/default/newtopname']['commit']['title']
== 'Commit 1')
test_project.wait_assert_api_branches(
lambda branches: (
set(branches) == {'branch/default', 'topic/default/newtopname'}
and branches['branch/default']['commit']['title'] == 'Commit 0'
and (branches['topic/default/newtopname']['commit']['title']
== 'Commit 1')
))
def test_topic_rename_partial(test_project, tmpdir):
......@@ -159,10 +161,11 @@ def test_topic_rename_partial(test_project, tmpdir):
repo.hg('topic', '-r', '.', 'newtopname')
repo.hg('push', url)
branches = test_project.api_branches()
assert set(branches) == {'branch/default',
'topic/default/zetop',
'topic/default/newtopname'}
branches = test_project.wait_assert_api_branches(
lambda branches: set(branches) == {'branch/default',
'topic/default/zetop',
'topic/default/newtopname'},
)
assert branches['branch/default']['commit']['title'] == 'Commit 0'
assert branches['topic/default/zetop']['commit']['title'] == 'Commit 1'
assert (branches['topic/default/newtopname']['commit']['title']
......@@ -198,11 +201,11 @@ def test_topic_branch_change(test_project, tmpdir):
repo.hg('push', url)
# the GitLab branch for the old branch/topic combination has been pruned
assert test_project.api_branch_titles() == {
test_project.wait_assert_api_branch_titles({
'branch/default': 'Commit 0',
'branch/other': 'Commit 1',
'topic/default/zetop': 'Commit 2',
}
})
def test_topic_publish(test_project, tmpdir):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment