From bfbeb7b1fb26515c88152a1a3b41d17b6e9395de Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 27 Aug 2022 09:36:37 +0200 Subject: [PATCH] Improved run-api-tests.sh script to make it compatible with sh --- .github/workflows/ci-tests.yml | 1 - .github/workflows/ci.yml | 1 - bin/test/run-api-tests.sh | 35 +++++++++++++++++++++------------- config/config.php | 3 ++- indocker | 7 +------ 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 3f3915c3..b7f7af98 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -28,7 +28,6 @@ jobs: php-extensions: openswoole-4.11.1 extensions-cache-key: tests-extensions-${{ matrix.php-version }}-${{ inputs.test-group }} - run: composer test:${{ inputs.test-group }}:ci - shell: bash - uses: actions/upload-artifact@v3 if: ${{ matrix.php-version == '8.1' }} with: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 857dbf59..709c9834 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,7 +49,6 @@ jobs: - run: composer install --no-interaction --prefer-dist - run: ./vendor/bin/rr get --location bin/ && chmod +x bin/rr - run: composer test:api:rr - shell: bash cli-tests: uses: './.github/workflows/ci-tests.yml' diff --git a/bin/test/run-api-tests.sh b/bin/test/run-api-tests.sh index 1f61b681..24652cb7 100755 --- a/bin/test/run-api-tests.sh +++ b/bin/test/run-api-tests.sh @@ -12,26 +12,35 @@ mkdir data/log/api-tests touch $OUTPUT_LOGS # Try to stop server just in case it hanged in last execution -[[ $TEST_RUNTIME == 'openswoole' ]] && vendor/bin/laminas mezzio:swoole:stop -[[ $TEST_RUNTIME == 'rr' ]] && bin/rr stop -f +if test "$TEST_RUNTIME" == 'openswoole'; then + vendor/bin/laminas mezzio:swoole:stop +elif test "$TEST_RUNTIME" == 'rr'; then + bin/rr stop -f +fi echo 'Starting server...' -[[ $TEST_RUNTIME == 'openswoole' ]] && vendor/bin/laminas mezzio:swoole:start -d -[[ $TEST_RUNTIME == 'rr' ]] && bin/rr serve -p -c=config/roadrunner/.rr.dev.yml \ - -o=http.address=0.0.0.0:9999 \ - -o=logs.encoding=json \ - -o=logs.channels.http.encoding=json \ - -o=logs.channels.server.encoding=json \ - -o=logs.output="${PWD}/${OUTPUT_LOGS}" \ - -o=logs.channels.http.output="${PWD}/${OUTPUT_LOGS}" \ - -o=logs.channels.server.output="${PWD}/${OUTPUT_LOGS}" & +if test "$TEST_RUNTIME" == 'openswoole'; then + vendor/bin/laminas mezzio:swoole:start -d +elif test "$TEST_RUNTIME" == 'rr'; then + bin/rr serve -p -c=config/roadrunner/.rr.dev.yml \ + -o=http.address=0.0.0.0:9999 \ + -o=logs.encoding=json \ + -o=logs.channels.http.encoding=json \ + -o=logs.channels.server.encoding=json \ + -o=logs.output="${PWD}/${OUTPUT_LOGS}" \ + -o=logs.channels.http.output="${PWD}/${OUTPUT_LOGS}" \ + -o=logs.channels.server.output="${PWD}/${OUTPUT_LOGS}" & +fi sleep 2 # Let's give the server a couple of seconds to start vendor/bin/phpunit --order-by=random -c phpunit-api.xml --testdox --colors=always --log-junit=build/coverage-api/junit.xml $* testsExitCode=$? -[[ $TEST_RUNTIME == 'openswoole' ]] && vendor/bin/laminas mezzio:swoole:stop -[[ $TEST_RUNTIME == 'rr' ]] && bin/rr stop -c config/roadrunner/.rr.dev.yml -o=http.address=0.0.0.0:9999 +if test "$TEST_RUNTIME" == 'openswoole'; then + vendor/bin/laminas mezzio:swoole:stop +elif test "$TEST_RUNTIME" == 'rr'; then + bin/rr stop -c config/roadrunner/.rr.dev.yml -o=http.address=0.0.0.0:9999 +fi # Exit this script with the same code as the tests. If tests failed, this script has to fail exit $testsExitCode diff --git a/config/config.php b/config/config.php index 2763d23d..cacf9bcd 100644 --- a/config/config.php +++ b/config/config.php @@ -17,8 +17,9 @@ use function Shlinkio\Shlink\Config\swooleIsInstalled; use const PHP_SAPI; -$enableSwoole = PHP_SAPI === 'cli' && swooleIsInstalled(); $isTestEnv = env('APP_ENV') === 'test'; +$isRR = env('RR_MODE') !== null; +$enableSwoole = PHP_SAPI === 'cli' && ! $isRR && swooleIsInstalled(); return (new ConfigAggregator\ConfigAggregator([ ! $isTestEnv diff --git a/indocker b/indocker index 3dde53c4..03061e2f 100755 --- a/indocker +++ b/indocker @@ -5,9 +5,4 @@ if ! [[ $(docker ps | grep shlink) ]]; then docker-compose up -d fi -if [[ "$*" == *"test:api:rr"* ]]; then - # API tests should be run inside the RoadRunner container when the test runtime is RoadRunner - docker exec -it shlink_roadrunner /bin/sh -c "$*" -else - docker exec -it shlink_swoole /bin/sh -c "$*" -fi +docker exec -it shlink_swoole /bin/sh -c "$*"