forked from It4innovations/hyperqueue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_array.py
More file actions
226 lines (176 loc) · 7.41 KB
/
test_array.py
File metadata and controls
226 lines (176 loc) · 7.41 KB
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
import collections
import datetime
import os
import time
from .conftest import HqEnv
from .utils import wait_for_job_state
from .utils.io import check_file_contents
from .utils.job import default_task_output, list_jobs
def test_job_array_submit(hq_env: HqEnv):
hq_env.start_server()
hq_env.start_worker(cpus=4)
hq_env.command(["submit", "--array=30-36", "--", "bash", "-c", "echo $HQ_JOB_ID-$HQ_TASK_ID"])
wait_for_job_state(hq_env, 1, "FINISHED")
for i in list(range(0, 30)) + list(range(37, 40)):
assert not os.path.isfile(os.path.join(hq_env.work_path, default_task_output(job_id=1, task_id=i)))
assert not os.path.isfile(
os.path.join(
hq_env.work_path,
default_task_output(job_id=1, task_id=i, type="stderr"),
)
)
for i in range(36, 37):
stdout = os.path.join(hq_env.work_path, default_task_output(job_id=1, task_id=i))
assert os.path.isfile(stdout)
assert os.path.isfile(
os.path.join(
hq_env.work_path,
default_task_output(job_id=1, task_id=i, type="stderr"),
)
)
check_file_contents(stdout, f"1-{i}\n")
def test_job_array_report(hq_env: HqEnv):
hq_env.start_server()
hq_env.start_worker(cpus=4)
hq_env.command(["submit", "--array=10-19", "--", "sleep", "1"])
time.sleep(1.6)
table = list_jobs(hq_env)
table.check_column_value("State", 0, "RUNNING")
table = hq_env.command(["job", "info", "1"])
print(table)
table = hq_env.command(["job", "info", "1"], as_table=True)
table.check_row_value("Tasks", "10; Ids: 10-19")
states = table.get_row_value("State").split("\n")
assert "RUNNING (4)" in states
assert "FINISHED (4)" in states
assert "WAITING (2)" in states
time.sleep(1.6)
table = hq_env.command(["job", "info", "1"], as_table=True)
assert table.get_row_value("State").split("\n")[-1] == "FINISHED (10)"
def test_job_array_error_some(hq_env: HqEnv):
hq_env.start_server()
hq_env.command(
[
"submit",
"--array=0-9",
"--",
"python3",
"-c",
"import os; assert os.environ['HQ_TASK_ID'] not in ['2', '3', '7']",
]
)
hq_env.start_worker(cpus=2)
wait_for_job_state(hq_env, 1, "FAILED")
table = list_jobs(hq_env)
table.check_column_value("State", 0, "FAILED")
table = hq_env.command(["job", "info", "1"], as_table=True)
states = table[0].get_row_value("State").split("\n")
assert "FAILED (3)" in states
assert "FINISHED (7)" in states
table = table[1]
assert table.header == ["Task ID", "Worker", "Error"]
assert table.get_column_value("Task ID")[0] == "2"
assert table.get_column_value("Error")[0] == "Program terminated with exit code 1."
assert table.get_column_value("Task ID")[1] == "3"
assert table.get_column_value("Error")[1] == "Program terminated with exit code 1."
assert table.get_column_value("Task ID")[2] == "7"
assert table.get_column_value("Error")[2] == "Program terminated with exit code 1."
table = hq_env.command(["task", "list", "1"], as_table=True)
for i, state in enumerate(
[
"FINISHED",
"FINISHED",
"FAILED",
"FAILED",
"FINISHED",
"FINISHED",
"FINISHED",
"FAILED",
]
+ 2 * ["FINISHED"]
):
table.check_column_value("State", i, state)
def test_job_array_error_all(hq_env: HqEnv):
hq_env.start_server()
hq_env.command(["submit", "--array=0-9", "--", "/non-existent"])
hq_env.start_worker(cpus=2)
wait_for_job_state(hq_env, 1, "FAILED")
table = list_jobs(hq_env)
table.check_column_value("State", 0, "FAILED")
table = hq_env.command(["job", "info", "1"], as_table=True)
states = table[0].get_row_value("State").split("\n")
assert "FAILED (10)" in states
errors = table[1].as_horizontal().get_column_value("Error")
for error in errors:
assert "No such file or directory" in error
table = hq_env.command(["job", "info", "1"], as_table=True)
states = table[0].get_row_value("State").split("\n")
assert "FAILED (10)" in states
task_table = hq_env.command(["task", "list", "1", "-v"], as_table=True)
for i in range(10):
assert task_table.get_column_value("Task ID")[i] == str(i)
assert task_table.get_column_value("State")[i] == "FAILED"
assert "No such file or directory" in task_table.get_column_value("Error")[i]
def test_job_array_cancel(hq_env: HqEnv):
hq_env.start_server()
hq_env.start_worker(cpus=4)
hq_env.command(["submit", "--array=0-9", "--", "sleep", "1"])
time.sleep(1.6)
hq_env.command(["job", "cancel", "1"])
time.sleep(0.4)
table = hq_env.command(["job", "info", "1"], as_table=True)
states = table.get_row_value("State").split("\n")
assert "FINISHED (4)" in states
assert "CANCELED (6)" in states
table = hq_env.command(["task", "list", "1"], as_table=True)
task_states = table.get_column_value("State")
c = collections.Counter(task_states)
assert c.get("FINISHED") == 4
assert c.get("CANCELED") == 6
table = list_jobs(hq_env)
table.check_column_value("State", 0, "CANCELED")
def test_array_reporting_state_after_worker_lost(hq_env: HqEnv):
hq_env.start_server()
hq_env.start_workers(1, cpus=2)
hq_env.command(["submit", "--array=1-4", "sleep", "1"])
time.sleep(0.25)
hq_env.kill_worker(1)
time.sleep(0.25)
table = hq_env.command(["job", "info", "1"], as_table=True)
assert "WAITING (4)" in table.get_row_value("State").split("\n")
table = hq_env.command(["task", "list", "1"], as_table=True)
task_states = table.get_column_value("State")
c = collections.Counter(task_states)
assert c.get("WAITING") == 4
hq_env.start_workers(1, cpus=2)
time.sleep(2.2)
table = hq_env.command(["job", "info", "1"], as_table=True)
assert "FINISHED (4)" in table.get_row_value("State").split("\n")
table = hq_env.command(["task", "list", "1"], as_table=True)
task_states = table.get_column_value("State")
c = collections.Counter(task_states)
assert c.get("FINISHED") == 4
def test_array_mix_with_simple_jobs(hq_env: HqEnv):
hq_env.start_server()
for i in range(100):
hq_env.command(["submit", "--array=1-4", "uname"])
hq_env.command(["submit", "uname"])
hq_env.start_workers(1, cpus=2)
wait_for_job_state(hq_env, list(range(1, 101)), "FINISHED")
table = list_jobs(hq_env)
for i in range(100):
assert table.get_column_value("ID")[i] == str(i + 1)
assert table.get_column_value("State")[i] == "FINISHED"
assert table.get_column_value("Tasks")[i] == "4" if i % 2 == 0 else "1"
def test_array_times(hq_env: HqEnv):
hq_env.start_server()
hq_env.start_worker()
hq_env.command(["submit", "--array=1-3", "sleep", "1"])
wait_for_job_state(hq_env, 1, "FINISHED")
time.sleep(1.2) # This sleep is not redundant, we check that after finished time is not moving
for i in range(1, 4):
table = hq_env.command(["task", "info", "1", str(i)], as_table=True)
start = datetime.datetime.strptime(table.get_row_value("Start"), "%d.%m.%Y %H:%M:%S")
end = datetime.datetime.strptime(table.get_row_value("End"), "%d.%m.%Y %H:%M:%S")
seconds = (end - start).total_seconds()
assert 0.9 <= seconds <= 1.1