diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 14:22:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 14:22:11 +0000 |
commit | 0c872e02b2c822e3397515ec324051ff540f0cd5 (patch) | |
tree | ce2fb6ce7030e4dad0f4118d21ab6453e5938cdd /scripts/rspec_helpers.sh | |
parent | f7e05a6853b12f02911494c4b3fe53d9540d74fc (diff) | |
download | gitlab-ce-15.7.0-rc42.tar.gz |
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'scripts/rspec_helpers.sh')
-rw-r--r-- | scripts/rspec_helpers.sh | 127 |
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} |