-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathtest_valid.py
409 lines (382 loc) · 17.2 KB
/
test_valid.py
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
# mypy: ignore-errors
import json
import os
from unittest import mock
import httpx
import jsone
import pytest
import yaml
from jsonschema import validate
from tools.ci.tc import decision
here = os.path.dirname(__file__)
root = os.path.abspath(os.path.join(here, "..", "..", "..", ".."))
def data_path(filename):
return os.path.join(here, "..", "testdata", filename)
def test_verify_taskcluster_yml():
"""Verify that the json-e in the .taskcluster.yml is valid"""
with open(os.path.join(root, ".taskcluster.yml"), encoding="utf8") as f:
template = yaml.safe_load(f)
events = [("pr_event.json", "github-pull-request", "Pull Request"),
("master_push_event.json", "github-push", "Push to master")]
for filename, tasks_for, title in events:
with open(data_path(filename), encoding="utf8") as f:
event = json.load(f)
context = {"tasks_for": tasks_for,
"event": event,
"as_slugid": lambda x: x}
jsone.render(template, context)
@pytest.mark.parametrize("event_path,expected",
[("pr_event.json",
frozenset(["lint", "wpt-chrome-dev-stability"])),
("pr_event_tests_affected.json", frozenset(["lint"]))]
)
def test_exclude_users(event_path, expected):
"""Verify that tasks excluded by the PR submitter are properly excluded"""
tasks = {
"lint": {
"commands": "wpt example"
},
"wpt-chrome-dev-stability": {
"commands": "wpt example",
"exclude-users": ["chromium-wpt-export-bot"]
}
}
with open(data_path(event_path), encoding="utf8") as f:
event = json.load(f)
decision.filter_excluded_users(tasks, event)
assert set(tasks) == expected
def test_sink_task_depends():
"""Verify that sink task only depends on required tasks"""
from tools.ci.tc.decision import decide
files_changed = {"layout-instability/clip-negative-bottom-margin.html",
"layout-instability/composited-element-movement.html"}
with open(data_path("pr_event_tests_affected.json"), encoding="utf8") as f:
event = json.load(f)
with mock.patch("tools.ci.tc.decision.get_fetch_rev", return_value=(None, None, None)):
with mock.patch("tools.wpt.testfiles.repo_files_changed",
return_value=files_changed):
# Ensure we don't exclude the Chrome jobs
event["pull_request"]["user"]["login"] = "test"
task_id_map = decide(event)
sink_task = task_id_map["sink-task"][1]
assert set(sink_task["dependencies"]) == (
set(task_id for (task_name, (task_id, _)) in task_id_map.items()
if task_name not in {"sink-task", "wpt-chrome-dev-stability"}))
def test_verify_payload():
"""Verify that the decision task produces tasks with a valid payload"""
from tools.ci.tc.decision import decide
r = httpx.get("https://community-tc.services.mozilla.com/schemas/queue/v1/create-task-request.json")
r.raise_for_status()
create_task_schema = r.json()
r = httpx.get("https://community-tc.services.mozilla.com/references/schemas/docker-worker/v1/payload.json")
r.raise_for_status()
payload_schema = r.json()
jobs = ["lint",
"manifest_upload",
"resources_unittest",
"tools_unittest",
"wpt_integration",
"wptrunner_infrastructure",
"wptrunner_unittest"]
for filename in ["pr_event.json", "master_push_event.json"]:
with open(data_path(filename), encoding="utf8") as f:
event = json.load(f)
with mock.patch("tools.ci.tc.decision.get_fetch_rev", return_value=(None, event["after"], None)):
with mock.patch("tools.ci.tc.decision.get_run_jobs", return_value=set(jobs)):
task_id_map = decide(event)
for name, (task_id, task_data) in task_id_map.items():
try:
validate(instance=task_data, schema=create_task_schema)
validate(instance=task_data["payload"], schema=payload_schema)
except Exception as e:
print(f"Validation failed for task '{name}':\n{json.dumps(task_data, indent=2)}")
raise e
@pytest.mark.parametrize("event_path,is_pr,files_changed,expected", [
("master_push_event.json", False, None,
['download-firefox-nightly',
'wpt-firefox-nightly-testharness-1',
'wpt-firefox-nightly-testharness-2',
'wpt-firefox-nightly-testharness-3',
'wpt-firefox-nightly-testharness-4',
'wpt-firefox-nightly-testharness-5',
'wpt-firefox-nightly-testharness-6',
'wpt-firefox-nightly-testharness-7',
'wpt-firefox-nightly-testharness-8',
'wpt-firefox-nightly-testharness-9',
'wpt-firefox-nightly-testharness-10',
'wpt-firefox-nightly-testharness-11',
'wpt-firefox-nightly-testharness-12',
'wpt-firefox-nightly-testharness-13',
'wpt-firefox-nightly-testharness-14',
'wpt-firefox-nightly-testharness-15',
'wpt-firefox-nightly-testharness-16',
'wpt-chrome-canary-testharness-1',
'wpt-chrome-canary-testharness-2',
'wpt-chrome-canary-testharness-3',
'wpt-chrome-canary-testharness-4',
'wpt-chrome-canary-testharness-5',
'wpt-chrome-canary-testharness-6',
'wpt-chrome-canary-testharness-7',
'wpt-chrome-canary-testharness-8',
'wpt-chrome-canary-testharness-9',
'wpt-chrome-canary-testharness-10',
'wpt-chrome-canary-testharness-11',
'wpt-chrome-canary-testharness-12',
'wpt-chrome-canary-testharness-13',
'wpt-chrome-canary-testharness-14',
'wpt-chrome-canary-testharness-15',
'wpt-chrome-canary-testharness-16',
'wpt-firefox-nightly-reftest-1',
'wpt-firefox-nightly-reftest-2',
'wpt-firefox-nightly-reftest-3',
'wpt-firefox-nightly-reftest-4',
'wpt-firefox-nightly-reftest-5',
'wpt-firefox-nightly-reftest-6',
'wpt-chrome-canary-reftest-1',
'wpt-chrome-canary-reftest-2',
'wpt-chrome-canary-reftest-3',
'wpt-chrome-canary-reftest-4',
'wpt-chrome-canary-reftest-5',
'wpt-chrome-canary-reftest-6',
'wpt-firefox-nightly-wdspec-1',
'wpt-firefox-nightly-wdspec-2',
'wpt-chrome-canary-wdspec-1',
'wpt-chrome-canary-wdspec-2',
'wpt-firefox-nightly-crashtest-1',
'wpt-chrome-canary-crashtest-1',
'wpt-firefox-nightly-print-reftest-1',
'wpt-chrome-canary-print-reftest-1',
'lint']),
("pr_event.json", True, {".taskcluster.yml", ".travis.yml", "tools/ci/start.sh"},
['lint',
'tools/ unittests (Python 3.8)',
'tools/ unittests (Python 3.13)',
'tools/ integration tests (Python 3.8)',
'tools/ integration tests (Python 3.13)',
'resources/ tests (Python 3.8)',
'resources/ tests (Python 3.13)',
'download-firefox-nightly',
'infrastructure/ tests',
'sink-task']),
# More tests are affected in the actual PR but it shouldn't affect the scheduled tasks
("pr_event_tests_affected.json", True, {"layout-instability/clip-negative-bottom-margin.html",
"layout-instability/composited-element-movement.html"},
['download-firefox-nightly',
'wpt-firefox-nightly-stability',
'wpt-firefox-nightly-results',
'wpt-firefox-nightly-results-without-changes',
'wpt-chrome-dev-results',
'wpt-chrome-dev-results-without-changes',
'lint',
'sink-task']),
("pr_event_tests_affected.json", True, {"resources/testharness.js"},
['lint',
'resources/ tests (Python 3.8)',
'resources/ tests (Python 3.13)',
'download-firefox-nightly',
'infrastructure/ tests',
'sink-task']),
("epochs_daily_push_event.json", False, None,
['download-firefox-stable',
'wpt-firefox-stable-testharness-1',
'wpt-firefox-stable-testharness-2',
'wpt-firefox-stable-testharness-3',
'wpt-firefox-stable-testharness-4',
'wpt-firefox-stable-testharness-5',
'wpt-firefox-stable-testharness-6',
'wpt-firefox-stable-testharness-7',
'wpt-firefox-stable-testharness-8',
'wpt-firefox-stable-testharness-9',
'wpt-firefox-stable-testharness-10',
'wpt-firefox-stable-testharness-11',
'wpt-firefox-stable-testharness-12',
'wpt-firefox-stable-testharness-13',
'wpt-firefox-stable-testharness-14',
'wpt-firefox-stable-testharness-15',
'wpt-firefox-stable-testharness-16',
'wpt-chromium-nightly-testharness-1',
'wpt-chromium-nightly-testharness-2',
'wpt-chromium-nightly-testharness-3',
'wpt-chromium-nightly-testharness-4',
'wpt-chromium-nightly-testharness-5',
'wpt-chromium-nightly-testharness-6',
'wpt-chromium-nightly-testharness-7',
'wpt-chromium-nightly-testharness-8',
'wpt-chromium-nightly-testharness-9',
'wpt-chromium-nightly-testharness-10',
'wpt-chromium-nightly-testharness-11',
'wpt-chromium-nightly-testharness-12',
'wpt-chromium-nightly-testharness-13',
'wpt-chromium-nightly-testharness-14',
'wpt-chromium-nightly-testharness-15',
'wpt-chromium-nightly-testharness-16',
'wpt-chrome-stable-testharness-1',
'wpt-chrome-stable-testharness-2',
'wpt-chrome-stable-testharness-3',
'wpt-chrome-stable-testharness-4',
'wpt-chrome-stable-testharness-5',
'wpt-chrome-stable-testharness-6',
'wpt-chrome-stable-testharness-7',
'wpt-chrome-stable-testharness-8',
'wpt-chrome-stable-testharness-9',
'wpt-chrome-stable-testharness-10',
'wpt-chrome-stable-testharness-11',
'wpt-chrome-stable-testharness-12',
'wpt-chrome-stable-testharness-13',
'wpt-chrome-stable-testharness-14',
'wpt-chrome-stable-testharness-15',
'wpt-chrome-stable-testharness-16',
'wpt-webkitgtk_minibrowser-nightly-testharness-1',
'wpt-webkitgtk_minibrowser-nightly-testharness-2',
'wpt-webkitgtk_minibrowser-nightly-testharness-3',
'wpt-webkitgtk_minibrowser-nightly-testharness-4',
'wpt-webkitgtk_minibrowser-nightly-testharness-5',
'wpt-webkitgtk_minibrowser-nightly-testharness-6',
'wpt-webkitgtk_minibrowser-nightly-testharness-7',
'wpt-webkitgtk_minibrowser-nightly-testharness-8',
'wpt-webkitgtk_minibrowser-nightly-testharness-9',
'wpt-webkitgtk_minibrowser-nightly-testharness-10',
'wpt-webkitgtk_minibrowser-nightly-testharness-11',
'wpt-webkitgtk_minibrowser-nightly-testharness-12',
'wpt-webkitgtk_minibrowser-nightly-testharness-13',
'wpt-webkitgtk_minibrowser-nightly-testharness-14',
'wpt-webkitgtk_minibrowser-nightly-testharness-15',
'wpt-webkitgtk_minibrowser-nightly-testharness-16',
'wpt-wpewebkit_minibrowser-nightly-testharness-1',
'wpt-wpewebkit_minibrowser-nightly-testharness-2',
'wpt-wpewebkit_minibrowser-nightly-testharness-3',
'wpt-wpewebkit_minibrowser-nightly-testharness-4',
'wpt-wpewebkit_minibrowser-nightly-testharness-5',
'wpt-wpewebkit_minibrowser-nightly-testharness-6',
'wpt-wpewebkit_minibrowser-nightly-testharness-7',
'wpt-wpewebkit_minibrowser-nightly-testharness-8',
'wpt-wpewebkit_minibrowser-nightly-testharness-9',
'wpt-wpewebkit_minibrowser-nightly-testharness-10',
'wpt-wpewebkit_minibrowser-nightly-testharness-11',
'wpt-wpewebkit_minibrowser-nightly-testharness-12',
'wpt-wpewebkit_minibrowser-nightly-testharness-13',
'wpt-wpewebkit_minibrowser-nightly-testharness-14',
'wpt-wpewebkit_minibrowser-nightly-testharness-15',
'wpt-wpewebkit_minibrowser-nightly-testharness-16',
'wpt-servo-nightly-testharness-1',
'wpt-servo-nightly-testharness-2',
'wpt-servo-nightly-testharness-3',
'wpt-servo-nightly-testharness-4',
'wpt-servo-nightly-testharness-5',
'wpt-servo-nightly-testharness-6',
'wpt-servo-nightly-testharness-7',
'wpt-servo-nightly-testharness-8',
'wpt-servo-nightly-testharness-9',
'wpt-servo-nightly-testharness-10',
'wpt-servo-nightly-testharness-11',
'wpt-servo-nightly-testharness-12',
'wpt-servo-nightly-testharness-13',
'wpt-servo-nightly-testharness-14',
'wpt-servo-nightly-testharness-15',
'wpt-servo-nightly-testharness-16',
'wpt-firefox_android-nightly-testharness-1',
'wpt-firefox_android-nightly-testharness-2',
'wpt-firefox_android-nightly-testharness-3',
'wpt-firefox_android-nightly-testharness-4',
'wpt-firefox_android-nightly-testharness-5',
'wpt-firefox_android-nightly-testharness-6',
'wpt-firefox_android-nightly-testharness-7',
'wpt-firefox_android-nightly-testharness-8',
'wpt-firefox_android-nightly-testharness-9',
'wpt-firefox_android-nightly-testharness-10',
'wpt-firefox_android-nightly-testharness-11',
'wpt-firefox_android-nightly-testharness-12',
'wpt-firefox_android-nightly-testharness-13',
'wpt-firefox_android-nightly-testharness-14',
'wpt-firefox_android-nightly-testharness-15',
'wpt-firefox_android-nightly-testharness-16',
'wpt-firefox_android-nightly-testharness-17',
'wpt-firefox_android-nightly-testharness-18',
'wpt-firefox_android-nightly-testharness-19',
'wpt-firefox_android-nightly-testharness-20',
'wpt-firefox_android-nightly-testharness-21',
'wpt-firefox_android-nightly-testharness-22',
'wpt-firefox_android-nightly-testharness-23',
'wpt-firefox_android-nightly-testharness-24',
'wpt-firefox_android-nightly-testharness-25',
'wpt-firefox_android-nightly-testharness-26',
'wpt-firefox_android-nightly-testharness-27',
'wpt-firefox_android-nightly-testharness-28',
'wpt-firefox_android-nightly-testharness-29',
'wpt-firefox_android-nightly-testharness-30',
'wpt-firefox-stable-reftest-1',
'wpt-firefox-stable-reftest-2',
'wpt-firefox-stable-reftest-3',
'wpt-firefox-stable-reftest-4',
'wpt-firefox-stable-reftest-5',
'wpt-firefox-stable-reftest-6',
'wpt-chromium-nightly-reftest-1',
'wpt-chromium-nightly-reftest-2',
'wpt-chromium-nightly-reftest-3',
'wpt-chromium-nightly-reftest-4',
'wpt-chromium-nightly-reftest-5',
'wpt-chromium-nightly-reftest-6',
'wpt-chrome-stable-reftest-1',
'wpt-chrome-stable-reftest-2',
'wpt-chrome-stable-reftest-3',
'wpt-chrome-stable-reftest-4',
'wpt-chrome-stable-reftest-5',
'wpt-chrome-stable-reftest-6',
'wpt-webkitgtk_minibrowser-nightly-reftest-1',
'wpt-webkitgtk_minibrowser-nightly-reftest-2',
'wpt-webkitgtk_minibrowser-nightly-reftest-3',
'wpt-webkitgtk_minibrowser-nightly-reftest-4',
'wpt-webkitgtk_minibrowser-nightly-reftest-5',
'wpt-webkitgtk_minibrowser-nightly-reftest-6',
'wpt-wpewebkit_minibrowser-nightly-reftest-1',
'wpt-wpewebkit_minibrowser-nightly-reftest-2',
'wpt-wpewebkit_minibrowser-nightly-reftest-3',
'wpt-wpewebkit_minibrowser-nightly-reftest-4',
'wpt-wpewebkit_minibrowser-nightly-reftest-5',
'wpt-wpewebkit_minibrowser-nightly-reftest-6',
'wpt-servo-nightly-reftest-1',
'wpt-servo-nightly-reftest-2',
'wpt-servo-nightly-reftest-3',
'wpt-servo-nightly-reftest-4',
'wpt-servo-nightly-reftest-5',
'wpt-servo-nightly-reftest-6',
'wpt-firefox_android-nightly-reftest-1',
'wpt-firefox_android-nightly-reftest-2',
'wpt-firefox_android-nightly-reftest-3',
'wpt-firefox_android-nightly-reftest-4',
'wpt-firefox_android-nightly-reftest-5',
'wpt-firefox_android-nightly-reftest-6',
'wpt-firefox-stable-wdspec-1',
'wpt-firefox-stable-wdspec-2',
'wpt-chromium-nightly-wdspec-1',
'wpt-chromium-nightly-wdspec-2',
'wpt-chrome-stable-wdspec-1',
'wpt-chrome-stable-wdspec-2',
'wpt-webkitgtk_minibrowser-nightly-wdspec-1',
'wpt-webkitgtk_minibrowser-nightly-wdspec-2',
'wpt-wpewebkit_minibrowser-nightly-wdspec-1',
'wpt-wpewebkit_minibrowser-nightly-wdspec-2',
'wpt-servo-nightly-wdspec-1',
'wpt-servo-nightly-wdspec-2',
'wpt-firefox_android-nightly-wdspec-1',
'wpt-firefox_android-nightly-wdspec-2',
'wpt-firefox-stable-crashtest-1',
'wpt-chromium-nightly-crashtest-1',
'wpt-chrome-stable-crashtest-1',
'wpt-webkitgtk_minibrowser-nightly-crashtest-1',
'wpt-wpewebkit_minibrowser-nightly-crashtest-1',
'wpt-servo-nightly-crashtest-1',
'wpt-firefox_android-nightly-crashtest-1',
'wpt-firefox-stable-print-reftest-1',
'wpt-chromium-nightly-print-reftest-1',
'wpt-chrome-stable-print-reftest-1'])
])
def test_schedule_tasks(event_path, is_pr, files_changed, expected):
with mock.patch("tools.ci.tc.decision.get_fetch_rev", return_value=(None, None, None)):
with mock.patch("tools.wpt.testfiles.repo_files_changed",
return_value=files_changed):
with open(data_path(event_path), encoding="utf8") as event_file:
event = json.load(event_file)
scheduled = decision.decide(event)
print(list(scheduled.keys()))
assert list(scheduled.keys()) == expected