Skip to content

Commit 20f870d

Browse files
committed
changing tests, so the execution time is only checked for unix and cf (windows and slurm/dask can spend a lot of time to create directory etc. and how to set a good check)
1 parent 677d3dd commit 20f870d

File tree

2 files changed

+128
-53
lines changed

2 files changed

+128
-53
lines changed

pydra/engine/tests/test_workflow.py

Lines changed: 127 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
import shutil, os
2+
import shutil, os, sys
33
import time
44
import attr
55
from pathlib import Path
@@ -2070,9 +2070,11 @@ def test_wf_nostate_cachelocations(plugin, tmpdir):
20702070
results2 = wf2.result()
20712071
assert 8 == results2.output.out
20722072

2073-
# checking execution time
2074-
assert t1 > 3
2075-
assert t2 < 0.5
2073+
# checking execution time (for unix and cf)
2074+
# for win and dask/slurm the time for dir creation etc. might take much longer
2075+
if sys.platform.startswith("win") and plugin == "cf":
2076+
assert t1 > 2
2077+
assert t2 < 0.5
20762078

20772079
# checking if the second wf didn't run again
20782080
assert wf1.output_dir.exists()
@@ -2125,10 +2127,12 @@ def test_wf_nostate_cachelocations_a(plugin, tmpdir):
21252127
results2 = wf2.result()
21262128
assert 8 == results2.output.out
21272129

2128-
# checking execution time (second one should be quick)
2129-
assert t1 > 3
2130-
# testing relative values (windows or slurm takes much longer to create wf itself)
2131-
assert t2 / t1 < 0.9
2130+
# for win and dask/slurm the time for dir creation etc. might take much longer
2131+
if sys.platform.startswith("win") and plugin == "cf":
2132+
# checking execution time (second one should be quick)
2133+
assert t1 > 2
2134+
# testing relative values (windows or slurm takes much longer to create wf itself)
2135+
assert t2 < 0.5
21322136

21332137
# checking if both wf.output_dir are created
21342138
assert wf1.output_dir.exists()
@@ -2184,9 +2188,11 @@ def test_wf_nostate_cachelocations_b(plugin, tmpdir):
21842188
results2 = wf2.result()
21852189
assert 8 == results2.output.out == results2.output.out_pr
21862190

2187-
# checking execution time
2188-
assert t1 > 3
2189-
assert t2 / t1 < 0.9
2191+
# for win and dask/slurm the time for dir creation etc. might take much longer
2192+
if sys.platform.startswith("win") and plugin == "cf":
2193+
# checking execution time
2194+
assert t1 > 2
2195+
assert t2 < 0.5
21902196

21912197
# checking if the second wf didn't run again
21922198
assert wf1.output_dir.exists()
@@ -2240,10 +2246,12 @@ def test_wf_nostate_cachelocations_setoutputchange(plugin, tmpdir):
22402246
results2 = wf2.result()
22412247
assert 8 == results2.output.out2
22422248

2243-
# checking execution time (the second wf should be fast, nodes do not have to rerun)
2244-
assert t1 > 3
2245-
# testing relative values (windows or slurm takes much longer to create wf itself)
2246-
assert t2 / t1 < 0.9
2249+
# for win and dask/slurm the time for dir creation etc. might take much longer
2250+
if sys.platform.startswith("win") and plugin == "cf":
2251+
# checking execution time (the second wf should be fast, nodes do not have to rerun)
2252+
assert t1 > 2
2253+
# testing relative values (windows or slurm takes much longer to create wf itself)
2254+
assert t2 < 0.5
22472255

22482256
# both wf output_dirs should be created
22492257
assert wf1.output_dir.exists()
@@ -2294,10 +2302,12 @@ def test_wf_nostate_cachelocations_setoutputchange_a(plugin, tmpdir):
22942302
results2 = wf2.result()
22952303
assert 8 == results2.output.out2
22962304

2297-
# checking execution time (the second wf should be fast, nodes do not have to rerun)
2298-
assert t1 > 3
2299-
# testing relative values (windows or slurm takes much longer to create wf itself)
2300-
assert t2 / t1 < 0.9
2305+
# for win and dask/slurm the time for dir creation etc. might take much longer
2306+
if sys.platform.startswith("win") and plugin == "cf":
2307+
# checking execution time (the second wf should be fast, nodes do not have to rerun)
2308+
assert t1 > 2
2309+
# testing relative values (windows or slurm takes much longer to create wf itself)
2310+
assert t2 < 0.5
23012311

23022312
# both wf output_dirs should be created
23032313
assert wf1.output_dir.exists()
@@ -2350,9 +2360,11 @@ def test_wf_nostate_cachelocations_forcererun(plugin, tmpdir):
23502360
results2 = wf2.result()
23512361
assert 8 == results2.output.out
23522362

2353-
# checking execution time
2354-
assert t1 > 3
2355-
assert t2 > 3
2363+
# for win and dask/slurm the time for dir creation etc. might take much longer
2364+
if sys.platform.startswith("win") and plugin == "cf":
2365+
# checking execution time
2366+
assert t1 > 2
2367+
assert t2 > 2
23562368

23572369
# checking if the second wf didn't run again
23582370
assert wf1.output_dir.exists()
@@ -2413,8 +2425,11 @@ def test_wf_nostate_cachelocations_wftaskrerun_propagateTrue(plugin, tmpdir):
24132425
# everything has to be recomputed
24142426
assert len(list(Path(cache_dir1).glob("F*"))) == 2
24152427
assert len(list(Path(cache_dir2).glob("F*"))) == 2
2416-
assert t1 > 3
2417-
assert t2 > 3
2428+
2429+
# for win and dask/slurm the time for dir creation etc. might take much longer
2430+
if sys.platform.startswith("win") and plugin == "cf":
2431+
assert t1 > 2
2432+
assert t2 > 2
24182433

24192434

24202435
def test_wf_nostate_cachelocations_wftaskrerun_propagateFalse(plugin, tmpdir):
@@ -2470,6 +2485,12 @@ def test_wf_nostate_cachelocations_wftaskrerun_propagateFalse(plugin, tmpdir):
24702485
assert wf1.output_dir.exists()
24712486
assert wf2.output_dir.exists()
24722487

