diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 154c6e497..f59fb910b 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -94,8 +94,57 @@ jobs: cat config/config.php ./occ user:list ./occ app:enable --force ${{ env.APP_NAME }} + ./occ config:system:set query_log_file --value '/home/runner/work/${{ env.APP_NAME }}/${{ env.APP_NAME }}/query.log' php -S localhost:8080 & - name: Run behat working-directory: apps/${{ env.APP_NAME }}/tests/integration run: ./run.sh + + - name: Query count + if: ${{ matrix.databases == 'mysql' }} + uses: actions/github-script@v5 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + let myOutput = '' + let myError = '' + + const options = {} + options.listeners = { + stdout: (data) => { + myOutput += data.toString() + }, + stderr: (data) => { + myError += data.toString() + } + } + await exec.exec(`/bin/bash -c "cat /home/runner/work/${{ env.APP_NAME }}/${{ env.APP_NAME }}/query.log | wc -l"`, [], options) + msg = myOutput + const queryCount = parseInt(myOutput, 10) + + myOutput = '' + await exec.exec('cat', ['/home/runner/work/${{ env.APP_NAME }}/${{ env.APP_NAME }}/apps/${{ env.APP_NAME }}/tests/integration/base-query-count.txt'], options) + const baseCount = parseInt(myOutput, 10) + + const absoluteIncrease = queryCount - baseCount + const relativeIncrease = baseCount <= 0 ? 100 : (parseInt((absoluteIncrease / baseCount * 10000), 10) / 100) + + if (absoluteIncrease >= 100 || relativeIncrease > 5) { + const comment = `🐢 Performance warning.\nIt looks like the query count of the integration tests increased with this PR.\nDatabase query count is now ` + queryCount + ' was ' + baseCount + ' (+' + relativeIncrease + '%)\nPlease check your code again. If you added a new test this can be expected and the base value in tests/integration/base-query-count.txt can be increased.' + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: comment + }) + } + if (queryCount < 100) { + const comment = `🐈 Performance messuring seems broken. Failed to get query count.` + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: comment + }) + } \ No newline at end of file diff --git a/tests/integration/base-query-count.txt b/tests/integration/base-query-count.txt new file mode 100644 index 000000000..bd7d9524a --- /dev/null +++ b/tests/integration/base-query-count.txt @@ -0,0 +1 @@ +61324 diff --git a/tests/integration/features/bootstrap/ServerContext.php b/tests/integration/features/bootstrap/ServerContext.php index 6880f764c..f7c192384 100644 --- a/tests/integration/features/bootstrap/ServerContext.php +++ b/tests/integration/features/bootstrap/ServerContext.php @@ -40,7 +40,6 @@ class ServerContext implements Context { } public function getCookieJar(): CookieJar { - echo $this->currentUser; return $this->cookieJar; } diff --git a/tests/integration/run.sh b/tests/integration/run.sh index bcabf9ed7..1dfe35b70 100755 --- a/tests/integration/run.sh +++ b/tests/integration/run.sh @@ -27,16 +27,16 @@ if [ -z "$EXECUTOR_NUMBER" ]; then fi PORT=$((9090 + $EXECUTOR_NUMBER)) echo $PORT -php -S localhost:$PORT -t $OC_PATH & +php -q -S localhost:$PORT -t $OC_PATH & PHPPID=$! echo $PHPPID export TEST_SERVER_URL="http://localhost:$PORT/ocs/" -vendor/bin/behat $SCENARIO_TO_RUN +vendor/bin/behat --colors $SCENARIO_TO_RUN RESULT=$? -kill $PHPPID +kill -9 $PHPPID echo "runsh: Exit code: $RESULT" exit $RESULT