-
Notifications
You must be signed in to change notification settings - Fork 2
/
single_threaded_execution.py
145 lines (115 loc) · 3.34 KB
/
single_threaded_execution.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
# coding: utf8
# Copyright 2013-2018 Vincent Jacques <vincent@vincent-jacques.net>
from __future__ import division, absolute_import, print_function
from ActionTree import *
from . import *
class ExecutionTestCase(ActionTreeTestCase):
def test_simple_execution(self):
a = self._action("a", return_value=42)
report = execute(a, cpu_cores=1)
self.assertTrue(report.is_success)
self.assertEqual(report.get_action_status(a).status, SUCCESSFUL)
self.assertEqual(report.get_action_status(a).return_value, 42)
def test_many_dependencies(self):
# a
# /|\
# / | \
# b c d
a = self._action("a")
b = self._action("b")
c = self._action("c")
d = self._action("d")
a.add_dependency(b)
a.add_dependency(c)
a.add_dependency(d)
execute(a, cpu_cores=1)
self.assertEventsEqual("bcd a")
def test_deep_dependencies(self):
# a
# |
# b
# |
# c
# |
# d
# |
# e
# |
# f
a = self._action("a")
b = self._action("b")
c = self._action("c")
d = self._action("d")
e = self._action("e")
f = self._action("f")
a.add_dependency(b)
b.add_dependency(c)
c.add_dependency(d)
d.add_dependency(e)
e.add_dependency(f)
execute(a, cpu_cores=1)
self.assertEventsEqual("f e d c b a")
def test_diamond_dependencies(self):
# a
# / \
# b c
# \ /
# d
a = self._action("a")
b = self._action("b")
c = self._action("c")
d = self._action("d")
a.add_dependency(b)
a.add_dependency(c)
b.add_dependency(d)
c.add_dependency(d)
execute(a, cpu_cores=1)
self.assertEventsEqual("d bc a")
def test_half_diamond_dependency(self):
# a
# /|
# b |
# \|
# d
a = self._action("a")
b = self._action("b")
d = self._action("d")
a.add_dependency(b)
a.add_dependency(d)
b.add_dependency(d)
execute(a, cpu_cores=1)
self.assertEventsEqual("d b a")
def test_two_deep_branches(self):
# a
# / \
# b c
# | |
# d e
a = self._action("a")
b = self._action("b")
c = self._action("c")
d = self._action("d")
e = self._action("e")
a.add_dependency(b)
a.add_dependency(c)
b.add_dependency(d)
c.add_dependency(e)
execute(a, cpu_cores=1)
self.assertEventsIn([
# Leaves first
["d", "e", "b", "c", "a"],
["e", "d", "b", "c", "a"],
["d", "e", "c", "b", "a"],
["e", "d", "c", "b", "a"],
# Full branch first
["d", "b", "e", "c", "a"],
["e", "c", "d", "b", "a"],
# Leave, then full branch
["e", "d", "b", "c", "a"],
["d", "e", "c", "b", "a"],
])
def test_limited_resource_doesnt_block_execution(self):
a = self._action("a")
a.require_resource(CPU_CORE, 10)
report = execute(a, cpu_cores=1)
self.assertTrue(report.is_success)