Skip to content

Commit f39d928

Browse files
ofekmasci
authored andcommitted
Add ability to filter checks to test by changes (DataDog#2163)
1 parent edb2c7f commit f39d928

File tree

3 files changed

+55
-65
lines changed

3 files changed

+55
-65
lines changed

appveyor.yml

+30-52
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,45 @@
11
version: '{branch}.{build}'
22
clone_depth: 3
3-
environment:
4-
TRAVIS_BUILD_DIR: c:\projects\integrations-core
5-
INTEGRATIONS_DIR: c:\projects\integrations-core\embedded
6-
PIP_CACHE: c:\projects\integrations-core\.cache\pip
7-
VOLATILE_DIR: c:\projects
8-
NOSE_FILTER: not unix and not fixme and not winfixme
9-
PYWIN_PATH: C:\projects\integrations-core\.cache\pywin32-py2.7.exe
10-
SKIP_LINT: true
11-
DD_AGENT_BRANCH: master
12-
SDK_TESTING: true
13-
PYTHON: C:\Python27-x64
14-
PYTHON_VERSION: 2.7.13
15-
PYTHON_ARCH: 64
16-
PYWIN32_URL: https://downloads.sourceforge.net/project/pywin32/pywin32/Build%20219/pywin32-219.win-amd64-py2.7.exe
17-
PYWIN32_INSTALL_DIR: pywin32-219-py2.7-win-amd64.egg
18-
init:
19-
- set PATH=%PYTHON%;%PYTHON%\Scripts;%PATH%
3+
build: off
4+
test: off
5+
skip_branch_with_pr: true
206
cache:
21-
- C:\projects\integrations-core\.cache
22-
- C:\projects\integrations-core\vendor\cache
23-
- C:\projects\integrations-core\embedded
7+
- '%LOCALAPPDATA%\pip\Cache'
248
services:
259
- iis
2610
# We can't start more than one MSSQL instance to avoid conflicts on TCP port 1433. The only workaround to test a check
2711
# against multiple versions is letting the test code to start/stop the corresponding services so that they run one at
2812
# a time. See https://www.appveyor.com/docs/services-databases/ for details.
2913
- mssql2008r2sp2
14+
15+
branches:
16+
only:
17+
- master
18+
19+
environment:
20+
PYTHON2: C:\Python27-x64
21+
PYTHON3: C:\Python36-x64
22+
23+
init:
24+
# Add Python 3 to PATH
25+
- set PATH=%PYTHON3%;%PYTHON3%\Scripts;%PATH%
26+
- python -c "import sys; print(sys.version)"
27+
28+
# Add Python 2 to PATH before Python 3
29+
- set PATH=%PYTHON2%;%PYTHON2%\Scripts;%PATH%
30+
- python -c "import sys; print(sys.version)"
31+
32+
- if defined APPVEYOR_PULL_REQUEST_NUMBER ( set "CHANGED_ONLY_FLAG= --changed" ) else ( set "CHANGED_ONLY_FLAG= " )
33+
3034
install:
31-
# Use the 64-bit ruby so that all the Powershell classes are accessible when running shell commands from ruby
32-
- set PATH=C:\Ruby22-x64\bin;%PATH%
33-
- bundle install
34-
- bundle package
35-
- git clone -b %DD_AGENT_BRANCH% https://github.com/DataDog/dd-agent.git c:\projects\dd-agent
36-
- if not exist %PIP_CACHE% mkdir %PIP_CACHE%
37-
- cmd: appveyor-retry powershell If (-Not (Test-Path $env:PYWIN_PATH)) {(new-object net.webclient).DownloadFile("$env:PYWIN32_URL", "$env:PYWIN_PATH")}
38-
- "%PYTHON%/Scripts/easy_install.exe %PYWIN_PATH%"
39-
- ps: mkdir -p $(python -m site --user-site)
40-
- ps: echo "C:\projects\dd-agent" | out-file "$(python -m site --user-site)/datadog-agent.pth" -encoding ASCII
41-
- ps: (& "$env:PYTHON/python.exe" -m pip install --upgrade pip codecov)
42-
- ps: '& "$env:PYTHON/Scripts/pip.exe" install -r c:\projects\dd-agent\requirements.txt'
43-
# Remove the adodbapi module shipped with pywin32: it conflicts with the pip-installed adodbapi
44-
- ps: rm $env:PYTHON/lib/site-packages/$env:PYWIN32_INSTALL_DIR/adodbapi/__init__.py
45-
- ps: rm $env:PYTHON/lib/site-packages/$env:PYWIN32_INSTALL_DIR/adodbapi/__init__.pyc
46-
- ps: (& "$env:PYTHON/Scripts/pip.exe" install -U virtualenv)
47-
- ps: (& "$env:PYTHON/Scripts/pip.exe" uninstall -y docker-py)
48-
- ps: (& "$env:PYTHON/Scripts/pip.exe" install .\datadog_checks_dev[cli])
35+
- python -m pip install --upgrade --disable-pip-version-check pip virtualenv codecov
36+
- pip uninstall -y docker-py
37+
- pip install .\datadog_checks_dev[cli]
4938
- ddev config set core .
50-
- cd datadog_checks_base
51-
- ps: (& "$env:PYTHON/Scripts/pip.exe" install .)
52-
- cd ..
53-
- cd sqlserver
54-
- ps: (& "$env:PYTHON/Scripts/pip.exe" install .)
55-
- cd ..
56-
- cd windows_service
57-
- ps: (& "$env:PYTHON/Scripts/pip.exe" install .)
58-
- cd ..
59-
- cd wmi_check
60-
- ps: (& "$env:PYTHON/Scripts/pip.exe" install .)
61-
- cd ..
62-
build: off
39+
6340
test_script:
64-
- ddev test datadog_checks_base active_directory aspdotnet dotnetclr exchange_server iis pdh_check sqlserver win32_event_log windows_service wmi_check
41+
# Only test any of these that have changed for pull requests
42+
- ddev test%CHANGED_ONLY_FLAG% datadog_checks_base active_directory aspdotnet dotnetclr exchange_server iis pdh_check sqlserver win32_event_log windows_service wmi_check
6543

6644
# Uncomment the following to enable RDP connection into the builder and debug a build
6745
# on_finish:

datadog_checks_dev/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ Options:
543543
-c, --cov Measure code coverage
544544
-m, --cov-missing Show line numbers of statements that were not executed
545545
--cov-keep Keep coverage reports
546+
--changed Only test changed checks
546547
-v, --verbose Increase verbosity (can be used additively)
547548
-h, --help Show this message and exit.
548549
```

datadog_checks_dev/datadog_checks/dev/tooling/commands/test.py

+24-13
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ def testable_files(files):
4242
return [f for f in files if f.endswith(TESTABLE_FILE_EXTENSIONS)]
4343

4444

45+
def get_changed_checks():
46+
# Get files that changed compared to `master`
47+
changed_files = files_changed()
48+
49+
# Filter by files that can influence the testing of a check
50+
changed_files[:] = testable_files(changed_files)
51+
52+
return {line.split('/')[0] for line in changed_files}
53+
54+
4555
@click.command(
4656
context_settings=CONTEXT_SETTINGS,
4757
short_help='Run tests'
@@ -51,28 +61,29 @@ def testable_files(files):
5161
@click.option('--cov', '-c', 'coverage', is_flag=True, help='Measure code coverage')
5262
@click.option('--cov-missing', '-m', is_flag=True, help='Show line numbers of statements that were not executed')
5363
@click.option('--cov-keep', is_flag=True, help='Keep coverage reports')
64+
@click.option('--changed', is_flag=True, help='Only test changed checks')
5465
@click.option('--verbose', '-v', count=True, help='Increase verbosity (can be used additively)')
55-
def test(checks, bench, coverage, cov_missing, cov_keep, verbose):
66+
def test(checks, bench, coverage, cov_missing, cov_keep, changed, verbose):
5667
"""Run tests for Agent-based checks.
5768
5869
If no checks are specified, this will only test checks that
5970
were changed compared to the master branch.
6071
"""
6172
root = get_root()
6273

63-
if not checks:
64-
# get the list of the files that changed compared to `master`
65-
changed_files = files_changed()
66-
67-
# get the list of files that can change the implementation of a check
68-
files_requiring_tests = testable_files(changed_files)
69-
70-
# get the integrations associated with changed files
71-
changed_checks = {line.split('/')[0] for line in files_requiring_tests}
72-
73-
checks = sorted(changed_checks & get_testable_checks())
74+
if checks:
75+
checks_to_test = get_testable_checks() & set(checks)
76+
if changed:
77+
checks_to_test = checks_to_test & get_changed_checks()
78+
# Retain order
79+
final_checks = []
80+
for check in checks:
81+
if check in checks_to_test:
82+
final_checks.append(check)
83+
checks_to_test.remove(check)
84+
checks = final_checks
7485
else:
75-
checks = sorted(set(checks) & get_testable_checks())
86+
checks = sorted(get_testable_checks() & get_changed_checks())
7687

7788
if not checks:
7889
echo_info('No checks to test!')

0 commit comments

Comments
 (0)