Пример #1
0
 def test_consume_and_add(self):
     s = TrxState(None)
     s.enqueue(1)
     for i, _m in enumerate(s.consume_messages()):
         if i < 10:
             s.enqueue(1)
     assert i == 10, i
Пример #2
0
    def test_consume_heap_auto_order(self):
        s = TrxState(None)
        s.enqueue("b")
        s.enqueue("a")
        s.enqueue("!", priority=0)

        m = ""
        for _m in s.consume_messages():
            m += _m
        assert m == "!ba"
Пример #3
0
 def test_consume_and_add(self):
     s = TrxState()
     s.enqueue(1)
     for i, _m in enumerate(s.consume_messages()):
         if i < 10:
             s.enqueue(1)
     assert i == 10, i
Пример #4
0
    def test_consume(self):
        s = TrxState(None)
        i = -1
        for i, _m in enumerate(s.consume_messages()):
            pass
        assert i == -1
        assert s.is_queue_empty()

        s.enqueue(1)
        s.enqueue(1)

        i = -1
        for i, _m in enumerate(s.consume_messages()):
            pass
        assert i == 1
        assert s.is_queue_empty()

        i = -1
        for i, _m in enumerate(s.consume_messages()):
            pass
        assert i == -1
        assert s.is_queue_empty()
Пример #5
0
    def test_consume_heap_order(self):
        s = TrxState(None)
        s.enqueue("b", priority=2)
        s.enqueue("a", priority=1)

        m = ""
        for _m in s.consume_messages():
            m += _m
        assert m == "ab"

        s.enqueue("b", priority=1)
        s.enqueue("a", priority=2)

        m = ""
        for _m in s.consume_messages():
            m += _m
        assert m == "ba"
Пример #6
0
    def test_consume_heap_auto_order(self):
        s = TrxState()
        s.enqueue("b")
        s.enqueue("a")
        s.enqueue("!", priority=0)

        m = ""
        for _m in s.consume_messages():
            m += _m
        assert m == "!ba"
Пример #7
0
    def test_consume(self):
        s = TrxState()
        i = -1
        for i, _m in enumerate(s.consume_messages()):
            pass
        assert i == -1
        assert s.is_queue_empty()

        s.enqueue(1)
        s.enqueue(1)

        i = -1
        for i, _m in enumerate(s.consume_messages()):
            pass
        assert i == 1
        assert s.is_queue_empty()

        i = -1
        for i, _m in enumerate(s.consume_messages()):
            pass
        assert i == -1
        assert s.is_queue_empty()
Пример #8
0
    def test_consume_heap_order(self):
        s = TrxState()
        s.enqueue("b", priority=2)
        s.enqueue("a", priority=1)

        m = ""
        for _m in s.consume_messages():
            m += _m
        assert m == "ab"

        s.enqueue("b", priority=1)
        s.enqueue("a", priority=2)

        m = ""
        for _m in s.consume_messages():
            m += _m
        assert m == "ba"