Exemplo n.º 1
0
def test_queue_adopt_producer_step():
    ("Queue#adopt_producer should take a step and know about its id and")

    # Given a dummy manager
    manager = Node()

    # Given a Queue with maximum size of 10
    queue = Queue("test-queue", maxsize=10)
    q1 = Queue("name1")
    q2 = Queue("name2")
    # And a running step (so it gains a thread id)
    step = DummyStep(q1, q2, manager)
    step.start()

    # When that queue adopts the step as a producer
    consumers, producers = queue.adopt_producer(step)

    # And the redis key should contain the step id
    hostname = socket.gethostname()
    pid = os.getpid()
    tid = step.ident
    value = "{hostname}|{pid}|{tid}|tests.functional.test_queue.DummyStep|lineup.framework.Node".format(**locals())

    redis = StrictRedis()
    members = redis.smembers("lineup:test-queue:producers")
    members.should.contain(value)
    queue.deactivate()
    q1.deactivate()
    q2.deactivate()
Exemplo n.º 2
0
def test_queue_adopt_producer_step(context):
    ("Queue#adopt_producer should take a step and know about its id and")

    # Given a dummy manager
    manager = Node(JSONRedisBackend)

    # Given a Queue with maximum size of 10
    queue = Queue('test-queue', backend_class=JSONRedisBackend, maxsize=10)
    q1 = Queue('name1', backend_class=JSONRedisBackend)
    q2 = Queue('name2', backend_class=JSONRedisBackend)

    # And a running step (so it gains a thread id)
    step = DummyStep(q1, q2, manager)

    # When that queue adopts the step as a producer
    consumers, producers = queue.adopt_producer(step)

    # And the redis key should contain the step id
    hostname = socket.gethostname()
    pid = os.getpid()
    tid = step.ident
    value = 'lineup.framework.Node|{hostname}|{pid}|{tid}|tests.functional.test_queue.DummyStep|lineup.framework.Node'.format(**locals())

    members = context.redis.smembers('lineup:test-queue:producers')
    members.should.contain(value)
    repr(q1).should.equal(
        '<lineup.Queue(lineup:name1, backend=<JSONRedisBackend>)>')
Exemplo n.º 3
0
def test_put_waits_to_consume():
    ("Queue#put should wait until someone consumes")
    # Given a dummy manager
    manager = Node()

    consume = Queue("consume")
    produce = Queue("produce")

    step = DummyStep(consume, produce, manager)
    step.start()

    consume.put({"foo": "Bar"})
    produce.get().should.equal({"cool": {"foo": "Bar"}})
    consume.deactivate()
    produce.deactivate()