From 575664325638fb3f2e7132a6cd29eab4fe8c3399 Mon Sep 17 00:00:00 2001 From: sabril <5334504+saturninoabril@users.noreply.github.com> Date: Tue, 10 Jun 2025 11:45:29 +0800 Subject: [PATCH] E2E/Test: Fix smoke tests (#31332) * add passwd for psql local query and add server/postgres logs for debugging * set license for smoke tests * fix fmt --- .github/workflows/e2e-tests-ci.yml | 2 ++ e2e-tests/.ci/report.publish.sh | 45 +++++++++++++++----------- e2e-tests/.ci/server.generate.sh | 16 ++++----- e2e-tests/.ci/server.prepare.sh | 14 ++++---- e2e-tests/.ci/server.run_cypress.sh | 4 +-- e2e-tests/.ci/server.run_playwright.sh | 2 +- e2e-tests/.ci/server.start.sh | 23 +++++++++++-- 7 files changed, 66 insertions(+), 40 deletions(-) diff --git a/.github/workflows/e2e-tests-ci.yml b/.github/workflows/e2e-tests-ci.yml index 3f7a96b96c..e6af1f7c74 100644 --- a/.github/workflows/e2e-tests-ci.yml +++ b/.github/workflows/e2e-tests-ci.yml @@ -15,3 +15,5 @@ jobs: with: commit_sha: "${{ inputs.commit_sha }}" status_check_context: "E2E Tests/smoketests" + secrets: + MM_LICENSE: "${{ secrets.MM_E2E_TEST_LICENSE_ONPREM_ENT }}" diff --git a/e2e-tests/.ci/report.publish.sh b/e2e-tests/.ci/report.publish.sh index 01f48ab3b7..18d0db5c61 100755 --- a/e2e-tests/.ci/report.publish.sh +++ b/e2e-tests/.ci/report.publish.sh @@ -16,7 +16,7 @@ cd "$(dirname "$0")" if [ "$TYPE" = "PR" ]; then # In this case, we expect the PR number to be present in the BRANCH variable BRANCH_REGEX='^server-pr-[0-9]+$' - if ! grep -qE "${BRANCH_REGEX}"<<<"$BRANCH"; then + if ! grep -qE "${BRANCH_REGEX}" <<<"$BRANCH"; then mme2e_log "Error: when using TYPE=PR, the BRANCH variable should respect regex '$BRANCH_REGEX'. Aborting." >&2 exit 1 fi @@ -24,7 +24,7 @@ if [ "$TYPE" = "PR" ]; then fi # Env vars used during the test. Their values will be included in the report -: ${TEST:?} # See E2E tests' readme +: ${TEST:?} # See E2E tests' readme : ${BRANCH:?} # May be either a ref, a commit hash, or 'server-pr-PR_NUMBER' (if TYPE=PR) : ${BUILD_ID:?} : ${SERVER:?} # May be either 'onprem' or 'cloud' @@ -56,20 +56,27 @@ if [ -n "${TM4J_API_KEY:-}" ]; then # Assert that the test type is among the ones supported by Zephyr, and select the corresponding folderId case "${SERVER}-${TYPE}" in onprem-RELEASE) - export TM4J_FOLDER_ID="2014475" ;; + export TM4J_FOLDER_ID="2014475" + ;; onprem-MASTER) - export TM4J_FOLDER_ID="2014476" ;; + export TM4J_FOLDER_ID="2014476" + ;; onprem-MASTER_UNSTABLE) - export TM4J_FOLDER_ID="2014478" ;; + export TM4J_FOLDER_ID="2014478" + ;; cloud-RELEASE) - export TM4J_FOLDER_ID="2014474" ;; + export TM4J_FOLDER_ID="2014474" + ;; cloud-CLOUD) - export TM4J_FOLDER_ID="2014479" ;; + export TM4J_FOLDER_ID="2014479" + ;; cloud-CLOUD_UNSTABLE) - export TM4J_FOLDER_ID="2014481" ;; + export TM4J_FOLDER_ID="2014481" + ;; *) mme2e_log "Error: unsupported Zephyr environment for the requested report (SERVER=${SERVER}, TYPE=${TYPE}). Aborting." >&2 exit 1 + ;; esac : ${TEST_CYCLE_LINK_PREFIX:?} : ${TM4J_CYCLE_KEY:-} # Optional. Populated automatically by the reporting script @@ -97,15 +104,15 @@ if [ ! -d "results/" ]; then fi case "$TEST" in - cypress) - npm i - node save_report.js - ;; - playwright) - if [ -n "$WEBHOOK_URL" ]; then - PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm i - # Utilize environment data and report files to generate the webhook body - node report.webhookgen.js | curl -X POST -fsSL -H 'Content-Type: application/json' -d @- "$WEBHOOK_URL" - fi - ;; +cypress) + npm i + node save_report.js + ;; +playwright) + if [ -n "$WEBHOOK_URL" ]; then + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm i + # Utilize environment data and report files to generate the webhook body + node report.webhookgen.js | curl -X POST -fsSL -H 'Content-Type: application/json' -d @- "$WEBHOOK_URL" + fi + ;; esac diff --git a/e2e-tests/.ci/server.generate.sh b/e2e-tests/.ci/server.generate.sh index 4cc125b1b5..d8966124ea 100755 --- a/e2e-tests/.ci/server.generate.sh +++ b/e2e-tests/.ci/server.generate.sh @@ -139,7 +139,7 @@ $(if mme2e_is_token_in_list "openldap" "$ENABLED_DOCKER_SERVICES"; then fi) $(if mme2e_is_token_in_list "elasticsearch" "$ENABLED_DOCKER_SERVICES"; then - echo ' + echo ' elasticsearch: restart: "no" network_mode: host @@ -163,7 +163,7 @@ $(if mme2e_is_token_in_list "elasticsearch" "$ENABLED_DOCKER_SERVICES"; then fi) $(if mme2e_is_token_in_list "opensearch" "$ENABLED_DOCKER_SERVICES"; then - echo ' + echo ' opensearch: restart: "no" network_mode: host @@ -181,7 +181,7 @@ $(if mme2e_is_token_in_list "opensearch" "$ENABLED_DOCKER_SERVICES"; then fi) $(if mme2e_is_token_in_list "redis" "$ENABLED_DOCKER_SERVICES"; then - echo ' + echo ' redis: restart: "no" network_mode: host @@ -338,11 +338,11 @@ generate_env_files() { # Generating service-specific env vars for SERVICE in $ENABLED_DOCKER_SERVICES; do - case $SERVICE in + case $SERVICE in opensearch) echo "MM_ELASTICSEARCHSETTINGS_BACKEND=opensearch" >>.env.server ;; - esac + esac done # Generating TEST-specific env files @@ -376,7 +376,7 @@ generate_env_files() { keycloak) echo "CYPRESS_keycloakBaseUrl=http://localhost:8484" >>.env.cypress ;; - elasticsearch|opensearch) + elasticsearch | opensearch) echo "CYPRESS_elasticsearchConnectionURL=http://localhost:9200" >>.env.cypress ;; esac @@ -385,8 +385,8 @@ generate_env_files() { case "$SERVER" in cloud) echo "CYPRESS_serverEdition=Cloud" >>.env.cypress - echo "CYPRESS_cwsURL=${CWS_URL}" >> .env.cypress - echo "CYPRESS_cwsAPIURL=${CWS_URL}" >> .env.cypress + echo "CYPRESS_cwsURL=${CWS_URL}" >>.env.cypress + echo "CYPRESS_cwsAPIURL=${CWS_URL}" >>.env.cypress ;; *) echo "CYPRESS_serverEdition=E20" >>.env.cypress diff --git a/e2e-tests/.ci/server.prepare.sh b/e2e-tests/.ci/server.prepare.sh index a985ec4dd1..4d6ce18675 100755 --- a/e2e-tests/.ci/server.prepare.sh +++ b/e2e-tests/.ci/server.prepare.sh @@ -5,11 +5,10 @@ cd "$(dirname "$0")" mme2e_log "Configuring starting server parameters that may be changed at runtime" for SETTING in \ - TeamSettings.EnableOpenServer=true \ - PluginSettings.Enable=true \ - PluginSettings.EnableUploads=true \ - PluginSettings.AutomaticPrepackagedPlugins=true - do + TeamSettings.EnableOpenServer=true \ + PluginSettings.Enable=true \ + PluginSettings.EnableUploads=true \ + PluginSettings.AutomaticPrepackagedPlugins=true; do mme2e_log "Configuring parameter: $SETTING" # shellcheck disable=SC2046 ${MME2E_DC_SERVER} exec -T -- server mmctl --local config set $(tr '=' ' ' <<<$SETTING) @@ -34,8 +33,7 @@ if [ "$TEST" = "cypress" ]; then for PLUGIN_URL in \ "https://github.com/mattermost/mattermost-plugin-gitlab/releases/download/v1.3.0/com.github.manland.mattermost-plugin-gitlab-1.3.0.tar.gz" \ "https://github.com/mattermost/mattermost-plugin-demo/releases/download/v0.9.0/com.mattermost.demo-plugin-0.9.0.tar.gz" \ - "https://github.com/mattermost/mattermost-plugin-demo/releases/download/v0.8.0/com.mattermost.demo-plugin-0.8.0.tar.gz" - do + "https://github.com/mattermost/mattermost-plugin-demo/releases/download/v0.8.0/com.mattermost.demo-plugin-0.8.0.tar.gz"; do PLUGIN_NAME="${PLUGIN_URL##*/}" PLUGIN_PATH="tests/fixtures/$PLUGIN_NAME" @@ -63,7 +61,7 @@ for SERVICE in $ENABLED_DOCKER_SERVICES; do fi mme2e_log "Configuring the $SERVICE container" ${MME2E_DC_SERVER} exec -T openldap bash -c 'ldapadd -Y EXTERNAL -H ldapi:/// -w mostest || true' <../../server/tests/custom-schema-objectID.ldif - ${MME2E_DC_SERVER} exec -T -- openldap bash -c 'ldapadd -Y EXTERNAL -H ldapi:/// -w mostest || true' < ../../server/tests/custom-schema-cpa.ldif + ${MME2E_DC_SERVER} exec -T -- openldap bash -c 'ldapadd -Y EXTERNAL -H ldapi:/// -w mostest || true' <../../server/tests/custom-schema-cpa.ldif ${MME2E_DC_SERVER} exec -T -- openldap bash -c 'ldapadd -x -D "cn=admin,dc=mm,dc=test,dc=com" -w mostest' <../../server/tests/test-data.ldif ;; minio) diff --git a/e2e-tests/.ci/server.run_cypress.sh b/e2e-tests/.ci/server.run_cypress.sh index 8e5ed7598c..e98d73d255 100755 --- a/e2e-tests/.ci/server.run_cypress.sh +++ b/e2e-tests/.ci/server.run_cypress.sh @@ -42,7 +42,7 @@ else fi # Collect run results -cat > ../cypress/results/summary.json <../cypress/results/summary.json < ../cypress/results/summary.json < "../cypress/logs/${LOGFILE_SUFFIX}_mattermost.log" 2>&1 +${MME2E_DC_SERVER} logs --no-log-prefix -- server >"../cypress/logs/${LOGFILE_SUFFIX}_mattermost.log" 2>&1 diff --git a/e2e-tests/.ci/server.run_playwright.sh b/e2e-tests/.ci/server.run_playwright.sh index 092d9baddb..a0862bd975 100755 --- a/e2e-tests/.ci/server.run_playwright.sh +++ b/e2e-tests/.ci/server.run_playwright.sh @@ -42,7 +42,7 @@ ${MME2E_DC_SERVER} exec -i -u "$MME2E_UID" -- playwright bash -c "cd e2e-tests/p # Collect run results # Documentation on the results.json file: https://playwright.dev/docs/api/class-testcase#test-case-expected-status -jq -f /dev/stdin ../playwright/results/reporter/results.json > ../playwright/results/summary.json <../playwright/results/summary.json <&2 exit 1 @@ -18,9 +25,21 @@ fi # shellcheck disable=SC2043 for MIGRATION in migration_advanced_permissions_phase_2; do # Query explanation: if it doesn't find the migration in the table, there are 0 results and the command fails with a divide-by-zero error. Otherwise the command succeeds - MIGRATION_CHECK_COMMAND="${MME2E_DC_SERVER} exec -T -- postgres psql -U mmuser mattermost_test -c \"select 1 / (select count(*) from Systems where name = '${MIGRATION}' and value = 'true');\"" - if ! mme2e_wait_command_success "$MIGRATION_CHECK_COMMAND >/dev/null 2>&1" "Waiting for migration to be completed: ${MIGRATION}" "30" "10"; then + MIGRATION_CHECK_COMMAND="${MME2E_DC_SERVER} exec -T postgres sh -c 'PGPASSWORD=mostest psql -U mmuser mattermost_test -c \"select 1 / (select count(*) from Systems where name = '\''${MIGRATION}'\'' and value = '\''true'\'');\"'" + if ! mme2e_wait_command_success "$MIGRATION_CHECK_COMMAND" "Waiting for migration to be completed: ${MIGRATION}" "10" "10"; then mme2e_log "Migration ${MIGRATION} not completed, retry attempts exhausted. Giving up." >&2 + + LOG_DIR="../${TEST}/logs" + mkdir -p "$LOG_DIR" + + # Save server logs to a file + ${MME2E_DC_SERVER} logs --no-log-prefix -- server >"$LOG_DIR/server.log" + mme2e_log "Server logs saved to server.log" + + # Save postgres logs to a file + ${MME2E_DC_SERVER} logs --no-log-prefix -- postgres >"$LOG_DIR/postgres.log" + mme2e_log "Postgres logs saved to postgres.log" + exit 2 fi mme2e_log "${MIGRATION}: completed."