Skip to content

Conversation

@aaronweeden
Copy link
Contributor

@aaronweeden aaronweeden commented Aug 24, 2023

Description

This PR refactors some of the existing integration tests (a further refactoring from #1706) to make integration tests easier to write and maintain. Specifically, it moves test data out of JSON test artifact files and into PHP associative arrays in the integration test code. This makes the test data simpler for developers to find, read, write, reuse, and debug, and it also speeds up the validation.

This PR also changes the API token authentication tests to only run for a single public user and a single non-public user, resulting in the integration test framework finishing faster.

Motivation and Context

There are many integration tests that involve making HTTP requests to an endpoint and validating the JSON response. This PR organizes similar code into functions to avoid repetition.

This PR serves as a base for #1788, #1765, ubccr/xdmod-appkernels#95, and ubccr/xdmod-supremm#350.

Tests performed

In a Docker container, as I refactored tests, I manually changed the covered code to make sure the test still tests that code.

Also, in a Docker container running tools-ext-01.ccr.xdmod.org/xdmod-10.5.0-x86_64:rockylinux8.5-0.3:

  1. Run the following commands:
    export COMPOSER_ALLOW_SUPERUSER=1
    export XDMOD_REALMS='jobs,storage,cloud'
    export XDMOD_IS_CORE=yes
    export XDMOD_INSTALL_DIR=/xdmod
    export XDMOD_TEST_MODE=upgrade
    openssl genrsa -rand /proc/cpuinfo:/proc/dma:/proc/filesystems:/proc/interrupts:/proc/ioports:/proc/uptime 2048 > /etc/pki/tls/private/localhost.key
    /usr/bin/openssl req -new -key /etc/pki/tls/private/localhost.key -x509 -sha256 -days 365 -set_serial $RANDOM -extensions v3_req -out /etc/pki/tls/certs/localhost.crt -subj "/C=XX/L=Default City/O=Default Company Ltd"
    git clone {https://github.com/ubccr,}/xdmod
    cd /xdmod
    composer install
    mkdir ~/phpunit
    mkdir /tmp/screenshots
    ~/bin/buildrpm xdmod
    ./tests/ci/bootstrap.sh
    ./tests/ci/validate.sh
    composer install --no-progress
    mv ./configuration/organization.json ./configuration/organization.json.old
    mv ./configuration/portal_settings.ini ./configuration/portal_settings.ini.old
    cp /etc/xdmod/portal_settings.ini ./configuration/portal_settings.ini
    cp /etc/xdmod/organization.json ./configuration/organization.json
    ./tests/ci/scripts/qa-test-setup.sh
    sed -i 's/\$phpunit /$phpunit --debug /' /xdmod/tests/unit/runtests.sh
    /xdmod/tests/unit/runtests.sh > /unit-before.txt
    sed -i 's/\$phpunit /$phpunit --debug /' /xdmod/tests/component/runtests.sh
    /xdmod/tests/component/runtests.sh > /component-before.txt
    sed -i 's/\$phpunit /$phpunit --debug /' /xdmod/tests/regression/runtests.sh
    /xdmod/tests/regression/runtests.sh > /regression-before.txt
    cd /xdmod/tests/integration
    ../../vendor/bin/phpunit --testsuite default --group UserAdminTest.createUsers --debug > /integration-before.txt
    ../../vendor/bin/phpunit --testsuite default --exclude-group UserAdminTest.createUsers --debug >> /integration-before.txt
    git clone https://github.com/aaronweeden/xdmod -b refactor-integration-tests /xdmod-new
    unalias rm
    rm -r /xdmod/tests/integration/lib
    cp -r /xdmod{-new,}/tests/integration/lib
    /xdmod/tests/unit/runtests.sh > /unit-after.txt
    /xdmod/tests/component/runtests.sh > /component-after.txt
    /xdmod/tests/regression/runtests.sh > /regression-after.txt
    cd /xdmod/tests/integration
    ../../vendor/bin/phpunit --testsuite default --group UserAdminTest.createUsers --debug > /integration-after.txt
    ../../vendor/bin/phpunit --testsuite default --exclude-group UserAdminTest.createUsers --debug >> /integration-after.txt
    unalias mv
    for file in /regression-{before,after}.txt; do
        for test in {testChartSettings,testChartFilters,testCsvExport}; do
            for realm in {Jobs,Cloud,Storage}; do
                sed -i "s/$test with data set.*$realm.*/$test $realm/" $file;
            done;
        done;
        sort $file > $file.tmp;
        mv $file.tmp $file;
    done
    
  2. Compare /unit-{before,after}.txt and make sure the only differences are user hashes and amount of time the tests ran.
  3. Compare /component-{before,after}.txt and make sure the only differences are test name hashes and amount of time the tests ran.
  4. Compare /regression-{before,after}.txt and make sure the only differences are the progress dots at the top and the amount of time the tests ran.
  5. Compare /integration-{before,after}.txt and make sure the differences are correct:
    1. First set of tests: 497 assertions -> 2972 assertions.
    2. Different random values for ControllerTest::testEnumTargetAddresses.
    3. In /integration-after.txt, only usr tests for:
      • MetricExplorerTest::testGetDwDescripterTokenAuth.
      • MetricExplorerTest::testGetDimensionFilters — and also a single valid_token test each for cd, cs, usr, pi, and mgr.
      • UsageExplorerTest::testGetDataTokenAuth.
      • WarehouseControllerProviderTest::testGetRawData.
      • WarehouseControllerProviderTest::testGetRawDataLimit.
      • WarehouseExportControllerProviderTest::testGetRealmsTokenAuth.
    4. Different test arguments for UserControllerProviderTest::testGetCurrentUser and WarehouseControllerProviderTest::testGetRawData.
    5. Last group of tests takes about 30 sec less, ~60 fewer MB, 813 tests -> 722 tests, 6469 assertions -> 570956 assertions.

Checklist:

  • The pull request description is suitable for a Changelog entry
  • The milestone is set correctly on the pull request
  • The appropriate labels have been added to the pull request

@aaronweeden aaronweeden added qa / testing Updates/additions to tests maintenance / code quality Improvements and code cleanup. Not a new feature or enhancement to existing functionality. labels Aug 24, 2023
@aaronweeden aaronweeden added this to the 11.0.0 milestone Aug 24, 2023
@aaronweeden aaronweeden changed the title Refactor some of the integration tests Add and refactor some integration tests Aug 29, 2023
@aaronweeden aaronweeden changed the title Add and refactor some integration tests Refactor some of the integration tests. Aug 30, 2023
@aaronweeden aaronweeden force-pushed the refactor-integration-tests branch from 3cae043 to e5f2cc6 Compare September 8, 2023 18:40
@aaronweeden aaronweeden force-pushed the refactor-integration-tests branch from e07ef18 to 546405f Compare September 27, 2023 18:46
@aaronweeden aaronweeden changed the base branch from xdmod10.5 to xdmod11.0 October 5, 2023 19:31
@aaronweeden aaronweeden force-pushed the refactor-integration-tests branch from 546405f to dd4bc45 Compare October 5, 2023 19:35
@aaronweeden aaronweeden marked this pull request as ready for review October 6, 2023 00:08
@aaronweeden aaronweeden force-pushed the refactor-integration-tests branch 4 times, most recently from 92512b3 to 7a34c66 Compare October 12, 2023 21:33
@aaronweeden aaronweeden mentioned this pull request Oct 12, 2023
3 tasks
@aaronweeden aaronweeden force-pushed the refactor-integration-tests branch from 7a34c66 to 875a49b Compare October 19, 2023 13:13
Copy link
Contributor

@ryanrath ryanrath left a comment

Choose a reason for hiding this comment

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

Alrighty, just some comments with no actual show stoppers. It's mainly documentation & naming related w/ a sprinkling of possible gotchas ( some Exception namespace stuff ).

@aaronweeden aaronweeden force-pushed the refactor-integration-tests branch 2 times, most recently from 153ab61 to 345670f Compare November 7, 2023 14:11
@aaronweeden aaronweeden requested a review from ryanrath November 7, 2023 14:26
@ryanrath
Copy link
Contributor

ryanrath commented Nov 7, 2023

Lemme know what you think about the expireToken function suggestions and then just re-request the review and I'll go ahead and approve.

@aaronweeden aaronweeden force-pushed the refactor-integration-tests branch from 345670f to 653bb85 Compare November 7, 2023 20:09
@aaronweeden aaronweeden merged commit 93991f9 into ubccr:xdmod11.0 Nov 7, 2023
@aaronweeden aaronweeden deleted the refactor-integration-tests branch November 7, 2023 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance / code quality Improvements and code cleanup. Not a new feature or enhancement to existing functionality. qa / testing Updates/additions to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants