コード例 #1
0
    def test_long_callback(self):
        self.d = FlushingDict(TestFlushingDict.SIZE,
                              TestFlushingDict.FLUSH_LATENCY_SECONDS,
                              self.long_callback)
        expected_data = []
        for i in range(TestFlushingDict.SIZE):
            self.d.add(i, i)
            expected_data.append((i, i))

        # We add another element while the callback is idling, to see
        # if the new element is flushed later. We need to wait 2
        # latencies for the callback, one more for the time-based
        # second flush, and we add some tolerance.
        gevent.sleep(0)
        self.d.add(TestFlushingDict.SIZE, TestFlushingDict.SIZE)
        gevent.sleep(TestFlushingDict.FLUSH_LATENCY_SECONDS * 3 + 0.1)

        self.assertEqual(TestFlushingDict.SIZE + 1,
                         sum(len(data) for data in self.received_data))
コード例 #2
0
 def setUp(self):
     super(TestFlushingDict, self).setUp()
     self.received_data = []
     self.d = FlushingDict(TestFlushingDict.SIZE,
                           TestFlushingDict.FLUSH_LATENCY_SECONDS,
                           self.callback)