Bug 1640902 - [ci] Add integration tests for the 'taskcluster' directory, r=tomprince

Initially this suite will only include a test for |mach try auto| pushes.

Differential Revision: https://phabricator.services.mozilla.com/D81403
This commit is contained in:
Andrew Halberstadt 2020-07-08 18:48:26 +00:00
Родитель 0d3d8d4744
Коммит 8dc68edc8e
8 изменённых файлов: 3790 добавлений и 13 удалений

Просмотреть файл

@ -32,18 +32,19 @@ job-defaults:
- 'config/mozunit/**'
- 'python/mach_commands.py'
taskgraph-tests:
firefox-ci:
description: taskcluster/taskgraph unit tests
python-version: [2, 3]
python-version: [2]
treeherder:
symbol: tg
symbol: ci
run:
using: python-test
subsuite: taskgraph
subsuite: ci
when:
files-changed:
- 'taskcluster/ci/**'
- 'taskcluster/**/*.py'
- 'python/mach/**/*.py'
- 'tools/tryselect/selectors/auto.py'
mach:
description: python/mach unit tests
@ -311,6 +312,19 @@ reftest-harness:
- 'testing/mozharness/mozharness/mozilla/structuredlog.py'
- 'testing/mozharness/mozharness/mozilla/testing/errors.py'
taskgraph-tests:
description: taskcluster/taskgraph unit tests
python-version: [2, 3]
treeherder:
symbol: tg
run:
using: python-test
subsuite: taskgraph
when:
files-changed:
- 'taskcluster/**/*.py'
- 'python/mach/**/*.py'
tryselect:
description: tools/tryselect unit tests
platform:

Просмотреть файл

@ -9,6 +9,7 @@ with Files('**'):
PYTHON_UNITTEST_MANIFESTS += [
'taskgraph/test/python.ini',
'test/python.ini',
]
SPHINX_TREES['/taskcluster'] = 'docs'
SPHINX_PYTHON_PACKAGE_DIRS += ['taskgraph']

Просмотреть файл

@ -0,0 +1,77 @@
# Any copyright is dedicated to the public domain.
# http://creativecommons.org/publicdomain/zero/1.0/
from __future__ import absolute_import
import json
import os
import pytest
from mach.logging import LoggingManager
from responses import RequestsMock
from taskgraph.generator import TaskGraphGenerator
from taskgraph.parameters import parameters_loader
from taskgraph.util.bugbug import BUGBUG_BASE_URL
here = os.path.abspath(os.path.dirname(__file__))
@pytest.fixture(scope="session")
def responses():
with RequestsMock() as rsps:
yield rsps
@pytest.fixture(scope="session")
def datadir():
return os.path.join(here, "data")
@pytest.fixture(scope="session")
def create_tgg(responses, datadir):
# Setup logging.
lm = LoggingManager()
lm.add_terminal_logging()
def inner(parameters=None, overrides=None, target_kind=None):
params = parameters_loader(parameters, strict=False, overrides=overrides)
tgg = TaskGraphGenerator(None, params, target_kind=target_kind)
# Mock out certain requests as they may depend on a revision that does
# not exist on hg.mozilla.org.
mock_requests = {}
# bugbug /push/schedules
url = BUGBUG_BASE_URL + "/push/{project}/{head_rev}/schedules".format(**tgg.parameters)
mock_requests[url] = "bugbug-push-schedules.json"
# files changed
url = "{head_repository}/json-automationrelevance/{head_rev}".format(**tgg.parameters)
mock_requests[url] = "automationrelevance.json"
for url, filename in mock_requests.items():
with open(os.path.join(datadir, filename)) as fh:
responses.add(
responses.GET,
url,
json=json.load(fh),
status=200,
)
# Still allow other real requests.
responses.add_passthru("https://hg.mozilla.org")
responses.add_passthru("https://firefox-ci-tc.services.mozilla.com")
return tgg
return inner
@pytest.fixture(scope="session")
def filter_tasks():
def inner(graph, func):
return filter(func, graph.tasks.values())
return inner

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,4 @@
[DEFAULT]
subsuite = ci
[test_mach_try_auto.py]

Просмотреть файл

@ -0,0 +1,40 @@
# Any copyright is dedicated to the public domain.
# http://creativecommons.org/publicdomain/zero/1.0/
from __future__ import absolute_import, print_function, unicode_literals
import pytest
from mozunit import main
from tryselect.selectors.auto import TRY_AUTO_PARAMETERS
pytestmark = pytest.mark.slow
@pytest.fixture(scope="module")
def tgg(create_tgg):
params = TRY_AUTO_PARAMETERS.copy()
params.update(
{"head_repository": "https://hg.mozilla.org/try", "project": "try"}
)
tgg = create_tgg(overrides=params, target_kind="test")
return tgg
@pytest.fixture(scope="module")
def full_task_graph(tgg):
return tgg.full_task_graph
@pytest.fixture(scope="module")
def optimized_task_graph(full_task_graph, tgg):
return tgg.optimized_task_graph
def test_generate_graph(optimized_task_graph):
"""Simply tests that generating the graph does not fail."""
assert len(optimized_task_graph.tasks) > 0
if __name__ == "__main__":
main()

Просмотреть файл

@ -8,6 +8,15 @@ from ..cli import BaseTryParser
from ..push import push_to_try
TRY_AUTO_PARAMETERS = {
'optimize_target_tasks': True,
'target_tasks_method': 'try_auto',
'test_manifest_loader': 'bugbug',
'try_mode': 'try_auto',
'try_task_config': {},
}
class AutoParser(BaseTryParser):
name = 'auto'
common_groups = ['push']
@ -24,22 +33,19 @@ class AutoParser(BaseTryParser):
def run(message='{msg}', push=True, closed_tree=False, try_config=None):
print("warning: 'mach try auto' is experimental, results may vary!")
msg = message.format(msg='Tasks automatically selected.')
try_config = try_config or {}
# XXX Remove once an intelligent scheduling algorithm is running on
# autoland by default. This ensures `mach try auto` doesn't run SETA.
try_config.setdefault('optimize-strategies',
'taskgraph.optimize:tryselect.bugbug_debug_disperse')
params = TRY_AUTO_PARAMETERS.copy()
if try_config:
params['try_task_config'] = try_config
task_config = {
'version': 2,
'parameters': {
'optimize_target_tasks': True,
'target_tasks_method': 'try_auto',
'test_manifest_loader': 'bugbug',
'try_mode': 'try_auto',
'try_task_config': try_config or {},
}
'parameters': params,
}
return push_to_try('auto', msg, try_task_config=task_config,
push=push, closed_tree=closed_tree)