Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/rspec_helpers.sh')
-rw-r--r--scripts/rspec_helpers.sh127
1 files changed, 41 insertions, 86 deletions
diff --git a/scripts/rspec_helpers.sh b/scripts/rspec_helpers.sh
index 14c5b94e921..923b633fcc9 100644
--- a/scripts/rspec_helpers.sh
+++ b/scripts/rspec_helpers.sh
@@ -3,44 +3,14 @@
function retrieve_tests_metadata() {
mkdir -p $(dirname "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}") $(dirname "${FLAKY_RSPEC_SUITE_REPORT_PATH}") "${RSPEC_PROFILING_FOLDER_PATH}"
- if [[ -n "${RETRIEVE_TESTS_METADATA_FROM_PAGES}" ]]; then
- if [[ ! -f "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" ]]; then
- curl --location -o "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" "https://gitlab-org.gitlab.io/gitlab/${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" ||
- echo "{}" > "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}"
- fi
-
- if [[ ! -f "${FLAKY_RSPEC_SUITE_REPORT_PATH}" ]]; then
- curl --location -o "${FLAKY_RSPEC_SUITE_REPORT_PATH}" "https://gitlab-org.gitlab.io/gitlab/${FLAKY_RSPEC_SUITE_REPORT_PATH}" ||
- echo "{}" > "${FLAKY_RSPEC_SUITE_REPORT_PATH}"
- fi
- else
- # ${CI_DEFAULT_BRANCH} might not be master in other forks but we want to
- # always target the canonical project here, so the branch must be hardcoded
- local project_path="gitlab-org/gitlab"
- local artifact_branch="master"
- local username="gitlab-bot"
- local job_name="update-tests-metadata"
- local test_metadata_job_id
-
- # Ruby
- test_metadata_job_id=$(scripts/api/get_job_id.rb --endpoint "https://gitlab.com/api/v4" --project "${project_path}" -q "status=success" -q "ref=${artifact_branch}" -q "username=${username}" -Q "scope=success" --job-name "${job_name}")
-
- if [[ -n "${test_metadata_job_id}" ]]; then
- echo "test_metadata_job_id: ${test_metadata_job_id}"
-
- if [[ ! -f "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" ]]; then
- scripts/api/download_job_artifact.rb --endpoint "https://gitlab.com/api/v4" --project "${project_path}" --job-id "${test_metadata_job_id}" --artifact-path "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" || echo "{}" > "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}"
- fi
-
- if [[ ! -f "${FLAKY_RSPEC_SUITE_REPORT_PATH}" ]]; then
- scripts/api/download_job_artifact.rb --endpoint "https://gitlab.com/api/v4" --project "${project_path}" --job-id "${test_metadata_job_id}" --artifact-path "${FLAKY_RSPEC_SUITE_REPORT_PATH}" ||
- echo "{}" > "${FLAKY_RSPEC_SUITE_REPORT_PATH}"
- fi
- else
- echo "test_metadata_job_id couldn't be found!"
+ if [[ ! -f "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" ]]; then
+ curl --location -o "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" "https://gitlab-org.gitlab.io/gitlab/${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" ||
echo "{}" > "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}"
+ fi
+
+ if [[ ! -f "${FLAKY_RSPEC_SUITE_REPORT_PATH}" ]]; then
+ curl --location -o "${FLAKY_RSPEC_SUITE_REPORT_PATH}" "https://gitlab-org.gitlab.io/gitlab/${FLAKY_RSPEC_SUITE_REPORT_PATH}" ||
echo "{}" > "${FLAKY_RSPEC_SUITE_REPORT_PATH}"
- fi
fi
}
@@ -74,31 +44,8 @@ function update_tests_metadata() {
function retrieve_tests_mapping() {
mkdir -p $(dirname "$RSPEC_PACKED_TESTS_MAPPING_PATH")
- if [[ -n "${RETRIEVE_TESTS_METADATA_FROM_PAGES}" ]]; then
- if [[ ! -f "${RSPEC_PACKED_TESTS_MAPPING_PATH}" ]]; then
- (curl --location -o "${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz" "https://gitlab-org.gitlab.io/gitlab/${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz" && gzip -d "${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz") || echo "{}" > "${RSPEC_PACKED_TESTS_MAPPING_PATH}"
- fi
- else
- # ${CI_DEFAULT_BRANCH} might not be master in other forks but we want to
- # always target the canonical project here, so the branch must be hardcoded
- local project_path="gitlab-org/gitlab"
- local artifact_branch="master"
- local username="gitlab-bot"
- local job_name="update-tests-metadata"
- local test_metadata_with_mapping_job_id
-
- test_metadata_with_mapping_job_id=$(scripts/api/get_job_id.rb --endpoint "https://gitlab.com/api/v4" --project "${project_path}" -q "status=success" -q "ref=${artifact_branch}" -q "username=${username}" -Q "scope=success" --job-name "${job_name}")
-
- if [[ -n "${test_metadata_with_mapping_job_id}" ]]; then
- echo "test_metadata_with_mapping_job_id: ${test_metadata_with_mapping_job_id}"
-
- if [[ ! -f "${RSPEC_PACKED_TESTS_MAPPING_PATH}" ]]; then
- (scripts/api/download_job_artifact.rb --endpoint "https://gitlab.com/api/v4" --project "${project_path}" --job-id "${test_metadata_with_mapping_job_id}" --artifact-path "${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz" && gzip -d "${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz") || echo "{}" > "${RSPEC_PACKED_TESTS_MAPPING_PATH}"
- fi
- else
- echo "test_metadata_with_mapping_job_id couldn't be found!"
- echo "{}" > "${RSPEC_PACKED_TESTS_MAPPING_PATH}"
- fi
+ if [[ ! -f "${RSPEC_PACKED_TESTS_MAPPING_PATH}" ]]; then
+ (curl --location -o "${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz" "https://gitlab-org.gitlab.io/gitlab/${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz" && gzip -d "${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz") || echo "{}" > "${RSPEC_PACKED_TESTS_MAPPING_PATH}"
fi
scripts/unpack-test-mapping "${RSPEC_PACKED_TESTS_MAPPING_PATH}" "${RSPEC_TESTS_MAPPING_PATH}"
@@ -107,31 +54,8 @@ function retrieve_tests_mapping() {
function retrieve_frontend_fixtures_mapping() {
mkdir -p $(dirname "$FRONTEND_FIXTURES_MAPPING_PATH")
- if [[ -n "${RETRIEVE_TESTS_METADATA_FROM_PAGES}" ]]; then
- if [[ ! -f "${FRONTEND_FIXTURES_MAPPING_PATH}" ]]; then
- (curl --location -o "${FRONTEND_FIXTURES_MAPPING_PATH}" "https://gitlab-org.gitlab.io/gitlab/${FRONTEND_FIXTURES_MAPPING_PATH}") || echo "{}" > "${FRONTEND_FIXTURES_MAPPING_PATH}"
- fi
- else
- # ${CI_DEFAULT_BRANCH} might not be master in other forks but we want to
- # always target the canonical project here, so the branch must be hardcoded
- local project_path="gitlab-org/gitlab"
- local artifact_branch="master"
- local username="gitlab-bot"
- local job_name="generate-frontend-fixtures-mapping"
- local test_metadata_with_mapping_job_id
-
- test_metadata_with_mapping_job_id=$(scripts/api/get_job_id.rb --endpoint "https://gitlab.com/api/v4" --project "${project_path}" -q "ref=${artifact_branch}" -q "username=${username}" -Q "scope=success" --job-name "${job_name}")
-
- if [[ $? -eq 0 ]] && [[ -n "${test_metadata_with_mapping_job_id}" ]]; then
- echo "test_metadata_with_mapping_job_id: ${test_metadata_with_mapping_job_id}"
-
- if [[ ! -f "${FRONTEND_FIXTURES_MAPPING_PATH}" ]]; then
- (scripts/api/download_job_artifact.rb --endpoint "https://gitlab.com/api/v4" --project "${project_path}" --job-id "${test_metadata_with_mapping_job_id}" --artifact-path "${FRONTEND_FIXTURES_MAPPING_PATH}") || echo "{}" > "${FRONTEND_FIXTURES_MAPPING_PATH}"
- fi
- else
- echo "test_metadata_with_mapping_job_id couldn't be found!"
- echo "{}" > "${FRONTEND_FIXTURES_MAPPING_PATH}"
- fi
+ if [[ ! -f "${FRONTEND_FIXTURES_MAPPING_PATH}" ]]; then
+ (curl --location -o "${FRONTEND_FIXTURES_MAPPING_PATH}" "https://gitlab-org.gitlab.io/gitlab/${FRONTEND_FIXTURES_MAPPING_PATH}") || echo "{}" > "${FRONTEND_FIXTURES_MAPPING_PATH}"
fi
}
@@ -324,9 +248,40 @@ function retry_failed_rspec_examples() {
# Merge the JUnit report from retry into the first-try report
junit_merge "${JUNIT_RETRY_FILE}" "${JUNIT_RESULT_FILE}" --update-only
+ if [[ $rspec_run_status -eq 0 ]]; then
+ # The test is flaky because it succeeded after being retried.
+ # Make the pipeline "pass with warnings" if the flaky test is part of this MR.
+ warn_on_successfully_retried_test
+ fi
+
exit $rspec_run_status
}
+# Exit with an allowed_failure exit code if the flaky test was part of the MR that triggered this pipeline
+function warn_on_successfully_retried_test {
+ local changed_files=$(git diff --name-only $CI_MERGE_REQUEST_TARGET_BRANCH_SHA | grep spec)
+ echoinfo "A test was flaky and succeeded after being retried. Checking to see if flaky test is part of this MR..."
+
+ if [[ "$changed_files" == "" ]]; then
+ echoinfo "Flaky test was not part of this MR."
+ return
+ fi
+
+ while read changed_file
+ do
+ # include the root path in the regexp to eliminate false positives
+ changed_file="^\./$changed_file"
+
+ if grep -q "$changed_file" "$RETRIED_TESTS_REPORT_PATH"; then
+ echoinfo "Flaky test '$changed_file' was found in the list of files changed by this MR."
+ echoinfo "Exiting with code $SUCCESSFULLY_RETRIED_TEST_EXIT_CODE."
+ exit $SUCCESSFULLY_RETRIED_TEST_EXIT_CODE
+ fi
+ done <<< "$changed_files"
+
+ echoinfo "Flaky test was not part of this MR."
+}
+
function rspec_rerun_previous_failed_tests() {
local test_file_count_threshold=${RSPEC_PREVIOUS_FAILED_TEST_FILE_COUNT_THRESHOLD:-10}
local matching_tests_file=${1}