зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1276216: make any tasks without dependencies depend on the decision task; r=ahal
MozReview-Commit-ID: 5k5jC7CCHNW --HG-- extra : rebase_source : 0f77e208b1947b2082481b7ceeab57055c13797e
This commit is contained in:
Родитель
072334bcdb
Коммит
69471c3482
|
@ -7,6 +7,7 @@ from __future__ import absolute_import, print_function, unicode_literals
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
import collections
|
import collections
|
||||||
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from slugid import nice as slugid
|
from slugid import nice as slugid
|
||||||
|
@ -20,8 +21,17 @@ def create_tasks(taskgraph, label_to_taskid):
|
||||||
|
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
|
|
||||||
|
decision_task_id = os.environ.get('TASK_ID')
|
||||||
|
|
||||||
for task_id in taskgraph.graph.visit_postorder():
|
for task_id in taskgraph.graph.visit_postorder():
|
||||||
task_def = taskgraph.tasks[task_id].task
|
task_def = taskgraph.tasks[task_id].task
|
||||||
|
|
||||||
|
# if this task has no dependencies, make it depend on this decision
|
||||||
|
# task so that it does not start immediately; and so that if this loop
|
||||||
|
# fails halfway through, none of the already-created tasks run.
|
||||||
|
if decision_task_id and not task_def.get('dependencies'):
|
||||||
|
task_def['dependencies'] = [decision_task_id]
|
||||||
|
|
||||||
task_def['taskGroupId'] = task_group_id
|
task_def['taskGroupId'] = task_group_id
|
||||||
_create_task(session, task_id, taskid_to_label[task_id], task_def)
|
_create_task(session, task_id, taskid_to_label[task_id], task_def)
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
from __future__ import absolute_import, print_function, unicode_literals
|
from __future__ import absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
import os
|
||||||
|
|
||||||
from .. import create
|
from .. import create
|
||||||
from ..graph import Graph
|
from ..graph import Graph
|
||||||
|
@ -24,12 +25,19 @@ class FakeKind(object):
|
||||||
class TestCreate(unittest.TestCase):
|
class TestCreate(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
self.old_task_id = os.environ.get('TASK_ID')
|
||||||
|
if 'TASK_ID' in os.environ:
|
||||||
|
del os.environ['TASK_ID']
|
||||||
self.created_tasks = {}
|
self.created_tasks = {}
|
||||||
self.old_create_task = create._create_task
|
self.old_create_task = create._create_task
|
||||||
create._create_task = self.fake_create_task
|
create._create_task = self.fake_create_task
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
create._create_task = self.old_create_task
|
create._create_task = self.old_create_task
|
||||||
|
if self.old_task_id:
|
||||||
|
os.environ['TASK_ID'] = self.old_task_id
|
||||||
|
elif 'TASK_ID' in os.environ:
|
||||||
|
del os.environ['TASK_ID']
|
||||||
|
|
||||||
def fake_create_task(self, session, task_id, label, task_def):
|
def fake_create_task(self, session, task_id, label, task_def):
|
||||||
self.created_tasks[task_id] = task_def
|
self.created_tasks[task_id] = task_def
|
||||||
|
@ -52,6 +60,22 @@ class TestCreate(unittest.TestCase):
|
||||||
for depid in task.get('dependencies', []):
|
for depid in task.get('dependencies', []):
|
||||||
self.assertIn(depid, self.created_tasks)
|
self.assertIn(depid, self.created_tasks)
|
||||||
|
|
||||||
|
def test_create_task_without_dependencies(self):
|
||||||
|
"a task with no dependencies depends on the decision task"
|
||||||
|
os.environ['TASK_ID'] = 'decisiontask'
|
||||||
|
kind = FakeKind()
|
||||||
|
tasks = {
|
||||||
|
'tid-a': Task(kind=kind, label='a', task={'payload': 'hello world'}),
|
||||||
|
}
|
||||||
|
label_to_taskid = {'a': 'tid-a'}
|
||||||
|
graph = Graph(nodes={'tid-a'}, edges=set())
|
||||||
|
taskgraph = TaskGraph(tasks, graph)
|
||||||
|
|
||||||
|
create.create_tasks(taskgraph, label_to_taskid)
|
||||||
|
|
||||||
|
for tid, task in self.created_tasks.iteritems():
|
||||||
|
self.assertEqual(task['dependencies'], [os.environ['TASK_ID']])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Загрузка…
Ссылка в новой задаче