Skip to content

Commit

Permalink
fix: Missing test coverage (#2474)
Browse files Browse the repository at this point in the history
* feat: Add unit tests coverage (Legacy PHP API)

* style: Rename coverage_flags to codecov_flags

* fix: Don't send empty reports

* Remove includeUncoveredFiles

* fix: Change paths to `dd-trace-php/...`

* fix: Rename /home/circleci/datadog to dd-trace-php/

* fix: Rename /home/circleci/datadog to ./

* fix: Don't disable xdebug when running coverage !

* fix: syntax

* fix: Use un-compiled files when running in coverage mode

* fix: Use un-compiled files when running in coverage mode

* fix: Use un-compiled files when running in coverage mode

* fix: Use un-compiled files when running in coverage mode

* fix: Don't include uncovered files

* fix: Allow un-compiled runs

* fix: Syntax

* fix: Web Requests Coverage

* fix: Ensure a code coverage ID exists

* tests: Skip some tests under coverage mode

* fix: Don't install symfony/test-pack

* fix: Don't install symfony/test-pack

* Revert --no-dev change

* fix: Handle RoadrunnerServer

* tests: Skip incompatible tests

* tests: Skip incompatible tests

* tests: Skip incompatible tests

* style: Rename tracer-integrations to tracer-php (w/ api)

* tests: Run WordPress Coverage on PHP 8.2

* fix: Add Laravel 8.x `.env` file

* tests: Remove `.env`

* fix: Laravel Tests Failures

* Push `.env` file
  • Loading branch information
PROFeNoM authored Feb 29, 2024
1 parent 40ea21c commit 58c5db3
Show file tree
Hide file tree
Showing 31 changed files with 403 additions and 330 deletions.
159 changes: 94 additions & 65 deletions .circleci/continue_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,30 @@ aliases:
name: Build and install extension
command: make sudo install install_ini BUILD_DIR=$(pwd)/tmp/build_extension

- &STEP_CODE_COVERAGE
when:
# codecov uploader only on amd64
condition:
and:
- equal: [ true, << parameters.coverage >> ]
- matches:
pattern: "^[^.]+$"
value: << parameters.resource_class >>
steps:
- run:
name: Merge coverage reports
command: |
make merge_coverage_reports
- run:
name: Install CodeCov Uploader Dependencies
command: |
sudo apt update
sudo apt install -y gpg
- codecov/upload:
file: reports/coverage.xml
upload_name: "PHP<< parameters.php_major_minor >>.<< parameters.make_target >>.dd-trace-php"
flags: << parameters.codecov_flags >>

- &STEP_COMPOSER_CACHE_RESTORE
restore_cache:
<<: *CACHE_COMPOSER_KEY
Expand Down Expand Up @@ -775,6 +799,12 @@ jobs:
resource_class:
type: string
default: medium
coverage:
type: boolean
default: false
codecov_flags:
type: string
default: ""
working_directory: ~/datadog
<<: *BARE_DOCKER_MACHINE
steps:
Expand Down Expand Up @@ -803,8 +833,10 @@ jobs:
name: Run tests
command: |
set -euo pipefail
<<# parameters.coverage >>unset CI && unset CIRCLECI && export DD_AUTOLOAD_NO_COMPILE=true<</ parameters.coverage >>
make << parameters.make_target >> RUST_DEBUG_BUILD=1 PHPUNIT_OPTS="--log-junit test-results/php-unit/results.xml" 2>&1 | tee /dev/stderr | { ! grep -qe "=== Total [0-9]+ memory leaks detected ==="; }
rm -rf tmp/build_extension/tests/opcache/file_cache/* || true
- <<: *STEP_CODE_COVERAGE
- <<: *STEP_STORE_TEST_RESULTS
- run:
command: |
Expand Down Expand Up @@ -1490,6 +1522,9 @@ jobs:
coverage:
type: boolean
default: false
codecov_flags:
type: string
default: ""
<<: *BARE_DOCKER_MACHINE
environment:
COMPOSER_PROCESS_TIMEOUT: 0
Expand Down Expand Up @@ -1522,35 +1557,21 @@ jobs:
- <<: *STEP_COMPOSER_TESTS_UPDATE
- <<: *STEP_PREPARE_TEST_RESULTS_DIR
- <<: *STEP_EXPORT_CI_ENV
- <<: *STEP_DISABLE_XDEBUG
- when:
condition:
equal: [ false, << parameters.coverage >> ]
steps:
- <<: *STEP_DISABLE_XDEBUG
- <<: *STEP_WAIT_MYSQL
- <<: *STEP_WAIT_REQUEST_REPLAYER
- <<: *STEP_WAIT_TEST_AGENT
- run:
name: Run tests
command: DD_TRACE_AGENT_TIMEOUT=1000 <<# parameters.disable_runner_distributed_tracing >> DD_DISTRIBUTED_TRACING=false <</ parameters.disable_runner_distributed_tracing >> DD_TRACE_TEST_SAPI=<< parameters.sapi >> make << parameters.make_target >> PHPUNIT_OPTS="--log-junit test-results/php-composer/results.xml"
- when:
# codecov uploader only on amd64
condition:
and:
- equal: [ true, << parameters.coverage >> ]
- matches:
pattern: "^[^.]+$"
value: << parameters.resource_class >>
steps:
- run:
name: Merge coverage reports
command: |
make merge_coverage_reports
- run:
name: Install CodeCov Uploader Dependencies
command: |
sudo apt update
sudo apt install -y gpg
- codecov/upload:
file: reports/coverage.xml
upload_name: "PHP<< parameters.php_major_minor >>.<< parameters.make_target >>.dd-trace-php"
flags: tracer-integrations
command: |
set -euo pipefail
<<# parameters.coverage >>unset CI && unset CIRCLECI && export DD_AUTOLOAD_NO_COMPILE=true<</ parameters.coverage >>
DD_TRACE_AGENT_TIMEOUT=1000 <<# parameters.disable_runner_distributed_tracing >> DD_DISTRIBUTED_TRACING=false <</ parameters.disable_runner_distributed_tracing >> DD_TRACE_TEST_SAPI=<< parameters.sapi >> make << parameters.make_target >> PHPUNIT_OPTS="--log-junit test-results/php-composer/results.xml"
- <<: *STEP_CODE_COVERAGE
- run:
command: |
mkdir -p /tmp/artifacts
Expand Down Expand Up @@ -1585,6 +1606,9 @@ jobs:
coverage:
type: boolean
default: false
codecov_flags:
type: string
default: ""
with_executor:
type: string
default: 'with_integrations'
Expand Down Expand Up @@ -1620,39 +1644,25 @@ jobs:
- <<: *STEP_COMPOSER_TESTS_UPDATE
- <<: *STEP_PREPARE_TEST_RESULTS_DIR
- <<: *STEP_EXPORT_CI_ENV
- <<: *STEP_DISABLE_XDEBUG
- when:
condition:
equal: [ "with_integrations", << parameters.with_executor >> ]
steps:
- <<: *STEP_WAIT_MYSQL
condition:
equal: [ false, << parameters.coverage >> ]
steps:
- <<: *STEP_DISABLE_XDEBUG
- when:
condition:
equal: [ "with_integrations", << parameters.with_executor >> ]
steps:
- <<: *STEP_WAIT_MYSQL
- <<: *STEP_WAIT_REQUEST_REPLAYER
- <<: *STEP_WAIT_TEST_AGENT
- run:
name: Run tests
command: DD_TRACE_AGENT_TIMEOUT=1000 <<# parameters.disable_runner_distributed_tracing >> DD_DISTRIBUTED_TRACING=false <</ parameters.disable_runner_distributed_tracing >> DD_TRACE_TEST_SAPI=<< parameters.sapi >> make << parameters.make_target >> RUST_DEBUG_BUILD=1 PHPUNIT_OPTS="--log-junit test-results/php-composer/results.xml"
- when:
# codecov uploader only on amd64
condition:
and:
- equal: [ true, << parameters.coverage >> ]
- matches:
pattern: "^[^.]+$"
value: << parameters.resource_class >>
steps:
- run:
name: Merge coverage reports
command: |
make merge_coverage_reports
- run:
name: Install CodeCov Uploader Dependencies
command: |
sudo apt update
sudo apt install -y gpg
- codecov/upload:
file: reports/coverage.xml
upload_name: "PHP<< parameters.php_major_minor >>.<< parameters.make_target >>.dd-trace-php"
flags: tracer-integrations
command: |
set -euo pipefail
<<# parameters.coverage >>unset CI && unset CIRCLECI && export DD_AUTOLOAD_NO_COMPILE=true<</ parameters.coverage >>
DD_TRACE_AGENT_TIMEOUT=1000 <<# parameters.disable_runner_distributed_tracing >> DD_DISTRIBUTED_TRACING=false <</ parameters.disable_runner_distributed_tracing >> DD_TRACE_TEST_SAPI=<< parameters.sapi >> make << parameters.make_target >> RUST_DEBUG_BUILD=1 PHPUNIT_OPTS="--log-junit test-results/php-composer/results.xml"
- <<: *STEP_CODE_COVERAGE
- run:
command: |
mkdir -p /tmp/artifacts
Expand Down Expand Up @@ -4418,6 +4428,18 @@ workflows:
- test_internal_api_randomized
- test_opcache

- test:
requires: [ 'Prepare Code' ]
coverage: true
codecov_flags: tracer-php
matrix:
parameters:
php_major_minor:
- "7.4"
- "8.2"
make_target:
- test_unit_coverage

- test:
requires: [ 'Prepare Code' ]
matrix:
Expand Down Expand Up @@ -4530,29 +4552,30 @@ workflows:
- '7.1'
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
make_target:
- test_auto_instrumentation
- test_composer
- test_integration
- test_distributed_tracing
- test_auto_instrumentation
- test_integration

- integration:
requires: [ 'Prepare Code' ]
resource_class: medium+
coverage: true
codecov_flags: tracer-php
matrix:
parameters:
php_major_minor:
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
make_target:
- test_composer_coverage
- test_integration_coverage
- test_distributed_tracing_coverage
- test_auto_instrumentation_coverage

- integration_snapshots:
requires: [ 'Prepare Code' ]
Expand All @@ -4565,6 +4588,11 @@ workflows:
- '7.1'
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
make_target:
- test_web
- test_integrations
Expand All @@ -4574,14 +4602,12 @@ workflows:
# Due to Symfony OOM during composer update
resource_class: xlarge
coverage: true
codecov_flags: tracer-php
matrix:
parameters:
php_major_minor:
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
make_target:
- test_web_coverage
- test_integrations_coverage
Expand All @@ -4599,6 +4625,11 @@ workflows:
- '7.1'
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
make_target:
- test_distributed_tracing

Expand Down Expand Up @@ -4629,15 +4660,13 @@ workflows:
sapi: fpm-fcgi
disable_runner_distributed_tracing: true
coverage: true
codecov_flags: tracer-php
with_executor: 'with_httpbin_and_request_replayer'
matrix:
parameters:
php_major_minor:
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
make_target:
- test_distributed_tracing_coverage

Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,8 @@ test: global_test_run_dependencies

test_unit: global_test_run_dependencies
$(call run_tests,--testsuite=unit $(TESTS))
test_unit_coverage: global_test_run_dependencies
PHPUNIT_COVERAGE=1 $(MAKE) test_unit

test_integration: global_test_run_dependencies
$(call run_tests,--testsuite=integration $(TESTS))
Expand Down Expand Up @@ -1282,7 +1284,7 @@ test_web_symfony_34: global_test_run_dependencies
test_web_symfony_40: global_test_run_dependencies
# We hit broken updates in this unmaintained version, so we committed a
# working composer.lock and we composer install instead of composer update
$(COMPOSER) --working-dir=tests/Frameworks/Symfony/Version_4_0 install
$(COMPOSER) --working-dir=tests/Frameworks/Symfony/Version_4_0 install --no-dev
php tests/Frameworks/Symfony/Version_4_0/bin/console cache:clear --no-warmup --env=prod
$(call run_tests_debug,tests/Integrations/Symfony/V4_0)
test_web_symfony_42: global_test_run_dependencies
Expand Down Expand Up @@ -1348,7 +1350,7 @@ test_scenario_%:
$(Q) $(COMPOSER_TESTS) scenario $*

merge_coverage_reports:
$(PHPCOV) merge --clover reports/coverage.xml reports/cov
php -d memory_limit=-1 $(PHPCOV) merge --clover reports/coverage.xml reports/cov

### Api tests ###
API_TESTS_ROOT := ./tests/api
Expand Down
2 changes: 1 addition & 1 deletion ext/request_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void dd_request_init_hook_rinit(void) {

PG(auto_prepend_file) = ZSTR_VAL(hook_path);
if (DDTRACE_G(auto_prepend_file) && DDTRACE_G(auto_prepend_file)[0]) {
LOG(WARN, "Backing up auto_prepend_file '%s'", DDTRACE_G(auto_prepend_file));
LOG(INFO, "Backing up auto_prepend_file '%s'", DDTRACE_G(auto_prepend_file));
}
}

Expand Down
Loading

0 comments on commit 58c5db3

Please sign in to comment.