Skip to content

Commit

Permalink
feat: add a PoolCE test to check the result of a failed submission
Browse files Browse the repository at this point in the history
  • Loading branch information
aldbr committed Apr 13, 2023
1 parent b65cb3d commit bcb95bc
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/DIRAC/Resources/Computing/test/Test_PoolComputingElement.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import pytest

# sut
from DIRAC import S_ERROR
from DIRAC.Resources.Computing.PoolComputingElement import PoolComputingElement

jobScript = """#!/usr/bin/env python
Expand All @@ -36,6 +37,15 @@
print("End job", jobNumber, time.time())
"""

badJobScript = """#!/usr/bin/env python
import sys
import time
time.sleep(2)
sys.exit(-5)
"""


def _stopJob(nJob):
with open("stop_job_%s" % nJob, "w") as stopFile:
Expand All @@ -52,6 +62,10 @@ def createAndDelete():
execFile.write(jobScript % i)
os.chmod("testPoolCEJob_%s.py" % i, 0o755)

with open("testBadPoolCEJob.py", "w") as execFile:
execFile.write(badJobScript)
os.chmod("testBadPoolCEJob.py", 0o755)

yield createAndDelete

# from here on is teardown
Expand All @@ -67,6 +81,7 @@ def createAndDelete():
for i in range(6):
try:
os.remove("testPoolCEJob_%s.py" % i)
os.remove("testBadPoolCEJob.py")
except OSError:
pass

Expand All @@ -89,6 +104,49 @@ def test_submit_and_shutdown(createAndDelete):
assert list(result["Value"].values())[0]["OK"] is True


@pytest.mark.slow
@pytest.mark.parametrize(
"script, ceSubmissionFailure, expected",
[
# The script is fine, but the InProcess submission is going to fail
("testPoolCEJob_0.py", True, False),
# The script is wrong, but the InProcess submission will be fine
("testBadPoolCEJob.py", False, False),
],
)
def test_submitBadJobs_and_getResult(mocker, createAndDelete, script, ceSubmissionFailure, expected):
"""Consists in testing failures during the submission process or the job execution"""
# Mocker configuration
# Only enabled if ceSubmissionFailure is True
proxy = None
if ceSubmissionFailure:
mocker.patch(
"DIRAC.Resources.Computing.ComputingElement.ComputingElement.writeProxyToFile",
return_value=S_ERROR("Unexpected failure"),
)
proxy = "any value to go in the branch that will fail the submission"

time.sleep(0.5)

ceParameters = {"WholeNode": True, "NumberOfProcessors": 4}
ce = PoolComputingElement("TestPoolCE")
ce.setParameters(ceParameters)
result = ce.submitJob(script, proxy=proxy)

# The PoolCE always return S_OK
# It cannot capture failures occurring during the submission or after
# because it is asynchronous
assert result["OK"] is True

# Waiting for the results of the submission/execution of the script
while not ce.taskResults:
time.sleep(0.1)

# Test the results
for _, result in ce.taskResults.items():
assert result["OK"] == expected


def test_executeJob_wholeNode4(createAndDelete):

time.sleep(0.5)
Expand Down

0 comments on commit bcb95bc

Please sign in to comment.