From bcb95bc6111e75d80b18f0e9fd25add3460eadcd Mon Sep 17 00:00:00 2001 From: aldbr Date: Thu, 13 Apr 2023 18:33:55 +0200 Subject: [PATCH] feat: add a PoolCE test to check the result of a failed submission --- .../test/Test_PoolComputingElement.py | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/DIRAC/Resources/Computing/test/Test_PoolComputingElement.py b/src/DIRAC/Resources/Computing/test/Test_PoolComputingElement.py index 8d86f5b2c74..a45084e848d 100644 --- a/src/DIRAC/Resources/Computing/test/Test_PoolComputingElement.py +++ b/src/DIRAC/Resources/Computing/test/Test_PoolComputingElement.py @@ -12,6 +12,7 @@ import pytest # sut +from DIRAC import S_ERROR from DIRAC.Resources.Computing.PoolComputingElement import PoolComputingElement jobScript = """#!/usr/bin/env python @@ -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: @@ -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 @@ -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 @@ -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)