コード例 #1
0
ファイル: test_schedulers.py プロジェクト: janpipek/wowp
def _run_linearity_test(scheduler):
    import random
    from time import sleep

    max_ = 100

    original_sequence = list(range(max_))

    def orig(x):
        # print("In act1:", x)
        return x

    def app_fn(x):
        # print("In act2:", x)
        s = random.randint(1, 30) / 1000.0
        sleep(s)
        return x

    orig_actor = FuncActor(orig, outports=('x', ))
    orig_actor.scheduler = scheduler
    new_actor = FuncActor(app_fn, outports=('x', ))
    orig_actor.outports["x"].connect(new_actor.inports["x"])

    for i in range(max_):
        scheduler.put_value(orig_actor.inports["x"], i)

    scheduler.execute()
    new_sequence = list(new_actor.outports['x'].pop_all())

    print("Received: ", new_sequence)
    print("Expected: ", original_sequence)

    assert new_sequence == original_sequence
コード例 #2
0
def _run_linearity_test(scheduler, size=100, ntimes=1):
    max_ = size

    original_sequence = list(range(max_))

    orig_actor = FuncActor(orig, outports=('x',))
    orig_actor.scheduler = scheduler
    new_actor = FuncActor(app_fn, outports=('x',))
    orig_actor.outports["x"].connect(new_actor.inports["x"])

    for t in range(ntimes):
        for i in range(max_):
            scheduler.put_value(orig_actor.inports["x"], i)

        scheduler.execute()
        new_sequence = list(new_actor.outports['x'].pop_all())

        try:
            assert new_sequence == original_sequence
        except AssertionError:
            print("Received: ", new_sequence)
            print("Expected: ", original_sequence)
            raise