Skip to content

Commit 7c0096d

Browse files
committed
feat: add a PoolCE test to check the result of a failed submission
1 parent e17f3f8 commit 7c0096d

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

src/DIRAC/Resources/Computing/test/Test_PoolComputingElement.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pytest
99

1010
# sut
11+
from DIRAC import S_ERROR
1112
from DIRAC.Resources.Computing.PoolComputingElement import PoolComputingElement
1213

1314
jobScript = """#!/usr/bin/env python
@@ -29,6 +30,15 @@
2930
print("End job", jobNumber, time.time())
3031
"""
3132

33+
badJobScript = """#!/usr/bin/env python
34+
35+
import sys
36+
import time
37+
38+
time.sleep(2)
39+
sys.exit(-5)
40+
"""
41+
3242

3343
def _stopJob(nJob):
3444
with open(f"stop_job_{nJob}", "w") as stopFile:
@@ -45,6 +55,10 @@ def createAndDelete():
4555
execFile.write(jobScript % i)
4656
os.chmod(f"testPoolCEJob_{i}.py", 0o755)
4757

58+
with open("testBadPoolCEJob.py", "w") as execFile:
59+
execFile.write(badJobScript)
60+
os.chmod("testBadPoolCEJob.py", 0o755)
61+
4862
yield createAndDelete
4963

5064
# from here on is teardown
@@ -60,6 +74,7 @@ def createAndDelete():
6074
for i in range(6):
6175
try:
6276
os.remove(f"testPoolCEJob_{i}.py")
77+
os.remove("testBadPoolCEJob.py")
6378
except OSError:
6479
pass
6580

@@ -81,6 +96,49 @@ def test_submit_and_shutdown(createAndDelete):
8196
assert list(result["Value"].values())[0]["OK"] is True
8297

8398

99+
@pytest.mark.slow
100+
@pytest.mark.parametrize(
101+
"script, ceSubmissionFailure, expected",
102+
[
103+
# The script is fine, but the InProcess submission is going to fail
104+
("testPoolCEJob_0.py", True, False),
105+
# The script is wrong, but the InProcess submission will be fine
106+
("testBadPoolCEJob.py", False, False),
107+
],
108+
)
109+
def test_submitBadJobs_and_getResult(mocker, createAndDelete, script, ceSubmissionFailure, expected):
110+
"""Consists in testing failures during the submission process or the job execution"""
111+
# Mocker configuration
112+
# Only enabled if ceSubmissionFailure is True
113+
proxy = None
114+
if ceSubmissionFailure:
115+
mocker.patch(
116+
"DIRAC.Resources.Computing.ComputingElement.ComputingElement.writeProxyToFile",
117+
return_value=S_ERROR("Unexpected failure"),
118+
)
119+
proxy = "any value to go in the branch that will fail the submission"
120+
121+
time.sleep(0.5)
122+
123+
ceParameters = {"WholeNode": True, "NumberOfProcessors": 4}
124+
ce = PoolComputingElement("TestPoolCE")
125+
ce.setParameters(ceParameters)
126+
result = ce.submitJob(script, proxy=proxy)
127+
128+
# The PoolCE always return S_OK
129+
# It cannot capture failures occurring during the submission or after
130+
# because it is asynchronous
131+
assert result["OK"] is True
132+
133+
# Waiting for the results of the submission/execution of the script
134+
while not ce.taskResults:
135+
time.sleep(0.1)
136+
137+
# Test the results
138+
for _, result in ce.taskResults.items():
139+
assert result["OK"] == expected
140+
141+
84142
def test_executeJob_wholeNode4(createAndDelete):
85143
time.sleep(0.5)
86144

0 commit comments

Comments
 (0)