|
1
|
|
|
# coding: utf8 |
|
2
|
|
|
|
|
3
|
|
|
# Copyright 2013-2017 Vincent Jacques <[email protected]> |
|
4
|
|
|
|
|
5
|
|
|
from __future__ import division, absolute_import, print_function |
|
6
|
|
|
|
|
7
|
|
|
from ActionTree import * |
|
8
|
|
|
from . import * |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class ExecutionTestCase(ActionTreeTestCase): |
|
12
|
|
|
def test_simple_execution(self): |
|
13
|
|
|
a = self._action("a", return_value=42) |
|
14
|
|
|
|
|
15
|
|
|
report = execute(a, cpu_cores=1) |
|
16
|
|
|
|
|
17
|
|
|
self.assertTrue(report.is_success) |
|
18
|
|
|
self.assertEqual(report.get_action_status(a).status, SUCCESSFUL) |
|
19
|
|
|
self.assertEqual(report.get_action_status(a).return_value, 42) |
|
20
|
|
|
|
|
21
|
|
|
def test_many_dependencies(self): |
|
22
|
|
|
# a |
|
23
|
|
|
# /|\ |
|
24
|
|
|
# / | \ |
|
25
|
|
|
# b c d |
|
26
|
|
|
|
|
27
|
|
|
a = self._action("a") |
|
28
|
|
|
b = self._action("b") |
|
29
|
|
|
c = self._action("c") |
|
30
|
|
|
d = self._action("d") |
|
31
|
|
|
a.add_dependency(b) |
|
32
|
|
|
a.add_dependency(c) |
|
33
|
|
|
a.add_dependency(d) |
|
34
|
|
|
|
|
35
|
|
|
execute(a, cpu_cores=1) |
|
36
|
|
|
|
|
37
|
|
|
self.assertEventsEqual("bcd a") |
|
38
|
|
|
|
|
39
|
|
|
def test_deep_dependencies(self): |
|
40
|
|
|
# a |
|
41
|
|
|
# | |
|
42
|
|
|
# b |
|
43
|
|
|
# | |
|
44
|
|
|
# c |
|
45
|
|
|
# | |
|
46
|
|
|
# d |
|
47
|
|
|
# | |
|
48
|
|
|
# e |
|
49
|
|
|
# | |
|
50
|
|
|
# f |
|
51
|
|
|
|
|
52
|
|
|
a = self._action("a") |
|
53
|
|
|
b = self._action("b") |
|
54
|
|
|
c = self._action("c") |
|
55
|
|
|
d = self._action("d") |
|
56
|
|
|
e = self._action("e") |
|
57
|
|
|
f = self._action("f") |
|
58
|
|
|
a.add_dependency(b) |
|
59
|
|
|
b.add_dependency(c) |
|
60
|
|
|
c.add_dependency(d) |
|
61
|
|
|
d.add_dependency(e) |
|
62
|
|
|
e.add_dependency(f) |
|
63
|
|
|
|
|
64
|
|
|
execute(a, cpu_cores=1) |
|
65
|
|
|
|
|
66
|
|
|
self.assertEventsEqual("f e d c b a") |
|
67
|
|
|
|
|
68
|
|
|
def test_diamond_dependencies(self): |
|
69
|
|
|
# a |
|
70
|
|
|
# / \ |
|
71
|
|
|
# b c |
|
72
|
|
|
# \ / |
|
73
|
|
|
# d |
|
74
|
|
|
|
|
75
|
|
|
a = self._action("a") |
|
76
|
|
|
b = self._action("b") |
|
77
|
|
|
c = self._action("c") |
|
78
|
|
|
d = self._action("d") |
|
79
|
|
|
a.add_dependency(b) |
|
80
|
|
|
a.add_dependency(c) |
|
81
|
|
|
b.add_dependency(d) |
|
82
|
|
|
c.add_dependency(d) |
|
83
|
|
|
|
|
84
|
|
|
execute(a, cpu_cores=1) |
|
85
|
|
|
|
|
86
|
|
|
self.assertEventsEqual("d bc a") |
|
87
|
|
|
|
|
88
|
|
|
def test_half_diamond_dependency(self): |
|
89
|
|
|
# a |
|
90
|
|
|
# /| |
|
91
|
|
|
# b | |
|
92
|
|
|
# \| |
|
93
|
|
|
# d |
|
94
|
|
|
|
|
95
|
|
|
a = self._action("a") |
|
96
|
|
|
b = self._action("b") |
|
97
|
|
|
d = self._action("d") |
|
98
|
|
|
a.add_dependency(b) |
|
99
|
|
|
a.add_dependency(d) |
|
100
|
|
|
b.add_dependency(d) |
|
101
|
|
|
|
|
102
|
|
|
execute(a, cpu_cores=1) |
|
103
|
|
|
|
|
104
|
|
|
self.assertEventsEqual("d b a") |
|
105
|
|
|
|
|
106
|
|
|
def test_two_deep_branches(self): |
|
107
|
|
|
# a |
|
108
|
|
|
# / \ |
|
109
|
|
|
# b c |
|
110
|
|
|
# | | |
|
111
|
|
|
# d e |
|
112
|
|
|
|
|
113
|
|
|
a = self._action("a") |
|
114
|
|
|
b = self._action("b") |
|
115
|
|
|
c = self._action("c") |
|
116
|
|
|
d = self._action("d") |
|
117
|
|
|
e = self._action("e") |
|
118
|
|
|
a.add_dependency(b) |
|
119
|
|
|
a.add_dependency(c) |
|
120
|
|
|
b.add_dependency(d) |
|
121
|
|
|
c.add_dependency(e) |
|
122
|
|
|
|
|
123
|
|
|
execute(a, cpu_cores=1) |
|
124
|
|
|
|
|
125
|
|
|
self.assertEventsIn([ |
|
126
|
|
|
# Leaves first |
|
127
|
|
|
["d", "e", "b", "c", "a"], |
|
128
|
|
|
["e", "d", "b", "c", "a"], |
|
129
|
|
|
["d", "e", "c", "b", "a"], |
|
130
|
|
|
["e", "d", "c", "b", "a"], |
|
131
|
|
|
# Full branch first |
|
132
|
|
|
["d", "b", "e", "c", "a"], |
|
133
|
|
|
["e", "c", "d", "b", "a"], |
|
134
|
|
|
# Leave, then full branch |
|
135
|
|
|
["e", "d", "b", "c", "a"], |
|
136
|
|
|
["d", "e", "c", "b", "a"], |
|
137
|
|
|
]) |
|
138
|
|
|
|
|
139
|
|
|
def test_limited_resource_doesnt_block_execution(self): |
|
140
|
|
|
a = self._action("a") |
|
141
|
|
|
a.require_resource(CPU_CORE, 10) |
|
142
|
|
|
|
|
143
|
|
|
report = execute(a, cpu_cores=1) |
|
144
|
|
|
|
|
145
|
|
|
self.assertTrue(report.is_success) |
|
146
|
|
|
|