Skip to content

Commit fac7766

Browse files
chore(ci): coverage and integration test fix [backport #5502, #5521, #5583 to 1.11] (#5634)
This PR backports #5583, #5521, and #5502 to 1.11. This PR fixes the bash conditional on our `run_test` pipeline jobs so that when a pipeline is manually triggered with `coverage=true` on CircleCI, coverage reporting is enabled. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/contributing.html#Release-Note-Guidelines) are followed. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] PR description includes explicit acknowledgement/acceptance of the performance implications of this PR as reported in the benchmarks PR comment. ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. --------- Co-authored-by: Brett Langdon <[email protected]>
1 parent e898ade commit fac7766

File tree

4 files changed

+96
-72
lines changed

4 files changed

+96
-72
lines changed

.circleci/config.yml

Lines changed: 56 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ httpbin_image: &httpbin_image kennethreitz/httpbin@sha256:2c7abc4803080c22928265
1616
vertica_image: &vertica_image sumitchawla/vertica:latest
1717
rabbitmq_image: &rabbitmq_image rabbitmq:3.7-alpine
1818

19+
parameters:
20+
coverage:
21+
type: boolean
22+
default: false
23+
1924
orbs:
2025
win: circleci/[email protected]
2126

@@ -160,10 +165,9 @@ commands:
160165
- run:
161166
environment:
162167
DD_TRACE_AGENT_URL: http://localhost:9126
163-
164168
command: |
165169
mv .riot .ddriot
166-
riot list --hash-only '<<parameters.pattern>>' | shuf | circleci tests split | xargs -n 1 ./scripts/ddtest riot -v run --exitfirst --pass-env -s
170+
riot list --hash-only '<<parameters.pattern>>' | shuf | circleci tests split | xargs -n 1 -I {} ./scripts/ddtest riot -v run --exitfirst --pass-env -s {} $([[ << pipeline.parameters.coverage >> == false ]] && echo '--no-cov' )
167171
- unless:
168172
condition:
169173
<< parameters.snapshot >>
@@ -176,38 +180,22 @@ commands:
176180
- run:
177181
name: "Waiting for << parameters.wait >>"
178182
command: riot -v run 'wait' << parameters.wait >>
179-
180183
- run:
181-
command: "riot list --hash-only '<<parameters.pattern>>' | shuf | circleci tests split | xargs -n 1 riot -v run --exitfirst --pass-env -s"
184+
command: |
185+
riot list --hash-only '<<parameters.pattern>>' | shuf | circleci tests split | xargs -n 1 -I {} riot -v run --exitfirst --pass-env -s {} $([[ << pipeline.parameters.coverage >> == false ]] && echo '--no-cov' )
182186
- save_pip_cache
183187
- when:
184188
condition:
185-
<< parameters.store_coverage >>
189+
and:
190+
- << pipeline.parameters.coverage >>
191+
- << parameters.store_coverage >>
186192
steps:
187193
- save_coverage
188194
- store_test_results:
189195
path: test-results
190196
- store_artifacts:
191197
path: test-results
192198

193-
run_tox_scenario_with_testagent:
194-
description: Run scripts/run-tox-scenario with setup, caching persistence and the testagent
195-
parameters:
196-
pattern:
197-
type: string
198-
steps:
199-
- checkout
200-
- restore_tox_cache
201-
- start_docker_services:
202-
env: SNAPSHOT_CI=1
203-
services: memcached redis testagent
204-
- run:
205-
name: "Run scripts/run-tox-scenario"
206-
environment:
207-
DD_TRACE_AGENT_URL: http://localhost:9126
208-
command: ./scripts/ddtest scripts/run-tox-scenario '<< parameters.pattern >>'
209-
- save_tox_cache
210-
211199
run_tox_scenario:
212200
description: "Run scripts/run-tox-scenario with setup, caching and persistence"
213201
parameters:
@@ -224,11 +212,6 @@ commands:
224212
name: "Run scripts/run-tox-scenario"
225213
command: scripts/run-tox-scenario '<< parameters.pattern >>'
226214
- save_tox_cache
227-
- when:
228-
condition:
229-
<< parameters.store_coverage >>
230-
steps:
231-
- save_coverage
232215
- store_test_results:
233216
path: test-results
234217
- store_artifacts:
@@ -317,34 +300,44 @@ jobs:
317300
coverage_report:
318301
executor: python310
319302
steps:
320-
- checkout
321-
- attach_workspace:
322-
at: .
323-
- run: pip install coverage codecov diff_cover
324-
- run: ls -hal *.coverage
325-
# Combine all job coverage reports into one
326-
- run: coverage combine *.coverage
327-
# Upload coverage report to Codecov
328-
# DEV: Do not use the bash uploader, it cannot be trusted
329-
- run: codecov
330-
# Generate and save xml report
331-
# DEV: "--ignore-errors" to skip over files that are missing
332-
- run: coverage xml --ignore-errors
333-
- store_artifacts:
334-
path: coverage.xml
335-
# Generate and save JSON report
336-
# DEV: "--ignore-errors" to skip over files that are missing
337-
- run: coverage json --ignore-errors
338-
- store_artifacts:
339-
path: coverage.json
340-
# Print ddtrace/ report to stdout
341-
# DEV: "--ignore-errors" to skip over files that are missing
342-
- run: coverage report --ignore-errors --omit=tests/
343-
# Print tests/ report to stdout
344-
# DEV: "--ignore-errors" to skip over files that are missing
345-
- run: coverage report --ignore-errors --omit=ddtrace/
346-
# Print diff-cover report to stdout (compares against origin/1.x)
347-
- run: diff-cover --compare-branch $(git rev-parse --abbrev-ref origin/HEAD) coverage.xml
303+
- when:
304+
condition:
305+
<< pipeline.parameters.coverage >>
306+
steps:
307+
- checkout
308+
- attach_workspace:
309+
at: .
310+
- run: pip install coverage codecov diff_cover
311+
- run: ls -hal *.coverage
312+
# Combine all job coverage reports into one
313+
- run: coverage combine *.coverage
314+
# Upload coverage report to Codecov
315+
# DEV: Do not use the bash uploader, it cannot be trusted
316+
- run: codecov
317+
# Generate and save xml report
318+
# DEV: "--ignore-errors" to skip over files that are missing
319+
- run: coverage xml --ignore-errors
320+
- store_artifacts:
321+
path: coverage.xml
322+
# Generate and save JSON report
323+
# DEV: "--ignore-errors" to skip over files that are missing
324+
- run: coverage json --ignore-errors
325+
- store_artifacts:
326+
path: coverage.json
327+
# Print ddtrace/ report to stdout
328+
# DEV: "--ignore-errors" to skip over files that are missing
329+
- run: coverage report --ignore-errors --omit=tests/
330+
# Print tests/ report to stdout
331+
# DEV: "--ignore-errors" to skip over files that are missing
332+
- run: coverage report --ignore-errors --omit=ddtrace/
333+
# Print diff-cover report to stdout (compares against origin/1.x)
334+
- run: diff-cover --compare-branch $(git rev-parse --abbrev-ref origin/HEAD) coverage.xml
335+
- unless:
336+
condition:
337+
<< pipeline.parameters.coverage >>
338+
steps:
339+
- run: echo "No coverage data collected. Set run workflow manually with pipeline parameter 'coverage=true'."
340+
348341

349342
build_base_venvs:
350343
resource_class: large
@@ -539,32 +532,26 @@ jobs:
539532

540533
integration_agent:
541534
<<: *machine_executor
535+
parallelism: 2
542536
steps:
543537
- attach_workspace:
544538
at: .
545539
- checkout
540+
- setup_riot
546541
- start_docker_services:
547542
services: ddagent
548543
- run:
549544
command: |
550545
mv .riot .ddriot
551-
./scripts/ddtest riot -v run --pass-env -s 'integration-latest'
546+
riot list --hash-only 'integration-latest' | shuf | circleci tests split | xargs -n 1 -I {} ./scripts/ddtest riot -v run --pass-env -s {}
552547
553548
integration_testagent:
554549
<<: *machine_executor
555550
steps:
556-
- attach_workspace:
557-
at: .
558-
- checkout
559-
- start_docker_services:
560-
env: SNAPSHOT_CI=1
561-
services: testagent
562-
- run:
563-
environment:
564-
DD_TRACE_AGENT_URL: http://localhost:9126
565-
command: |
566-
mv .riot .ddriot
567-
./scripts/ddtest riot -v run --pass-env -s 'integration-snapshot'
551+
- run_test:
552+
snapshot: true
553+
store_coverage: false
554+
pattern: 'integration-snapshot'
568555

569556
vendor:
570557
<<: *contrib_job_small

.riot/requirements/4797e24.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#
2+
# This file is autogenerated by pip-compile
3+
# To update, run:
4+
#
5+
# pip-compile --no-annotate .riot/requirements/4797e24.in
6+
#
7+
atomicwrites==1.4.1
8+
attrs==21.4.0
9+
backports.functools-lru-cache==1.6.4
10+
configparser==4.0.2
11+
contextlib2==0.6.0.post1
12+
coverage==5.5
13+
enum34==1.1.10
14+
funcsigs==1.0.2
15+
futures==3.4.0
16+
hypothesis==4.57.1
17+
importlib-metadata==2.1.3
18+
mock==3.0.5
19+
more-itertools==5.0.0
20+
msgpack==1.0.5
21+
opentracing==2.4.0
22+
packaging==20.9
23+
pathlib2==2.3.7.post1
24+
pluggy==0.13.1
25+
py==1.11.0
26+
pyparsing==2.4.7
27+
pytest-cov==2.12.1
28+
pytest-mock==2.0.0
29+
pytest==4.6.0
30+
scandir==1.10.0
31+
six==1.16.0
32+
sortedcontainers==2.4.0
33+
toml==0.10.2
34+
typing==3.10.0.0
35+
wcwidth==0.2.6
36+
zipp==1.2.0

riotfile.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ def select_pys(min_version=MIN_PYTHON_VERSION, max_version=MAX_PYTHON_VERSION):
298298
),
299299
Venv(
300300
name="integration",
301+
# Enabling coverage for integration tests breaks certain tests in CI
301302
command="pytest --no-cov {cmdargs} tests/integration/",
302303
pkgs={"msgpack": [latest]},
303304
venvs=[
@@ -1576,9 +1577,9 @@ def select_pys(min_version=MIN_PYTHON_VERSION, max_version=MAX_PYTHON_VERSION):
15761577
pys=["2.7"],
15771578
# pytest==4.6 is last to support python 2.7
15781579
pkgs={
1579-
"pytest": ">=4.0,<4.6",
1580+
"pytest": ">=4.0,<=4.6",
15801581
"msgpack": latest,
1581-
"pytest-cov": "==2.5.0",
1582+
"pytest-cov": "==2.12.1",
15821583
},
15831584
),
15841585
Venv(

tests/integration/test_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ def test_regression_logging_in_context(tmpdir, logs_injection, debug_mode, patch
771771
[sys.executable, "test.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=str(tmpdir), env=env
772772
)
773773
try:
774-
p.wait(timeout=2)
774+
p.wait(timeout=10)
775775
except TypeError:
776776
# timeout argument added in Python 3.3
777777
p.wait()

0 commit comments

Comments
 (0)