Пример #1
0
def testMaxDispense(tmpdir):
    q = PriorityEnqueue(str(tmpdir))
    q.queue([dict(id=i, p='L', expected=3) for i in xrange(200)])
    q.close()

    ls_datadir(tmpdir)

    data = []
    qr = PriorityDequeue(str(tmpdir))
    # set lower MAX_DISPENSE for testing
    qr.MAX_DISPENSE = 10
    # start reading; this should set current queue to priority=3
    u = qr.get(timeout=0.01)
    assert u, "qr.get->%r" % u
    assert u['expected'] == 3
    data.append(u)
    # then add data with higher priority
    q.queue([dict(id=i, p='', expected=0) for i in xrange(200, 220)])
    q.close()
    # continue reading
    for i in xrange(qr.MAX_DISPENSE * 2):
        u = qr.get(timeout=0.01)
        assert u
        data.append(u)

    assert len(data) == 1 + qr.MAX_DISPENSE * 2

    # check the result
    d1 = data[qr.MAX_DISPENSE - 1]
    d2 = data[qr.MAX_DISPENSE]
    assert d1['expected'] == 3
    assert d2['expected'] == 0, "data[%d]=%r" % (
        qr.MAX_DISPENSE, d2)