Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod-tests
Commits
eb157863c7b9
Commit
c1eabc4f
authored
Jan 18, 2022
by
Georges Racinet
🦑
Browse files
native migration: testing pipelines
We're also checking a MR pipeline, for theire SHA-based specific variables.
parent
ea84482bc2bc
Pipeline
#31311
passed with stages
in 72 minutes and 28 seconds
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
tests/test_native_migration.py
View file @
eb157863
...
...
@@ -12,6 +12,7 @@ from .utils import (
hg
,
needs
,
unique_name
,
wait_assert
,
)
from
.utils.constants
import
DATA_DIR
from
.utils.merge_request
import
MergeRequest
...
...
@@ -25,6 +26,9 @@ from .test_merge_requests import (
prepare_topic
,
rebase_publish_push
,
)
from
.utils.runner
import
(
job_variables
,
)
def
dict_same_value
(
d
,
key1
,
key2
):
...
...
@@ -154,3 +158,77 @@ def test_partially_migrated_mrs(heptapod, tmpdir):
imported
.
rake_migrate_native
()
assert
mr_info
[
'sha'
]
==
topic_sha
assert_commit_link
(
imported
,
1
,
"Même une antilope !"
,
topic_sha
)
def
assert_jobs_sha_consistency
(
proj
,
shas
,
wait_count
=
1
):
"""Assert existence of jobs for all given shas and internal consistency.
"""
# TODO include in a Project method
jobs
=
wait_assert
(
lambda
:
proj
.
api_jobs
(),
lambda
jobs
:
sum
(
len
(
sj
)
for
sj
in
jobs
.
values
())
>=
wait_count
)
for
sha
in
shas
:
sha_jobs
=
jobs
.
get
(
sha
)
assert
sha_jobs
# reject also empty list, if even possible
for
job
in
sha_jobs
:
assert
job
[
'pipeline'
][
'sha'
]
==
sha
def
assert_acquired_job_sha_consistency
(
acquired_jobs
,
sha
,
base_sha
=
None
):
job
=
acquired_jobs
.
get
(
sha
)
assert
job
# also rejecting empty list if possible
variables
=
job_variables
(
job
)
pipeline_id
=
int
(
variables
[
'CI_PIPELINE_ID'
])
vcs_info
=
job
[
'git_info'
]
assert
vcs_info
[
'sha'
]
==
sha
assert
vcs_info
[
'refspecs'
][
0
]
==
'+%s:refs/pipelines/%d'
%
(
sha
,
pipeline_id
)
if
base_sha
is
not
None
:
assert
vcs_info
[
'before_sha'
]
==
base_sha
assert
variables
[
'CI_COMMIT_SHA'
]
==
sha
assert
sha
.
startswith
(
variables
[
'CI_COMMIT_SHORT_SHA'
])
@
needs
.
hg_git
@
needs
.
services
def
test_native_migration_pipeline
(
test_project_with_runner
,
tmpdir
):
proj
,
runner
=
test_project_with_runner
repo
=
hg
.
LocalRepo
.
init
(
tmpdir
.
join
(
'repo'
),
default_url
=
proj
.
owner_basic_auth_url
)
topic
=
prepare_topic
(
repo
,
with_ci
=
True
,
with_mr_pipelines
=
True
)
default_sha
=
repo
.
node
(
'default'
)
base_sha
=
repo
.
node
(
'0'
)
topic_sha
=
repo
.
node
(
topic
)
# baseline: just checking that everything is as expected (Git SHAs)
gl_branches
=
proj
.
api_branches
()
default_git_sha
,
topic_git_sha
=
[
gl_branches
[
br
][
'commit'
][
'id'
]
for
br
in
(
'branch/default'
,
'topic/default/antelope'
)]
assert
default_git_sha
!=
default_sha
assert
topic_git_sha
!=
topic_sha
assert_jobs_sha_consistency
(
proj
,
(
default_git_sha
,
topic_git_sha
),
wait_count
=
2
)
MergeRequest
.
api_create
(
proj
,
'topic/default/antelope'
)
proj
.
rake_migrate_native
()
assert_jobs_sha_consistency
(
proj
,
(
default_sha
,
topic_sha
),
wait_count
=
3
)
acquired_jobs
=
{
job
[
'git_info'
][
'hgsha'
]:
job
for
job
in
runner
.
wait_assert_jobs
(
2
)}
# because we waited before creating the MR for at least two jobs to
# be created, we can be confident that the MR job is the third.
mr_job
=
runner
.
wait_assert_one_job
()
assert_acquired_job_sha_consistency
(
acquired_jobs
,
default_sha
)
# We could expect before_sha to be base_sha for that one,
# but that is not the case, it is ZERO_SHA (same before migration,
# TODO maybe compare with a Git project to check it is not a general
# bug, unrelated to what is been tested here).
assert_acquired_job_sha_consistency
(
acquired_jobs
,
topic_sha
)
mr_vars
=
job_variables
(
mr_job
)
# assertions for MR job specific variables
assert
mr_vars
[
'CI_MERGE_REQUEST_DIFF_BASE_SHA'
]
==
base_sha
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment