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

refactor: run integration tests outside LMS container #4

Merged
merged 34 commits into from
Oct 3, 2024

Conversation

magajh
Copy link
Contributor

@magajh magajh commented Sep 16, 2024

Overview

This PR introduces significant modifications to the GitHub Action for testing Open edX plugins in the Tutor environment. These changes are necessary for improving the effectiveness and reliability of our integration tests

Motivation for Changes

The initial implementation ran integration tests inside the LMS container of Tutor. This approach created several challenges:

  • Networking Issues: Running tests inside the same container restricted the ability to make requests to external hosts, leading to unreliable test outcomes.
  • Realistic Testing: To ensure that our integration tests reflect real-world interactions between our plugins and the Open edX platform, it is crucial to run them outside the Tutor container, maintaining a separation between the tests and the platform environment.

To address these issues, this PR modifies the workflow to run integration tests outside the Tutor container, improving the testing environment and results.

Workflow Steps and Their Necessity

  1. Set Tutor Environment Variables:

    • Sets necessary environment variables such as LMS_HOST, CMS_HOST, TUTOR_ROOT, and TUTOR_PLUGINS_ROOT for proper Tutor configuration.
  2. Install and Prepare Tutor:

    • Installs the specified version of Tutor or clones the nightly branch if tutor_version is set to "nightly".
    • Configures Tutor with the necessary host settings and launches it in non-interactive mode.
  3. Configure Caddyfile and Open edX Settings:

    • Moved patches.yml into the action directory and copies it into the plugins directory during the workflow.
    • Enables the patches plugin to customize the Caddyfile and Open edX production settings. This configuration allows for the necessary routing for testing with multiple sites and security settings for our tests.
  4. Add Mount for Plugin:

    • Mounts the plugin directory into the LMS and CMS containers, ensuring that the plugin code is accessible within the Tutor environment.
  5. Restart Tutor Services:

    • Restarts Tutor services to apply the new mounts and configurations.
  6. Install Plugin and Extra Requirements:

    • Installs the plugin in editable mode within the LMS container.
    • Installs any additional pip requirements specified in openedx_extra_pip_requirements in both LMS and CMS containers.
  7. Run Migrations:

    • Executes database migrations for both the LMS and CMS to ensure the database schema is up-to-date.
  8. Import Demo Course:

    • Imports the Open edX demo course for testing purposes.
  9. Set DEMO_COURSE_ID Environment Variable:

  • Sets the DEMO_COURSE_ID environment variable based on the Tutor version.
  • Purpose: Allows tests to refer to the demo course ID when running integration tests.
  1. Test Open edX Imports in Plugin (Optional):
  • Provides a mechanism to verify that all imports from the Open edX platform in the plugin are working correctly.
  • Executes the test function specified by openedx_imports_test_file_path and openedx_imports_test_function_name, ensuring that the plugin's imports from Open edX do not have any issues.
  1. Load Initial Data for the Tests (Optional):

    • Loads initial data from a fixtures file into the LMS if fixtures_file is provided.
  2. Curl Heartbeat:

    • Verifies that the LMS is running and responsive by checking the heartbeat endpoint.
  3. Run Integration Tests:

    • Creates a virtual environment and runs the specified shell script to execute the integration tests outside the Tutor container, improving test reliability.

Personalization Options

The workflow includes several inputs that can be customized:

  • app_name: The name of the application to test (e.g., eox-core).
  • tutor_version: The version of Tutor to use, allowing for testing against specific versions or the nightly build.
  • shell_file_to_run: The path to the shell script that contains the integration tests.
  • openedx_extra_pip_requirements: Optional additional dependencies needed for testing.
  • fixtures_file: Optional path to a JSON file containing initial data to load for the tests.
  • openedx_imports_test_file_path: Optional path to the Python file containing the import test function.
  • openedx_imports_test_function_name: Optional name of the function to execute in the import test file.

Testing the Workflow

To test this workflow:

  1. Create a Branch:

    • Create a branch from any of the EOX plugins that includes integration tests. For example, you can use the branch bav/add-integration-tests in eox-core, which includes several integration tests.
  2. Add Integration Test Script:

    • Include a shell script (e.g., integration.sh) in your plugin that installs dependencies and runs the tests.

      #!/bin/bash
      
      echo "Installing test requirements"
      make install-dev-dependencies
      
      echo "Running integration tests"
      pytest eox_core/api/v1/tests/integration/test_views.py
  3. Configure the Workflow:

    • Update your workflow file to use the updated action and specify the required inputs.

      name: Tutor Integration Tests
      on: [pull_request]
      
      jobs:
        integration-test:
          name: Tutor Integration Tests
          runs-on: ubuntu-latest
          strategy:
            matrix:
              tutor_version: ['<18.0.0', '==17.0.3', 'nightly']
          steps:
            - name: Run Integration Tests
              uses: eduNEXT/integration-test-in-tutor@v1
              with:
                tutor_version: ${{ matrix.tutor_version }}
                app_name: 'eox-core'
                shell_file_to_run: 'scripts/integration.sh'
                openedx_extra_pip_requirements: 'eox-tenant'
                fixtures_file: 'fixtures/initial_data.json'
                openedx_imports_test_file_path: 'eox_core/edxapp_wrapper/tests/integration/test_backends.py'
                openedx_imports_test_function_name: 'test_current_settings_code_imports'
  4. Verify the Tests Run Successfully:

Additional Notes

  • Supporting Tutor Nightly:

    • The action now supports running tests against the nightly version of Tutor, enabling early detection of compatibility issues with upcoming changes.
  • Improved Documentation:

    • The README has been updated to reflect the latest changes, including detailed input descriptions, usage examples, and special notes on using the nightly version.

@magajh magajh changed the title Mjh/run integration tests outside container refactor: run integration tests outside LMS container Sep 16, 2024
@magajh magajh force-pushed the mjh/run-integration-tests-outside-container branch 7 times, most recently from 43ba8c0 to 89cac69 Compare September 17, 2024 00:04
@magajh magajh force-pushed the mjh/run-integration-tests-outside-container branch from 60e82aa to a016821 Compare September 17, 2024 12:46
@magajh magajh requested a review from a team September 17, 2024 12:48
@magajh
Copy link
Contributor Author

magajh commented Sep 17, 2024

Note to reviewers: I'm working on updating the README

Copy link
Contributor

@BryanttV BryanttV left a comment

Choose a reason for hiding this comment

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

@magajh, This looks great! thank you!

Just to note, when adding these changes we must modify all eox's that use this action, as the commands in your scripts will not work.

action.yml Outdated Show resolved Hide resolved
action.yml Outdated Show resolved Hide resolved
action.yml Outdated Show resolved Hide resolved
action.yml Outdated Show resolved Hide resolved
action.yml Outdated Show resolved Hide resolved
@magajh
Copy link
Contributor Author

magajh commented Oct 1, 2024

@mariajgrimaldi @BryanttV: thank you for your valuable feedback! I've addressed all the comments and this is ready for review again. I think the only pending discussion that we have is #4 (comment)

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated
Comment on lines 74 to 84
### `openedx_imports_test_file_path`

**Optional**
The path to the Python file in your plugin that contains the test function for validating Open edX imports. This path is relative to your plugin directory.
*Example*: `"tests/import_tests.py"`

### `openedx_imports_test_function_name`

**Optional**
The name of the function in the specified file that executes the import tests for Open edX.
*Example*: `"test_openedx_imports"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @magajh. I agree with Majo's question. Also, do you happen to have any log for the jobs that shows what it looks like when some backend fails?

run_openedx_imports_test.py Outdated Show resolved Hide resolved
@magajh magajh force-pushed the mjh/run-integration-tests-outside-container branch 2 times, most recently from c7e49bf to aba7551 Compare October 1, 2024 21:26
@magajh magajh force-pushed the mjh/run-integration-tests-outside-container branch from 86bec38 to 935eafe Compare October 2, 2024 19:54
@magajh magajh force-pushed the mjh/run-integration-tests-outside-container branch from 444dfbc to b27df97 Compare October 3, 2024 13:57
@magajh magajh requested a review from BryanttV October 3, 2024 13:59
Copy link
Contributor

@BryanttV BryanttV left a comment

Choose a reason for hiding this comment

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

This looks great! Thank you very much for addressing our comments!

Copy link

@mariajgrimaldi mariajgrimaldi left a comment

Choose a reason for hiding this comment

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

Thank you so much!

@magajh magajh merged commit 769e464 into main Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants