File: test_fail.py

package info (click to toggle)
python-parsl 2026.01.26%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 12,144 kB
  • sloc: python: 24,400; makefile: 352; sh: 252; ansic: 45
file content (58 lines) | stat: -rw-r--r-- 1,692 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import pytest

from parsl.app.app import python_app
from parsl.dataflow.errors import DependencyError


class ManufacturedTestFailure(Exception):
    pass


@python_app
def random_fail(fail_prob: float, inputs=()):
    import random
    if random.random() < fail_prob:
        raise ManufacturedTestFailure("App failure")


def test_no_deps():
    """Test basic error handling, with no dependent failures
    """
    futs = [random_fail(1), random_fail(0), random_fail(0)]

    for f in futs:
        try:
            f.result()
        except ManufacturedTestFailure:
            pass


def test_fail_sequence_first():
    t1 = random_fail(fail_prob=1)
    t2 = random_fail(fail_prob=0, inputs=[t1])
    t_final = random_fail(fail_prob=0, inputs=[t2])

    with pytest.raises(DependencyError):
        t_final.result()

    assert len(t_final.exception().dependent_exceptions_tids) == 1
    assert isinstance(t_final.exception().dependent_exceptions_tids[0][0], DependencyError)
    assert t_final.exception().dependent_exceptions_tids[0][1].startswith("task ")

    assert hasattr(t_final.exception(), '__cause__')
    assert t_final.exception().__cause__ == t1.exception()


def test_fail_sequence_middle():
    t1 = random_fail(fail_prob=0)
    t2 = random_fail(fail_prob=1, inputs=[t1])
    t_final = random_fail(fail_prob=0, inputs=[t2])

    with pytest.raises(DependencyError):
        t_final.result()

    assert len(t_final.exception().dependent_exceptions_tids) == 1
    assert isinstance(t_final.exception().dependent_exceptions_tids[0][0], ManufacturedTestFailure)

    assert hasattr(t_final.exception(), '__cause__')
    assert t_final.exception().__cause__ == t2.exception()