2488+
# for win and dask/slurm the time for dir creation etc. might take much longer
2489+
if sys.platform.startswith("win") and plugin == "cf":
2490+
# checking the time
2491+
assert t1 > 2
2492+
assert t2 > 2
2493+
24732494
# tasks should not be recomputed
24742495
assert len(list(Path(cache_dir1).glob("F*"))) == 2
24752496
assert len(list(Path(cache_dir2).glob("F*"))) == 0
@@ -2524,14 +2545,17 @@ def test_wf_nostate_cachelocations_taskrerun_wfrerun_propagateFalse(plugin, tmpd
25242545
results2 = wf2.result()
25252546
assert 8 == results2.output.out
25262547

2548+
# for win and dask/slurm the time for dir creation etc. might take much longer
2549+
if sys.platform.startswith("win") and plugin == "cf":
2550+
# checking the execution time
2551+
assert t1 > 2
2552+
assert t2 > 2
25272553
# checking if the second wf doesn't runs again
25282554
assert wf1.output_dir.exists()
25292555
assert wf2.output_dir.exists()
25302556
# the second task should be recomputed
25312557
assert len(list(Path(cache_dir1).glob("F*"))) == 2
25322558
assert len(list(Path(cache_dir2).glob("F*"))) == 1
2533-
assert t1 > 3
2534-
assert t2 > 3
25352559

25362560

25372561
def test_wf_nostate_nodecachelocations(plugin, tmpdir):
@@ -2578,6 +2602,11 @@ def test_wf_nostate_nodecachelocations(plugin, tmpdir):
25782602
results2 = wf2.result()
25792603
assert 12 == results2.output.out
25802604

2605+
# for win and dask/slurm the time for dir creation etc. might take much longer
2606+
if sys.platform.startswith("win") and plugin == "cf":
2607+
# checking the execution time
2608+
assert t1 > 2
2609+
assert t2 > 2
25812610
# checking if the second wf runs again, but runs only one task
25822611
assert wf1.output_dir.exists()
25832612
assert wf2.output_dir.exists()
@@ -2627,6 +2656,11 @@ def test_wf_nostate_nodecachelocations_upd(plugin, tmpdir):
26272656
results2 = wf2.result()
26282657
assert 12 == results2.output.out
26292658

2659+
# for win and dask/slurm the time for dir creation etc. might take much longer
2660+
if sys.platform.startswith("win") and plugin == "cf":
2661+
# checking the execution time
2662+
assert t1 > 2
2663+
assert t2 > 2
26302664
# checking if the second wf runs again, but runs only one task
26312665
assert wf1.output_dir.exists()
26322666
assert wf2.output_dir.exists()
@@ -2684,9 +2718,11 @@ def test_wf_state_cachelocations(plugin, tmpdir):
26842718
assert results2[0].output.out == 8
26852719
assert results2[1].output.out == 82
26862720

2687-
# checking execution time
2688-
assert t1 > 3
2689-
assert t2 < 0.5
2721+
# for win and dask/slurm the time for dir creation etc. might take much longer
2722+
if sys.platform.startswith("win") and plugin == "cf":
2723+
# checking the execution time
2724+
assert t1 > 2
2725+
assert t2 < 0.5
26902726

26912727
# checking all directories
26922728
assert wf1.output_dir
@@ -2749,9 +2785,11 @@ def test_wf_state_cachelocations_forcererun(plugin, tmpdir):
27492785
assert results2[0].output.out == 8
27502786
assert results2[1].output.out == 82
27512787

2752-
# checking execution time
2753-
assert t1 > 3
2754-
assert t2 > 3
2788+
# for win and dask/slurm the time for dir creation etc. might take much longer
2789+
if sys.platform.startswith("win") and plugin == "cf":
2790+
# checking the execution time
2791+
assert t1 > 2
2792+
assert t2 > 2
27552793

27562794
# checking all directories
27572795
assert wf1.output_dir
@@ -2816,9 +2854,11 @@ def test_wf_state_cachelocations_updateinp(plugin, tmpdir):
28162854
assert results2[0].output.out == 8
28172855
assert results2[1].output.out == 82
28182856

2819-
# checking execution time
2820-
assert t1 > 3
2821-
assert t2 < 0.5
2857+
# for win and dask/slurm the time for dir creation etc. might take much longer
2858+
if sys.platform.startswith("win") and plugin == "cf":
2859+
# checking the execution time
2860+
assert t1 > 2
2861+
assert t2 < 0.5
28222862

28232863
# checking all directories
28242864
assert wf1.output_dir
@@ -2930,9 +2970,11 @@ def test_wf_nostate_cachelocations_updated(plugin, tmpdir):
29302970
results2 = wf2.result()
29312971
assert 8 == results2.output.out
29322972

2933-
# checking execution time
2934-
assert t1 > 3
2935-
assert t2 > 3
2973+
# for win and dask/slurm the time for dir creation etc. might take much longer
2974+
if sys.platform.startswith("win") and plugin == "cf":
2975+
# checking the execution time
2976+
assert t1 > 2
2977+
assert t2 > 2
29362978

29372979
# checking if both wf run
29382980
assert wf1.output_dir.exists()
@@ -2990,6 +3032,12 @@ def test_wf_nostate_cachelocations_recompute(plugin, tmpdir):
29903032
assert wf1.output_dir.exists()
29913033
assert wf2.output_dir.exists()
29923034

3035+
# for win and dask/slurm the time for dir creation etc. might take much longer
3036+
if sys.platform.startswith("win") and plugin == "cf":
3037+
# checking the execution time
3038+
assert t1 > 2
3039+
assert t2 > 2
3040+
29933041
# the second wf should have only one task run
29943042
assert len(list(Path(cache_dir1).glob("F*"))) == 2
29953043
assert len(list(Path(cache_dir2).glob("F*"))) == 1
@@ -3044,9 +3092,11 @@ def test_wf_ndstate_cachelocations(plugin, tmpdir):
30443092
results2 = wf2.result()
30453093
assert results2.output.out == [8, 82]
30463094

3047-
# checking execution time
3048-
assert t1 > 3
3049-
assert t2 < 0.5
3095+
# for win and dask/slurm the time for dir creation etc. might take much longer
3096+
if sys.platform.startswith("win") and plugin == "cf":
3097+
# checking the execution time
3098+
assert t1 > 2
3099+
assert t2 < 0.5
30503100

30513101
# checking all directories
30523102
assert wf1.output_dir.exists()
@@ -3106,9 +3156,11 @@ def test_wf_ndstate_cachelocations_forcererun(plugin, tmpdir):
31063156
results2 = wf2.result()
31073157
assert results2.output.out == [8, 82]
31083158

3109-
# checking execution time
3110-
assert t1 > 3
3111-
assert t2 > 3
3159+
# for win and dask/slurm the time for dir creation etc. might take much longer
3160+
if sys.platform.startswith("win") and plugin == "cf":
3161+
# checking the execution time
3162+
assert t1 > 2
3163+
assert t2 > 2
31123164

31133165
# checking all directories
31143166
assert wf1.output_dir.exists()
@@ -3166,9 +3218,11 @@ def test_wf_ndstate_cachelocations_updatespl(plugin, tmpdir):
31663218
results2 = wf2.result()
31673219
assert results2.output.out == [8, 82]
31683220

3169-
# checking execution time
3170-
assert t1 > 3
3171-
assert t2 < 0.5
3221+
# for win and dask/slurm the time for dir creation etc. might take much longer
3222+
if sys.platform.startswith("win") and plugin == "cf":
3223+
# checking the execution time
3224+
assert t1 > 2
3225+
assert t2 < 0.5
31723226

31733227
# checking all directories
31743228
assert wf1.output_dir.exists()
@@ -3227,9 +3281,11 @@ def test_wf_ndstate_cachelocations_recompute(plugin, tmpdir):
32273281
results2 = wf2.result()
32283282
assert results2.output.out == [8, 10, 62, 82]
32293283

3230-
# checking execution time
3231-
assert t1 > 3
3232-
assert t2 > 3
3284+
# for win and dask/slurm the time for dir creation etc. might take much longer
3285+
if sys.platform.startswith("win") and plugin == "cf":
3286+
# checking the execution time
3287+
assert t1 > 2
3288+
assert t2 > 2
32333289

32343290
# checking all directories
32353291
assert wf1.output_dir.exists()
@@ -3254,8 +3310,10 @@ def test_wf_nostate_runtwice_usecache(plugin, tmpdir):
32543310
wf1.inputs.y = 3
32553311
wf1.plugin = plugin
32563312

3313+
t0 = time.time()
32573314
with Submitter(plugin=plugin) as sub:
32583315
sub(wf1)
3316+
t1 = time.time() - t0
32593317

32603318
results1 = wf1.result()
32613319
assert 8 == results1.output.out
@@ -3266,14 +3324,22 @@ def test_wf_nostate_runtwice_usecache(plugin, tmpdir):
32663324
cache_dir_content = os.listdir(wf1.cache_dir)
32673325

32683326
# running workflow the second time
3327+
t0 = time.time()
32693328
with Submitter(plugin=plugin) as sub:
32703329
sub(wf1)
3330+
t2 = time.time() - t0
32713331

32723332
results1 = wf1.result()
32733333
assert 8 == results1.output.out
3274-
# checking if no new directory is not created
3334+
# checking if no new directory is created
32753335
assert cache_dir_content == os.listdir(wf1.cache_dir)
32763336

3337+
# for win and dask/slurm the time for dir creation etc. might take much longer
3338+
if sys.platform.startswith("win") and plugin == "cf":
3339+
# checking the execution time
3340+
assert t1 > 2
3341+
assert t2 < 0.5
3342+
32773343

32783344
def test_wf_state_runtwice_usecache(plugin, tmpdir):
32793345
"""
@@ -3291,8 +3357,10 @@ def test_wf_state_runtwice_usecache(plugin, tmpdir):
32913357
wf1.inputs.y = [3, 30]
32923358
wf1.plugin = plugin
32933359

3360+
t0 = time.time()
32943361
with Submitter(plugin=plugin) as sub:
32953362
sub(wf1)
3363+
t1 = time.time() - t0
32963364

32973365
results1 = wf1.result()
32983366
assert 8 == results1[0].output.out
@@ -3305,14 +3373,21 @@ def test_wf_state_runtwice_usecache(plugin, tmpdir):
33053373
cache_dir_content = os.listdir(wf1.cache_dir)
33063374

33073375
# running workflow the second time
3376+
t0 = time.time()
33083377
with Submitter(plugin=plugin) as sub:
33093378
sub(wf1)
3379+
t2 = time.time() - t0
33103380

33113381
results1 = wf1.result()
33123382
assert 8 == results1[0].output.out
33133383
assert 602 == results1[1].output.out
3314-
# checking if no new directory is not created
3384+
# checking if no new directory is created
33153385
assert cache_dir_content == os.listdir(wf1.cache_dir)
3386+
# for win and dask/slurm the time for dir creation etc. might take much longer
3387+
if sys.platform.startswith("win") and plugin == "cf":
3388+
# checking the execution time
3389+
assert t1 > 2
3390+
assert t2 < 0.5
33163391

33173392

33183393
@pytest.fixture

pydra/engine/tests/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def ten(x):
128128

129129
@mark.task
130130
def add2_wait(x):
131-
time.sleep(3)
131+
time.sleep(2)
132132
return x + 2
133133

134134

0 commit comments

Comments
 (0)