def test_channel(self): chan = SlidingChannel() chan.put(1) chan.process() chan.put(2) chan.process() chan.put(3) chan.process() prom = chan.get() chan.process() self.assertEqual(prom.value, 3)
def test_channel_with_limit(self): chan = SlidingChannel(limit=5) def _and_process(x): process_all() return x put_proms = [_and_process(chan.put(x)) for x in range(10)] get_proms = [_and_process(chan.get()) for _ in range(10)] for n, prom in enumerate(put_proms): process_all() self.assertTrue(prom.delivered) self.assertTrue(prom.value) for n, prom in enumerate(get_proms): if n > 4: self.assertFalse(prom.delivered) else: self.assertTrue(prom.delivered) self.assertEqual(prom.value, n + 5)