1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
|
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import datetime
import json
import os
from unittest.mock import MagicMock
import mozunit
import pytest
@pytest.mark.skipif(os.name == "nt", reason="fzf not installed on host")
@pytest.mark.parametrize("show_chunk_numbers", [True, False])
def test_query_paths(run_mach, capfd, show_chunk_numbers):
cmd = [
"try",
"fuzzy",
"--no-push",
"-q",
"^test-linux '64/debug-mochitest-chrome-1proc-",
"caps/tests/mochitest/test_addonMayLoad.html",
]
chunk = "*"
if show_chunk_numbers:
cmd.append("--show-chunk-numbers")
chunk = "1"
assert run_mach(cmd) == 0
output = capfd.readouterr().out
print(output)
delim = "Calculated try_task_config.json:"
index = output.find(delim)
result = json.loads(output[index + len(delim) :])
# If there are more than one tasks here, it means that something went wrong
# with the path filtering.
tasks = result["parameters"]["try_task_config"]["tasks"]
assert tasks == ["test-linux2404-64/debug-mochitest-chrome-1proc-%s" % chunk]
@pytest.mark.skipif(os.name == "nt", reason="fzf not installed on host")
@pytest.mark.parametrize("show_chunk_numbers", [True, False])
def test_query_paths_no_chunks(run_mach, capfd, show_chunk_numbers):
cmd = [
"try",
"fuzzy",
"--no-push",
"-q",
"^test-linux '64/debug-cppunittest",
]
if show_chunk_numbers:
cmd.append("--show-chunk-numbers")
assert run_mach(cmd) == 0
output = capfd.readouterr().out
print(output)
delim = "Calculated try_task_config.json:"
index = output.find(delim)
result = json.loads(output[index + len(delim) :])
# If there are more than one tasks here, it means that something went wrong
# with the path filtering.
tasks = result["parameters"]["try_task_config"]["tasks"]
assert tasks == ["test-linux2404-64/debug-cppunittest-1proc"]
@pytest.mark.skipif(os.name == "nt", reason="fzf not installed on host")
@pytest.mark.parametrize("variant", ["", "spi-nw"])
def test_query_paths_variants(monkeypatch, run_mach, capfd, variant):
# Freeze time to avoid test failures due to an expired variant
datetime_mock = MagicMock(wraps=datetime.datetime)
datetime_mock.today.return_value = datetime.datetime.strptime(
"2025-08-01", "%Y-%m-%d"
)
monkeypatch.setattr(datetime, "datetime", datetime_mock)
if variant:
variant = "-%s" % variant
cmd = [
"try",
"fuzzy",
"--no-push",
"-q",
"^test-linux !ioi !vt '64/debug-mochitest-browser-chrome%s-" % variant,
]
assert run_mach(cmd) == 0
output = capfd.readouterr().out
print(output)
if variant:
expected = ["test-linux2404-64/debug-mochitest-browser-chrome%s-*" % variant]
else:
expected = [
"test-linux2404-64/debug-mochitest-browser-chrome-spi-nw-*",
"test-linux2404-64/debug-mochitest-browser-chrome-swr-*",
]
delim = "Calculated try_task_config.json:"
index = output.find(delim)
result = json.loads(output[index + len(delim) :])
tasks = result["parameters"]["try_task_config"]["tasks"]
assert sorted(tasks) == sorted(expected)
@pytest.mark.skipif(os.name == "nt", reason="fzf not installed on host")
@pytest.mark.parametrize("full", [True, False])
def test_query(run_mach, capfd, full):
cmd = ["try", "fuzzy", "--no-push", "-q", "'source-test-python-taskgraph-tests"]
if full:
cmd.append("--full")
assert run_mach(cmd) == 0
output = capfd.readouterr().out
print(output)
delim = "Calculated try_task_config.json:"
index = output.find(delim)
result = json.loads(output[index + len(delim) :])
# Should only ever mach one task exactly.
tasks = result["parameters"]["try_task_config"]["tasks"]
assert tasks == ["source-test-python-taskgraph-tests"]
@pytest.mark.skipif(os.name == "nt", reason="fzf not installed on host")
@pytest.mark.parametrize("tag", ["webextensions", "not_a_valid_tag"])
def test_query_tags(run_mach, capfd, tag):
cmd = [
"try",
"fuzzy",
"--no-push",
"--tag",
tag,
"-q",
"^test-linux '64/debug- !http !spi !swr !nofis !headless !xorig !async !ioi !vt",
]
if tag == "not_a_valid_tag":
assert run_mach(cmd) == 1
else:
assert run_mach(cmd) == 0
output = capfd.readouterr().out
print(output)
expected = [
"test-linux2404-64/debug-mochitest-devtools-chrome-*",
"test-linux2404-64/debug-mochitest-chrome-1proc-*",
"test-linux2404-64/debug-mochitest-chrome-gpu-1proc",
"test-linux2404-64/debug-mochitest-plain-*",
"test-linux2404-64/debug-mochitest-plain-gpu",
"test-linux2404-64/debug-xpcshell-*",
"test-linux2404-64/debug-test-verify",
"test-linux2404-64/debug-test-verify-gpu",
"test-linux2404-64/debug-test-verify-wpt",
]
if tag == "webextensions":
expected.remove("test-linux2404-64/debug-mochitest-devtools-chrome-*")
delim = "Calculated try_task_config.json:"
index = output.find(delim)
result = json.loads(output[index + len(delim) :])
tasks = result["parameters"]["try_task_config"]["tasks"]
# If enough test files change, the test-verify task may get chunked.
def canonical(tasks):
return sorted(t.rstrip("-*") for t in tasks)
assert canonical(tasks) == canonical(expected)
@pytest.mark.skipif(os.name == "nt", reason="fzf not installed on host")
@pytest.mark.parametrize(
"tag",
[
{"tags": ["webextensions"], "results": 0},
{"tags": ["webextensions", "devtools"], "results": 0},
],
)
def test_query_multiple_tags(run_mach, capfd, tag):
cmd = [
"try",
"fuzzy",
"--no-push",
"-q",
"^test-linux '64/debug- !http !spi !swr !nofis !headless !xorig",
]
for t in tag["tags"]:
cmd.extend(["--tag", t])
if tag["results"] == 0:
assert run_mach(cmd) == tag["results"]
else:
with pytest.raises(SystemExit) as result:
run_mach(cmd)
assert result.value.code == tag["results"]
output = capfd.readouterr().out
print(output)
@pytest.mark.skipif(os.name == "nt", reason="fzf not installed on host")
def test_target_tasks_method_pre_filter(run_mach, capfd):
cmd = [
"try",
"fuzzy",
"--no-push",
"--target-tasks-method=os-integration",
"-xq",
"^test 'talos",
]
assert run_mach(cmd) == 0
output = capfd.readouterr().out
print(output)
delim = "Calculated try_task_config.json:"
index = output.find(delim)
result = json.loads(output[index + len(delim) :])
assert "target_tasks_method" not in result["parameters"]
tasks = result["parameters"]["try_task_config"]["tasks"]
# Assert we didn't select any unexpected talos tests, which implies the
# os-integration pre-filtering worked. Talos was chosen because the tasks
# we add to os-integration are unlikely to change much, but another type
# of task could be used instead if needed.
expected_talos_tests = {"other", "xperf", "webgl"}
for label in tasks:
assert any(e in label for e in expected_talos_tests)
if __name__ == "__main__":
mozunit.main()
|