Exemple #1
0
def test_parallel_speed():
    # given
    funcs = {'x': u, 'y': v}
    dependencies = {'x': [], 'y': []}
    graph = taskmap.create_graph(funcs, dependencies)

    # when
    start = time.time()
    taskmap.run_parallel(graph, nprocs=2, sleep=.001)
    end = time.time()

    # then
    assert end - start < .8
Exemple #2
0
def test_sync_error_raise_errors():
    # given
    dependencies = {'c': ['d'], 'd': []}
    funcs = {'d': d, 'c': c}

    # when
    graph = taskmap.create_graph(funcs, dependencies)
    with pytest.raises(RuntimeError, match='some error'):
        taskmap.run(graph, raise_errors=True)

    graph = taskmap.create_graph(funcs, dependencies)
    with pytest.raises(RuntimeError, match='some error'):
        taskmap.run_parallel(graph, raise_errors=True)
Exemple #3
0
def test_sync_error_handling():
    # given
    dependencies = {
        'c': ['d'],
        'd': [],
    }

    funcs = {
        'd': d,
        'c': c,
    }

    # when
    graph = taskmap.create_graph(funcs.copy(), dependencies.copy())
    graph = taskmap.run(graph)

    graph_parallel = taskmap.create_graph(funcs.copy(), dependencies.copy())
    graph_parallel = taskmap.run_parallel(graph, nprocs=2, sleep=.001)

    # then
    expected = {
        'd': error,
        'c': 'Ancestor task d failed; task not run',
    }
    assert graph.results['c'] == expected['c']
    assert graph.results['d'].__class__ == expected['d'].__class__
    assert graph.results['d'].args == expected['d'].args

    assert graph_parallel.results['c'] == expected['c']
    assert graph_parallel.results['d'].__class__ == expected['d'].__class__
    assert graph_parallel.results['d'].args == expected['d'].args
Exemple #4
0
def test_run_parallel():
    # given
    dependencies = {
        'c': ['long_task', 'b'],
        'b': ['long_task'],
        'long_task': [],
    }

    funcs = {
        'long_task': long_task,
        'b': b,
        'c': c,
    }

    graph = taskmap.create_graph(funcs, dependencies)

    # when
    graph = taskmap.run_parallel(graph, nprocs=2, sleep=.001)

    # then
    assert graph.results == {'long_task': 5, 'b': 15, 'c': 40}