Esempio n. 1
0
    def test04_get_only_valid_requests(self):
        """
        - create a lot of requests marked as 'expired'
        - wait some time
        - create another lot of requests marked as 'valid'
        -> check if only 'valid' requests present
        """

        clock = Clock()

        sessions = Sessions(False, 10, clock)
        collector = Collector(sessions)

        dl = []
        for i in xrange(10):
            d = collector.queue_and_process("192.168.45.12", "expired")
            dl.append(d)

        clock.advance(15)

        for i in xrange(10):
            d = collector.queue_and_process("192.168.45.12", "valid")
            dl.append(d)


        dfl = DeferredList(dl)
        @dfl.addCallback
        def get_result(ignored):

            for i in xrange(10):
                uid, ip, request = collector.get()
                self.assertEqual(request, "valid")
Esempio n. 2
0
    def test01_first_add_and_get(self):
        """
        First element added to queue will be returned as first.
        """

        collector = Collector(self.sessions)

        first_data = "my first data"

        collector.queue_and_process("192.168.45.12", first_data)
        # We are sure that only one element queued
        uid, ip, request = collector.get()
        self.assertEqual(request, first_data)
Esempio n. 3
0
    def test02_add_and_release(self):
        """
        - Add an element and get its deferred (as my_deferred)
        - Add another elements
        - Because this is a first element, first get() returns its uid
        -> Release an element with our uid, we get the same deferred
        """

        collector = Collector(self.sessions)

        any_data = "any data"

        my_deferred = collector.queue_and_process("192.168.45.12", any_data)

        for i in xrange(10):

            collector.queue_and_process("192.168.127.22",
                                        "%s_%d" % (any_data, i))

        uid, ip, request = collector.get()

        d = collector.release(uid, "any result")

        self.assertTrue(my_deferred is d)