Exemple #1
0
    def test_lib_net_chan_txfini(self):
        class FiniableLink(s_net.Link):
            def tx(self, msg, **kwargs):
                logger.error(msg)

        msg = '%r' % (('cool', {}),)
        with self.getLoggerStream('synapse.tests.test_lib_net', msg) as stream:
            chan = s_net.Chan(FiniableLink(), None)
            chan.txfini(data=('cool', {}))
            self.true(stream.wait(10))

        stream.seek(0)
        self.isin(msg, stream.read())
Exemple #2
0
    def test_lib_net_chan_queue(self):
        chan = s_net.Chan(s_net.Link(), None)

        self.raises(AttributeError, chan.next)
        self.raises(AttributeError, chan.slice, 1337)
        with self.raises(AttributeError) as e:
            [logger.error(item) for item in chan.iter()]

        chan.setq()
        msgs = (
            ('woo1', {}),
            ('woo2', {}),
            ('woo3', {}),
            ('woo4', {}),
            ('woo5', {}),
        )

        [chan.rx(None, msg) for msg in msgs]
        self.eq(chan.next(timeout=1), msgs[0])
        self.eq(chan.next(timeout=1), msgs[1])
        self.eq(chan.next(timeout=1), msgs[2])
        self.eq(chan.next(timeout=1), msgs[3])
        self.eq(chan.next(timeout=1), msgs[4])
        self.raises(s_exc.TimeOut, chan.next, timeout=0.01)

        [chan.rx(None, msg) for msg in msgs]

        self.eq(chan.slice(4), [msgs[0], msgs[1], msgs[2], msgs[3]])
        self.eq(chan.next(timeout=1), msgs[4])

        self.raises(s_exc.TimeOut, chan.next, timeout=0.01)
        self.raises(s_exc.TimeOut, chan.slice, 100, timeout=0.01)

        #results = []
        #[chan.rx(None, msg) for msg in msgs]
        #[results.append(item) for item in chan.iter(timeout=1)]
        #self.eq(results, list(msgs))
        #[results.append(item) for item in chan.iter(timeout=1)]
        #self.eq(results, list(msgs))

        self.false(chan._chan_rxq._que_done)
        chan.rxfini()
        self.true(chan._chan_rxq._que_done)
        [chan.rx(None, msg) for msg in msgs]
        self.raises(s_exc.IsFini, chan.next, timeout=0.01)
Exemple #3
0
 def test_lib_net_chan_iden(self):
     iden = 'hehe'
     chan = s_net.Chan(None, iden)
     self.eq(chan.iden(), iden)