def test2(self):

        f = fifo.FIFO(5)
        f.add_reader("r1")
        f.add_reader("r2")

        # Ensure fifo is empty
        self.assertEquals(f.read("r1"), None)
        self.assertEquals(len(f), 0)

        # Add something
        self.assertTrue(f.write(Token('1')))
        self.assertEquals(len(f), 1)

        # Reader r1 read something
        self.assertTrue(f.read('r1'))
        f.commit_reads('r1')

        self.assertEquals([True] * 3, [f.write(Token(t)) for t in ['2', '3', '4']])
        self.assertFalse(f.write(Token('5')))
        self.verify_data(['2', '3', '4'], [f.read('r1') for _ in range(3)])
        f.commit_reads("r1")

        # Reader r1 all done, ensure reader r2 can still read
        self.assertEquals(len(f), 4)
        self.assertFalse(f.can_write())
        self.assertTrue(f.can_read("r2"))
        self.assertFalse(f.can_read("r1"))

        # Reader r2 reads something
        self.verify_data(['1', '2', '3'], [f.read("r2") for _ in range(3)])
        f.commit_reads("r2")
        self.assertEquals(len(f), 1)

        self.assertTrue(f.write(Token('5')))
        self.verify_data(['4', '5'], [f.read("r2") for _ in range(2)])

        self.assertFalse(f.can_read("r2"))
        self.assertEquals(None, f.read("r2"))
        self.assertTrue(f.can_read("r1"))
        self.verify_data(['5'], [f.read("r1")])

        f.commit_reads("r2")
        f.commit_reads("r1")

        self.assertTrue(f.write(Token('6')))
        self.assertTrue(f.write(Token('7')))
        self.assertTrue(f.write(Token('8')))

        self.assertTrue([f.read("r1")
                         for _ in range(4)], [f.read("r2") for _ in range(4)])
Multiple readers
dataset/ETHPy150Open EricssonResearch/calvin-base/calvin/tests/test_fifo.py/FifoTests.test2