Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve the e2e-tests.sh script to make local functional tests faster #1375

Merged
merged 4 commits into from
Feb 3, 2025

Conversation

monsieurswag
Copy link
Contributor

@monsieurswag monsieurswag commented Jan 17, 2025

Summary by CodeRabbit

  • Documentation

    • Updated README.md to specify poetry 2.0+ as the required version for development setup
  • Chores

    • Updated .gitignore with new test-related entries
    • Modified end-to-end test script with improved error handling and flexibility, including new command-line flags and enhanced functionality

@monsieurswag monsieurswag force-pushed the improve/e2e_tests_script branch from 8c562d4 to ca1d933 Compare January 17, 2025 16:23
@monsieurswag monsieurswag marked this pull request as ready for review January 17, 2025 18:44
@ab-smith ab-smith changed the title Improve the e2e-tests.sh script to make local functional tests faster test: improve the e2e-tests.sh script to make local functional tests faster Jan 22, 2025
@ab-smith
Copy link
Contributor

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Jan 22, 2025

✅ Actions performed

Full review triggered.

Copy link
Contributor

coderabbitai bot commented Jan 22, 2025

Walkthrough

The pull request introduces updates to the project's development setup and testing infrastructure. The changes span across three files: README.md, frontend/.gitignore, and frontend/tests/e2e-tests.sh. The modifications primarily focus on updating the dependency version for poetry, reorganizing ignored files in the .gitignore, and enhancing the end-to-end testing script with improved error handling and flexible execution options.

Changes

File Change Summary
README.md Updated poetry dependency version from 1.8+ to 2.0+; minor formatting adjustments.
frontend/.gitignore Added new entries: tests/.frontend_hash, tests/results/, tests/reports/; removed previous entries for tests/results/ and tests/reports/.
frontend/tests/e2e-tests.sh - Added new script flags (-q, -v, -k)
- Introduced DB_INIT_NAME variable
- Removed VENV_PATH
- Updated path resolution and error handling
- Modified test execution and database management logic

Poem

🐰 A Rabbit's Ode to Testing Delight
With poetry's version and flags so bright,
Our scripts now dance with newfound might,
Ignoring files with gitignore's grace,
E2e tests running at lightning pace!
🚀 Code on, brave developers! 🌟


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
frontend/tests/e2e-tests.sh (1)

83-98: Improve Python script formatting and error handling.

The Python script for port checking is more robust with the timeout, but the formatting could be improved.

-if python3 -c "
-import socket
-try :
-	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-	# Using python to check if the port is opened is safer for compatibility
-	# But it increase the execution time of the script with the timeout
-	# A local TCP connection should never reach a 1s delay
-	s.settimeout(1)
-	s.connect(('127.0.0.1', $BACKEND_PORT))
-	port_already_in_used = True
-except :
-	port_already_in_used = False
-s.close()
-# We use "not" because 0 is True and 1 is False in bash
-exit(not port_already_in_used)
-"; then
+if python3 -c "
+import socket
+try:
+    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    # Using python to check if the port is opened is safer for compatibility
+    # But it increases the execution time of the script with the timeout
+    # A local TCP connection should never reach a 1s delay
+    s.settimeout(1)
+    s.connect(('127.0.0.1', $BACKEND_PORT))
+    port_already_in_use = True
+except (socket.timeout, socket.error):
+    port_already_in_use = False
+finally:
+    s.close()
+# We use "not" because 0 is True and 1 is False in bash
+exit(not port_already_in_use)
+"; then
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 96-96: Word is of the form "A"B"C" (B indicated). Did you mean "ABC" or "A"B"C"?

(SC2140)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 959f097 and ab4eee0.

📒 Files selected for processing (3)
  • README.md (1 hunks)
  • frontend/.gitignore (1 hunks)
  • frontend/tests/e2e-tests.sh (8 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
frontend/tests/e2e-tests.sh

[warning] 96-96: Word is of the form "A"B"C" (B indicated). Did you mean "ABC" or "A"B"C"?

(SC2140)


[error] 159-159: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).

(SC2199)


[warning] 230-230: Use 'find .. -print0 | xargs -0 ..' or 'find .. -exec .. +' to allow non-alphanumeric filenames.

(SC2038)


[error] 238-238: Argument mixes string and array. Use * or separate argument.

(SC2145)


[error] 240-240: Argument mixes string and array. Use * or separate argument.

