Пример #1
0
def test_post_replace():
    pool = DAGPool()
    pool.post("a", 1)
    pool.post("a", 2, replace=True)
    assert_equals(pool.get("a"), 2)
    assert_equals(dict(pool.wait_each("a")), dict(a=2))
    assert_equals(pool.wait("a"), dict(a=2))
    assert_equals(pool["a"], 2)
Пример #2
0
def test_post_replace():
    pool = DAGPool()
    pool.post("a", 1)
    pool.post("a", 2, replace=True)
    assert_equals(pool.get("a"), 2)
    assert_equals(dict(pool.wait_each("a")), dict(a=2))
    assert_equals(pool.wait("a"), dict(a=2))
    assert_equals(pool["a"], 2)
Пример #3
0
def test_post_collision_spawn():
    pool = DAGPool()
    pool.spawn("a", (), lambda key, result: 1)
    # hasn't yet run
    with assert_raises(Collision):
        # n.b. This exercises the code that tests whether post(key) is or is
        # not coming from that key's greenthread.
        pool.post("a", 2)
    # kill it
    pool.kill("a")
    # now we can post
    pool.post("a", 3)
    assert_equals(pool.get("a"), 3)

    pool = DAGPool()
    pool.spawn("a", (), lambda key, result: 4)
    # run it
    spin()
    with assert_raises(Collision):
        pool.post("a", 5)
    # can't kill it now either
    with assert_raises(KeyError):
        pool.kill("a")
    # still can't post
    with assert_raises(Collision):
        pool.post("a", 6)
Пример #4
0
def test_post_collision_spawn():
    pool = DAGPool()
    pool.spawn("a", (), lambda key, result: 1)
    # hasn't yet run
    with assert_raises(Collision):
        # n.b. This exercises the code that tests whether post(key) is or is
        # not coming from that key's greenthread.
        pool.post("a", 2)
    # kill it
    pool.kill("a")
    # now we can post
    pool.post("a", 3)
    assert_equals(pool.get("a"), 3)

    pool = DAGPool()
    pool.spawn("a", (), lambda key, result: 4)
    # run it
    spin()
    with assert_raises(Collision):
        pool.post("a", 5)
    # can't kill it now either
    with assert_raises(KeyError):
        pool.kill("a")
    # still can't post
    with assert_raises(Collision):
        pool.post("a", 6)
Пример #5
0
def test_post_get_exc():
    pool = DAGPool()
    bogua = BogusError("bogua")
    pool.post("a", bogua)
    assert isinstance(pool.get("a"), BogusError), \
        "should have delivered BogusError instead of raising"
    bogub = PropagateError("b", BogusError("bogub"))
    pool.post("b", bogub)
    with assert_raises(PropagateError):
        pool.get("b")

    # Notice that although we have both "a" and "b" keys, items() is
    # guaranteed to raise PropagateError because one of them is
    # PropagateError. Other values don't matter.
    with assert_raises(PropagateError):
        pool.items()

    # Similar remarks about waitall() and wait().
    with assert_raises(PropagateError):
        pool.waitall()
    with assert_raises(PropagateError):
        pool.wait()
    with assert_raises(PropagateError):
        pool.wait("b")
    with assert_raises(PropagateError):
        pool.wait("ab")
    # but if we're only wait()ing for success results, no exception
    assert isinstance(pool.wait("a")["a"], BogusError), \
        "should have delivered BogusError instead of raising"

    # wait_each() is guaranteed to eventually raise PropagateError, though you
    # may obtain valid values before you hit it.
    with assert_raises(PropagateError):
        for k, v in pool.wait_each():
            pass

    # wait_each_success() filters
    assert_equals(dict(pool.wait_each_success()), dict(a=bogua))
    assert_equals(dict(pool.wait_each_success("ab")), dict(a=bogua))
    assert_equals(dict(pool.wait_each_success("a")), dict(a=bogua))
    assert_equals(dict(pool.wait_each_success("b")), {})

    # wait_each_exception() filters the other way
    assert_equals(dict(pool.wait_each_exception()), dict(b=bogub))
    assert_equals(dict(pool.wait_each_exception("ab")), dict(b=bogub))
    assert_equals(dict(pool.wait_each_exception("a")), {})
    assert_equals(dict(pool.wait_each_exception("b")), dict(b=bogub))
Пример #6
0
def test_post_get_exc():
    pool = DAGPool()
    bogua = BogusError("bogua")
    pool.post("a", bogua)
    assert isinstance(pool.get("a"), BogusError), \
        "should have delivered BogusError instead of raising"
    bogub = PropagateError("b", BogusError("bogub"))
    pool.post("b", bogub)
    with assert_raises(PropagateError):
        pool.get("b")

    # Notice that although we have both "a" and "b" keys, items() is
    # guaranteed to raise PropagateError because one of them is
    # PropagateError. Other values don't matter.
    with assert_raises(PropagateError):
        pool.items()

    # Similar remarks about waitall() and wait().
    with assert_raises(PropagateError):
        pool.waitall()
    with assert_raises(PropagateError):
        pool.wait()
    with assert_raises(PropagateError):
        pool.wait("b")
    with assert_raises(PropagateError):
        pool.wait("ab")
    # but if we're only wait()ing for success results, no exception
    assert isinstance(pool.wait("a")["a"], BogusError), \
        "should have delivered BogusError instead of raising"

    # wait_each() is guaranteed to eventually raise PropagateError, though you
    # may obtain valid values before you hit it.
    with assert_raises(PropagateError):
        for k, v in pool.wait_each():
            pass

    # wait_each_success() filters
    assert_equals(dict(pool.wait_each_success()), dict(a=bogua))
    assert_equals(dict(pool.wait_each_success("ab")), dict(a=bogua))
    assert_equals(dict(pool.wait_each_success("a")), dict(a=bogua))
    assert_equals(dict(pool.wait_each_success("b")), {})

    # wait_each_exception() filters the other way
    assert_equals(dict(pool.wait_each_exception()), dict(b=bogub))
    assert_equals(dict(pool.wait_each_exception("ab")), dict(b=bogub))
    assert_equals(dict(pool.wait_each_exception("a")), {})
    assert_equals(dict(pool.wait_each_exception("b")), dict(b=bogub))
Пример #7
0
def test_post_collision_post():
    pool = DAGPool()
    pool.post("a", 1)
    with assert_raises(Collision):
        pool.post("a", 2)
Пример #8
0
def test_post_collision_preload():
    pool = DAGPool(dict(a=1))
    with assert_raises(Collision):
        pool.post("a", 2)
Пример #9
0
def test_spawn_collision_post():
    pool = DAGPool()
    pool.post("a", "aval")
    with assert_raises(Collision):
        pool.spawn("a", (), lambda key, results: None)
Пример #10
0
def test_post_collision_post():
    pool = DAGPool()
    pool.post("a", 1)
    with assert_raises(Collision):
        pool.post("a", 2)
Пример #11
0
def test_post_collision_preload():
    pool = DAGPool(dict(a=1))
    with assert_raises(Collision):
        pool.post("a", 2)
Пример #12
0
def test_spawn_collision_post():
    pool = DAGPool()
    pool.post("a", "aval")
    with assert_raises(Collision):
        pool.spawn("a", (), lambda key, results: None)