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)
def test_wait_each_preload(): pool = DAGPool(dict(a=1, b=2, c=3)) with suspend_checker(): with check_no_suspend(): # wait_each() may deliver in arbitrary order; collect into a dict # for comparison assert_equals(dict(pool.wait_each("abc")), dict(a=1, b=2, c=3)) # while we're at it, test wait() for preloaded keys assert_equals(pool.wait("bc"), dict(b=2, c=3))
def test_wait_posted(): # same as test_wait_each_posted(), but calling wait() capture = Capture() pool = DAGPool(dict(a=1, b=2, c=3)) eventlet.spawn(post_each, pool, capture) gotten = pool.wait("bcdefg") capture.add("got all") assert_equals(gotten, dict(b=2, c=3, d="dval", e="eval", f="fval", g="gval")) capture.validate([ [], [], ["got all"], ])
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))