(SC2145)

🔇 Additional comments (5)
frontend/.gitignore (1)

4-6: LGTM! Appropriate test output directories and cache files added to .gitignore.

The added entries properly exclude test results, reports, and build cache from version control.

frontend/tests/e2e-tests.sh (3)

2-2: Improve path resolution robustness.

Using realpath is a good improvement for resolving the application directory path, making it more reliable across different environments.


79-80: Good addition of root user warning.

The warning about running with root privileges is important for preventing Playwright issues.


188-197: Good optimization with database snapshot feature.

The database snapshot feature significantly improves startup time by avoiding unnecessary migrations.

README.md (1)

279-279: LGTM! Poetry version requirement updated.

The update to poetry 2.0+ aligns with the changes in the testing infrastructure.

Comment on lines 229 to 235
FRONTEND_HASH_FILE="$APP_DIR/frontend/tests/.frontend_hash"
FRONTEND_HASH=$(find "$APP_DIR/frontend/src" -type f \( -name "*.ts" -o -name "*.svelte" \) | xargs -I {} md5sum {} | md5sum)

if ! cmp <(cat "$FRONTEND_HASH_FILE") <(echo "$FRONTEND_HASH") &>/dev/null; then
pnpm run build # Required for the "pnpm run preview" command of playwright.config.ts
echo "$FRONTEND_HASH" > "$FRONTEND_HASH_FILE"
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Fix potential issues with filenames in frontend hash calculation.

The frontend hash calculation needs to handle filenames with spaces and special characters properly.

-FRONTEND_HASH=$(find "$APP_DIR/frontend/src" -type f \( -name "*.ts" -o -name "*.svelte" \) | xargs -I {} md5sum {} | md5sum)
+FRONTEND_HASH=$(find "$APP_DIR/frontend/src" -type f \( -name "*.ts" -o -name "*.svelte" \) -print0 | xargs -0 md5sum | md5sum)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
FRONTEND_HASH_FILE="$APP_DIR/frontend/tests/.frontend_hash"
FRONTEND_HASH=$(find "$APP_DIR/frontend/src" -type f \( -name "*.ts" -o -name "*.svelte" \) | xargs -I {} md5sum {} | md5sum)
if ! cmp <(cat "$FRONTEND_HASH_FILE") <(echo "$FRONTEND_HASH") &>/dev/null; then
pnpm run build # Required for the "pnpm run preview" command of playwright.config.ts
echo "$FRONTEND_HASH" > "$FRONTEND_HASH_FILE"
fi
FRONTEND_HASH_FILE="$APP_DIR/frontend/tests/.frontend_hash"
FRONTEND_HASH=$(find "$APP_DIR/frontend/src" -type f \( -name "*.ts" -o -name "*.svelte" \) -print0 | xargs -0 md5sum | md5sum)
if ! cmp <(cat "$FRONTEND_HASH_FILE") <(echo "$FRONTEND_HASH") &>/dev/null; then
pnpm run build # Required for the "pnpm run preview" command of playwright.config.ts
echo "$FRONTEND_HASH" > "$FRONTEND_HASH_FILE"
fi
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 230-230: Use 'find .. -print0 | xargs -0 ..' or 'find .. -exec .. +' to allow non-alphanumeric filenames.

(SC2038)

Comment on lines +237 to +240
if [[ -n "$QUICK_MODE_ACTIVATED" ]]; then
pnpm playwright test ./tests/functional/"${TEST_PATHS[@]}" --project=chromium "${SCRIPT_LONG_ARGS[@]}" "${SCRIPT_SHORT_ARGS[@]}"
else
npx playwright test ./tests/functional/"${TEST_PATHS[@]}" "${SCRIPT_LONG_ARGS[@]}"
pnpm playwright test ./tests/functional/"${TEST_PATHS[@]}" "${SCRIPT_LONG_ARGS[@]}" "${SCRIPT_SHORT_ARGS[@]}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix array handling in test execution.

The test execution needs to handle arrays properly to avoid word splitting issues.

