8
8
import pytest
9
9
10
10
# sut
11
+ from DIRAC import S_ERROR
11
12
from DIRAC .Resources .Computing .PoolComputingElement import PoolComputingElement
12
13
13
14
jobScript = """#!/usr/bin/env python
29
30
print("End job", jobNumber, time.time())
30
31
"""
31
32
33
+ badJobScript = """#!/usr/bin/env python
34
+
35
+ import sys
36
+ import time
37
+
38
+ time.sleep(2)
39
+ sys.exit(-5)
40
+ """
41
+
32
42
33
43
def _stopJob (nJob ):
34
44
with open (f"stop_job_{ nJob } " , "w" ) as stopFile :
@@ -45,6 +55,10 @@ def createAndDelete():
45
55
execFile .write (jobScript % i )
46
56
os .chmod (f"testPoolCEJob_{ i } .py" , 0o755 )
47
57
58
+ with open ("testBadPoolCEJob.py" , "w" ) as execFile :
59
+ execFile .write (badJobScript )
60
+ os .chmod ("testBadPoolCEJob.py" , 0o755 )
61
+
48
62
yield createAndDelete
49
63
50
64
# from here on is teardown
@@ -60,6 +74,7 @@ def createAndDelete():
60
74
for i in range (6 ):
61
75
try :
62
76
os .remove (f"testPoolCEJob_{ i } .py" )
77
+ os .remove ("testBadPoolCEJob.py" )
63
78
except OSError :
64
79
pass
65
80
@@ -81,6 +96,49 @@ def test_submit_and_shutdown(createAndDelete):
81
96
assert list (result ["Value" ].values ())[0 ]["OK" ] is True
82
97
83
98
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
+
84
142
def test_executeJob_wholeNode4 (createAndDelete ):
85
143
time .sleep (0.5 )
86
144
0 commit comments