Skip to content

Commit 6e11057

Browse files
authored
Merge pull request #8292 from chrisburr/faster-ci
[9.0] Optimise tests for faster CI/pytest
2 parents 7c84335 + 5983dba commit 6e11057

File tree

8 files changed

+41
-8
lines changed

8 files changed

+41
-8
lines changed

src/DIRAC/RequestManagementSystem/DB/test/RMSTestScenari.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# pylint: disable=invalid-name,wrong-import-position
77
import time
88

9+
import pytest
910

1011
from DIRAC.RequestManagementSystem.Client.Request import Request
1112
from DIRAC.RequestManagementSystem.Client.Operation import Operation
@@ -42,6 +43,7 @@ def test_stress(reqDB):
4243
assert delete["OK"], delete
4344

4445

46+
@pytest.mark.slow
4547
def test_stressBulk(reqDB):
4648
"""stress test bulk"""
4749

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
if os.path.isfile(stopFile):
2626
os.remove(stopFile)
2727
break
28-
if (time.time() - start) > 30:
28+
if (time.time() - start) > 5:
2929
break
3030
print("End job", jobNumber, time.time())
3131
"""
@@ -262,6 +262,7 @@ def test_executeJob_wholeNode8(createAndDelete):
262262
assert "Not enough processors" in submissionResult["Message"]
263263

264264

265+
@pytest.mark.slow
265266
def test_executeJob_submitAndStop(createAndDelete):
266267
time.sleep(0.5)
267268

src/DIRAC/Workflow/Modules/test/Test_Modules.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import copy
66
import shutil
77

8+
import pytest
9+
810
from unittest.mock import MagicMock as Mock
911

1012
from DIRAC import gLogger
@@ -742,6 +744,7 @@ def test_execute(self):
742744
class ScriptSuccess(ModulesTestCase):
743745
#################################################
744746

747+
@pytest.mark.slow
745748
def test_execute(self):
746749
self.script.jobType = "merge"
747750
self.script.stepInputData = ["foo", "bar"]
@@ -770,6 +773,7 @@ def test_execute(self):
770773
class ScriptUnicode(ModulesTestCase):
771774
#################################################
772775

776+
@pytest.mark.slow
773777
def test_execute(self):
774778
self.script.jobType = "merge"
775779
self.script.stepInputData = ["foo", "bar"]
@@ -799,6 +803,7 @@ def test_execute(self):
799803
class ScriptFailure(ModulesTestCase):
800804
#################################################
801805

806+
@pytest.mark.slow
802807
def test_execute(self):
803808
self.script.jobType = "merge"
804809
self.script.stepInputData = ["foo", "bar"]

src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_JobAgent.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ def test__checkMatcherInfo(mocker, matcherInfo, matcherParams, expectedResult):
260260
#############################################################################
261261

262262

263+
@pytest.mark.slow
263264
@pytest.mark.parametrize(
264265
"mockGCReply, mockPMReply, expected",
265266
[
@@ -308,6 +309,7 @@ def test__setupProxy(mocker, mockGCReply, mockPMReply, expected):
308309
assert result["Message"] == expected["Message"]
309310

310311

312+
@pytest.mark.slow
311313
@pytest.mark.parametrize(
312314
"mockGCReply, mockPMReply, expected",
313315
[

src/DIRAC/WorkloadManagementSystem/Agent/test/Test_Agent_PushJobAgent.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def jobID():
178178
shutil.rmtree(jobID)
179179

180180

181+
@pytest.mark.slow
181182
def test_submitJobWrapper(mocker, jobID):
182183
"""Test JobAgent._submitJobWrapper()"""
183184
mocker.patch("DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__")

src/DIRAC/WorkloadManagementSystem/JobWrapper/JobWrapper.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
from DIRAC.WorkloadManagementSystem.Client.SandboxStoreClient import SandboxStoreClient
5656
from DIRAC.WorkloadManagementSystem.JobWrapper.Watchdog import Watchdog
5757

58+
CHILD_PID_POLL_INTERVALS = list(range(5, 40, 5))
59+
5860

5961
class JobWrapper:
6062
"""The only user of the JobWrapper is the JobWrapperTemplate"""
@@ -430,14 +432,14 @@ def process(self, command: str, env: dict):
430432
)
431433
exeThread.start()
432434
payloadPID = None
433-
for seconds in range(5, 40, 5):
435+
for seconds in CHILD_PID_POLL_INTERVALS:
434436
time.sleep(seconds)
435437
payloadPID = spObject.getChildPID()
436438
if payloadPID:
437439
self.__setJobParam("PayloadPID", payloadPID)
438440
break
439441
if not payloadPID:
440-
return S_ERROR("Payload process could not start after 140 seconds")
442+
return S_ERROR(f"Payload process could not start after {sum(CHILD_PID_POLL_INTERVALS)} seconds")
441443

442444
watchdog = Watchdog(
443445
pid=self.currentPID,

src/DIRAC/WorkloadManagementSystem/JobWrapper/test/Test_JobWrapper.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,24 +344,40 @@ def test_processQuickExecutionNoWatchdog(mocker):
344344

345345

346346
@pytest.mark.slow
347-
def test_processSubprocessFailureNoPid(mocker):
348-
"""Test the process method of the JobWrapper class: the subprocess fails and no PID is returned."""
347+
@pytest.mark.parametrize("expect_failure", [True, False])
348+
def test_processSubprocessFailureNoPid(mocker, monkeypatch, expect_failure):
349+
"""Test the process method of the JobWrapper class: the subprocess fails and no PID is returned.
350+
351+
expect_failure is used to ensure that the JobWrapper is functioning correctly even with the other patching
352+
that is applied in the test (e.g. CHILD_PID_POLL_INTERVALS).
353+
"""
349354
# Test failure in starting the payload process
350355
jw = JobWrapper()
351356
jw.jobArgs = {}
352357

353358
mocker.patch.object(jw, "_JobWrapper__report")
354359
mocker.patch.object(jw, "_JobWrapper__setJobParam")
360+
monkeypatch.setattr(
361+
"DIRAC.WorkloadManagementSystem.JobWrapper.JobWrapper.CHILD_PID_POLL_INTERVALS", [0.1, 0.2, 0.3, 0.4, 0.5]
362+
)
363+
355364
mock_exeThread = mocker.Mock()
356365
mock_exeThread.start.side_effect = lambda: time.sleep(0.1)
357-
mocker.patch("DIRAC.WorkloadManagementSystem.JobWrapper.JobWrapper.ExecutionThread", return_value=mock_exeThread)
366+
if expect_failure:
367+
mocker.patch(
368+
"DIRAC.WorkloadManagementSystem.JobWrapper.JobWrapper.ExecutionThread", return_value=mock_exeThread
369+
)
358370

359371
with tempfile.NamedTemporaryFile(delete=True) as std_out, tempfile.NamedTemporaryFile(delete=True) as std_err:
360372
jw.outputFile = std_out.name
361373
jw.errorFile = std_err.name
362374
result = jw.process(command="mock_command", env={})
363-
assert not result["OK"]
364-
assert "Payload process could not start after 140 seconds" in result["Message"]
375+
376+
if expect_failure:
377+
assert not result["OK"]
378+
assert "Payload process could not start after 1.5 seconds" in result["Message"]
379+
else:
380+
assert result["OK"]
365381

366382

367383
# -------------------------------------------------------------------------------------------------

src/DIRAC/WorkloadManagementSystem/JobWrapper/test/Test_JobWrapperTemplate.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def extraOptions():
7272
os.remove(extraOptions)
7373

7474

75+
@pytest.mark.slow
7576
def test_createAndExecuteJobWrapperTemplate_success(extraOptions):
7677
"""Test the creation of a classical job wrapper and its execution:
7778
There is an extra option cfg file to be passed to the job wrapper.
@@ -144,6 +145,7 @@ def test_createAndExecuteJobWrapperTemplate_success(extraOptions):
144145
shutil.rmtree(os.path.join(os.getcwd(), "job"))
145146

146147

148+
@pytest.mark.slow
147149
def test_createAndExecuteJobWrapperTemplate_missingExtraOptions():
148150
"""Test the creation of a classical job wrapper and its execution:
149151
There is no extra options to be passed to the job wrapper.
@@ -205,6 +207,7 @@ def test_createAndExecuteJobWrapperTemplate_missingExtraOptions():
205207
shutil.rmtree(os.path.join(os.getcwd(), "job"))
206208

207209

210+
@pytest.mark.slow
208211
def test_createAndExecuteRelocatedJobWrapperTemplate_success(extraOptions):
209212
"""Test the creation of a relocated job wrapper and its execution:
210213
This is generally used when containers are involved (SingularityCE).
@@ -325,6 +328,7 @@ def test_createAndExecuteRelocatedJobWrapperTemplate_success(extraOptions):
325328
shutil.rmtree(wrapperPath)
326329

327330

331+
@pytest.mark.slow
328332
def test_createAndExecuteJobWrapperOfflineTemplate_success(extraOptions):
329333
"""Test the creation of an offline job wrapper and its execution:
330334
This is generally used when pre/post processing operations are executed locally,

0 commit comments

Comments
 (0)