-if [[ -n "$QUICK_MODE_ACTIVATED" ]]; then
-	pnpm playwright test ./tests/functional/"${TEST_PATHS[@]}" --project=chromium "${SCRIPT_LONG_ARGS[@]}" "${SCRIPT_SHORT_ARGS[@]}"
-else
-	pnpm playwright test ./tests/functional/"${TEST_PATHS[@]}" "${SCRIPT_LONG_ARGS[@]}" "${SCRIPT_SHORT_ARGS[@]}"
+if [[ -n "$QUICK_MODE_ACTIVATED" ]]; then
+	pnpm playwright test ./tests/functional/"${TEST_PATHS[*]}" --project=chromium "${SCRIPT_LONG_ARGS[*]}" "${SCRIPT_SHORT_ARGS[*]}"
+else
+	pnpm playwright test ./tests/functional/"${TEST_PATHS[*]}" "${SCRIPT_LONG_ARGS[*]}" "${SCRIPT_SHORT_ARGS[*]}"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [[ -n "$QUICK_MODE_ACTIVATED" ]]; then
pnpm playwright test ./tests/functional/"${TEST_PATHS[@]}" --project=chromium "${SCRIPT_LONG_ARGS[@]}" "${SCRIPT_SHORT_ARGS[@]}"
else
npx playwright test ./tests/functional/"${TEST_PATHS[@]}" "${SCRIPT_LONG_ARGS[@]}"
pnpm playwright test ./tests/functional/"${TEST_PATHS[@]}" "${SCRIPT_LONG_ARGS[@]}" "${SCRIPT_SHORT_ARGS[@]}"
if [[ -n "$QUICK_MODE_ACTIVATED" ]]; then
pnpm playwright test ./tests/functional/"${TEST_PATHS[*]}" --project=chromium "${SCRIPT_LONG_ARGS[*]}" "${SCRIPT_SHORT_ARGS[*]}"
else
pnpm playwright test ./tests/functional/"${TEST_PATHS[*]}" "${SCRIPT_LONG_ARGS[*]}" "${SCRIPT_SHORT_ARGS[*]}"
🧰 Tools
🪛 Shellcheck (0.10.0)

[error] 238-238: Argument mixes string and array. Use * or separate argument.

(SC2145)


[error] 240-240: Argument mixes string and array. Use * or separate argument.

(SC2145)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
frontend/tests/e2e-tests.sh (3)

53-59: Improve help message formatting consistency.

Consider aligning the option descriptions for better readability.

-  -q                      Quick mode: execute only the tests 1 time with no retries and only 1 project
-  -k                      Keep a saved snapshot of the initial database and use it to avoid executing useless migrations.
+  -q                      Quick mode: execute only the tests 1 time with no retries and only 1 project
+  -k                      Keep a saved snapshot of the initial database and use it to avoid executing
+                          useless migrations

79-80: Strengthen the root user warning.

Consider making this warning more prominent and possibly exiting the script when run as root to prevent potential issues.

 if [[ "$(id -u "$(whoami)")" -eq 0 ]]; then
-  echo "Running this script with a root account is highly discouraged as it can cause bugs with playwright."
+  echo "WARNING: Running this script as root is not recommended!"
+  echo "This can cause permission issues with Playwright and affect test reliability."
+  echo "Please run the script as a non-root user."
+  read -p "Do you want to continue anyway? (y/N) " -n 1 -r
+  echo
+  if [[ ! $REPLY =~ ^[Yy]$ ]]; then
+    exit 1
+  fi
 fi

131-134: Add error handling for database snapshot operations.

Consider adding error handling for the file operations to provide better feedback.

 if [[ -z "$KEEP_DATABASE_SNAPSHOT" && -f "$DB_DIR/$DB_INIT_NAME" ]]; then
-    rm "$DB_DIR/$DB_INIT_NAME"
-    echo "| test initial database snapshot deleted"
+    if rm "$DB_DIR/$DB_INIT_NAME"; then
+        echo "| test initial database snapshot deleted"
+    else
+        echo "| warning: failed to delete test initial database snapshot"
+    fi
 fi
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ab4eee0 and efdb2b7.

📒 Files selected for processing (1)
  • frontend/tests/e2e-tests.sh (8 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
frontend/tests/e2e-tests.sh

[warning] 96-96: Word is of the form "A"B"C" (B indicated). Did you mean "ABC" or "A"B"C"?

(SC2140)


[error] 159-159: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).

(SC2199)


[error] 238-238: Argument mixes string and array. Use * or separate argument.

(SC2145)


[error] 240-240: Argument mixes string and array. Use * or separate argument.

(SC2145)

⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: startup-functional-test (3.12)
  • GitHub Check: startup-docker-compose-test
  • GitHub Check: functional-tests (3.12, chromium)
  • GitHub Check: enterprise-startup-functional-test (3.12)
  • GitHub Check: enterprise-startup-docker-compose-test
  • GitHub Check: enterprise-functional-tests (3.12, chromium)
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
frontend/tests/e2e-tests.sh (4)

2-5: LGTM! Good use of realpath for reliable path resolution.

Using realpath ensures consistent path resolution across different environments.


34-39: LGTM! Well-structured argument handling for new features.

The new flags (-q, -v, -k) provide useful options for:

  • Quick mode execution
  • Backend output visibility
  • Database snapshot management

229-235: LGTM! Properly handling special characters in filenames.

The implementation now correctly handles filenames with spaces and special characters using -print0 and xargs -0.


237-240: Fix array handling in test execution.

The test execution needs to handle arrays properly to avoid word splitting issues.

 if [[ -n "$QUICK_MODE_ACTIVATED" ]]; then
-    pnpm playwright test ./tests/functional/"${TEST_PATHS[@]}" --project=chromium "${SCRIPT_LONG_ARGS[@]}" "${SCRIPT_SHORT_ARGS[@]}"
+    pnpm playwright test ./tests/functional/"${TEST_PATHS[*]}" --project=chromium "${SCRIPT_LONG_ARGS[*]}" "${SCRIPT_SHORT_ARGS[*]}"
 else
-    pnpm playwright test ./tests/functional/"${TEST_PATHS[@]}" "${SCRIPT_LONG_ARGS[@]}" "${SCRIPT_SHORT_ARGS[@]}"
+    pnpm playwright test ./tests/functional/"${TEST_PATHS[*]}" "${SCRIPT_LONG_ARGS[*]}" "${SCRIPT_SHORT_ARGS[*]}"
 fi
🧰 Tools
🪛 Shellcheck (0.10.0)

[error] 238-238: Argument mixes string and array. Use * or separate argument.

(SC2145)


[error] 240-240: Argument mixes string and array. Use * or separate argument.

(SC2145)

Comment on lines +83 to +98
if python3 -c "
import socket
try :
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Using python to check if the port is opened is safer for compatibility
# But it increase the execution time of the script with the timeout
# A local TCP connection should never reach a 1s delay
s.settimeout(1)
s.connect(('127.0.0.1', $BACKEND_PORT))
port_already_in_used = True
except :
port_already_in_used = False
s.close()
# We use "not" because 0 is True and 1 is False in bash
exit(not port_already_in_used)
"; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix socket resource handling in port check.

The socket is not properly closed in case of an exception, which could lead to resource leaks.

 if python3 -c "
 import socket
 try:
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     s.settimeout(1)
     s.connect(('127.0.0.1', $BACKEND_PORT))
     port_already_in_used = True
+    s.close()
 except:
     port_already_in_used = False
-s.close()
+    try:
+        s.close()
+    except:
+        pass
 exit(not port_already_in_used)
 "; then
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if python3 -c "
import socket
try :
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Using python to check if the port is opened is safer for compatibility
# But it increase the execution time of the script with the timeout
# A local TCP connection should never reach a 1s delay
s.settimeout(1)
s.connect(('127.0.0.1', $BACKEND_PORT))
port_already_in_used = True
except :
port_already_in_used = False
s.close()
# We use "not" because 0 is True and 1 is False in bash
exit(not port_already_in_used)
"; then
if python3 -c "
import socket
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Using python to check if the port is opened is safer for compatibility
# But it increase the execution time of the script with the timeout
# A local TCP connection should never reach a 1s delay
s.settimeout(1)
s.connect(('127.0.0.1', $BACKEND_PORT))
port_already_in_used = True
s.close()
except:
port_already_in_used = False
try:
s.close()
except:
pass
exit(not port_already_in_used)
"; then
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 96-96: Word is of the form "A"B"C" (B indicated). Did you mean "ABC" or "A"B"C"?

(SC2140)

Copy link
Collaborator

@Mohamed-Hacene Mohamed-Hacene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0k

@Mohamed-Hacene Mohamed-Hacene merged commit ecfcc44 into main Feb 3, 2025
18 checks passed
@Mohamed-Hacene Mohamed-Hacene deleted the improve/e2e_tests_script branch February 3, 2025 09:44
@github-actions github-actions bot locked and limited conversation to collaborators Feb 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants