Example #1
0
def test_pmap():
    print "Testing parallel execution with random data..."
    with PluginTester(autoinit=False) as t:
        t.orchestrator_config.use_colors = False
        t.orchestrator_config.ui_mode = "disabled"
        t.audit_config.audit_db = ":memory:"
        t.init_environment()
        t_list = thread_list()
        func = lambda x: x
        for i in xrange(20):
            input_data = [randint(-10, 10) for x in xrange(randint(10, 200))]
            output_data = pmap(func, input_data)
            control_data = map(func, input_data)
            assert output_data == control_data
            assert input_data == output_data
        assert t_list == thread_list()
Example #2
0
def test_pmap():
    print "Testing parallel execution with random data..."
    with PluginTester(autoinit=False) as t:
        t.orchestrator_config.use_colors = False
        t.orchestrator_config.ui_mode = "disabled"
        t.audit_config.audit_db = "memory://"
        t.init_environment()
        t_list = thread_list()
        func = lambda x: x
        for i in xrange(20):
            input_data = [randint(-10, 10) for x in xrange(randint(10, 200))]
            output_data = pmap(func, input_data)
            control_data = map(func, input_data)
            assert output_data == control_data
            assert input_data == output_data
        assert t_list == thread_list()
Example #3
0
def test_pmap_delays():
    print "Testing parallel execution with delays..."
    with PluginTester(autoinit=False) as t:
        t.orchestrator_config.use_colors = False
        t.orchestrator_config.ui_mode = "disabled"
        t.audit_config.audit_db = ":memory:"
        t.init_environment()
        t_list = thread_list()
        def func(x):
            ##print "(%d)" % get_ident()
            sleep(1)
            return x
        def test(x):
            assert pmap(func, xrange(x)) == range(x)
        test(1)
        test(4)
        test(8)
        assert t_list == thread_list()
Example #4
0
def test_pmap_multi():
    print "Testing parallel execution with random data and multiple parameters..."
    with PluginTester(autoinit=False) as t:
        t.orchestrator_config.use_colors = False
        t.orchestrator_config.ui_mode = "disabled"
        t.audit_config.audit_db = ":memory:"
        t.init_environment()
        t_list = thread_list()
        def func(*args):
            return sum( x for x in args if x is not None )
        for i in xrange(10):
            input_data = []
            for j in xrange(randint(2, 100)):
                args = [randint(-10, 10) for x in xrange(randint(10, 20))]
                input_data.append(args)
            output_data  = pmap(func, *input_data, pool_size=10)
            control_data = map(func, *input_data)
            assert output_data == control_data
        assert t_list == thread_list()
Example #5
0
def test_pmap_errors():
    print "Testing parallel execution with errors..."
    with PluginTester(autoinit=False) as t:
        t.orchestrator_config.use_colors = False
        t.orchestrator_config.ui_mode = "disabled"
        t.audit_config.audit_db = ":memory:"
        t.init_environment()
        t_list = thread_list()
        def func(x):
            if x & 1:
                raise ValueError("I don't like odd numbers!")
            return int(x / 2)
        def control(x):
            if x & 1:
                return None
            return int(x / 2)
        output_data  = pmap(func,   xrange(200))
        control_data = map(control, xrange(200))
        assert output_data == control_data
        assert t_list == thread_list()
Example #6
0
def test_pmap_multi():
    print "Testing parallel execution with random data and multiple parameters..."
    with PluginTester(autoinit=False) as t:
        t.orchestrator_config.use_colors = False
        t.orchestrator_config.ui_mode = "disabled"
        t.audit_config.audit_db = ":memory:"
        t.init_environment()
        t_list = thread_list()

        def func(*args):
            return sum(x for x in args if x is not None)

        for i in xrange(10):
            input_data = []
            for j in xrange(randint(2, 100)):
                args = [randint(-10, 10) for x in xrange(randint(10, 20))]
                input_data.append(args)
            output_data = pmap(func, *input_data, pool_size=10)
            control_data = map(func, *input_data)
            assert output_data == control_data
        assert t_list == thread_list()
Example #7
0
def test_pmap_delays():
    print "Testing parallel execution with delays..."
    with PluginTester(autoinit=False) as t:
        t.orchestrator_config.use_colors = False
        t.orchestrator_config.ui_mode = "disabled"
        t.audit_config.audit_db = ":memory:"
        t.init_environment()
        t_list = thread_list()

        def func(x):
            ##print "(%d)" % get_ident()
            sleep(1)
            return x

        def test(x):
            assert pmap(func, xrange(x)) == range(x)

        test(1)
        test(4)
        test(8)
        assert t_list == thread_list()
Example #8
0
def test_pmap_errors():
    print "Testing parallel execution with errors..."
    with PluginTester(autoinit=False) as t:
        t.orchestrator_config.use_colors = False
        t.orchestrator_config.ui_mode = "disabled"
        t.audit_config.audit_db = ":memory:"
        t.init_environment()
        t_list = thread_list()

        def func(x):
            if x & 1:
                raise ValueError("I don't like odd numbers!")
            return int(x / 2)

        def control(x):
            if x & 1:
                return None
            return int(x / 2)

        output_data = pmap(func, xrange(200))
        control_data = map(control, xrange(200))
        assert output_data == control_data
        assert t_list == thread_list()