Ejemplo n.º 1
0
    def test_noop(self):
        """Setup and tear down without running reactor.
        """

        self.get = CAGet(self.chan)
        self.check = ref(self.get)

        # circuit not connected
        self.assertEqual(len(self.chan._circ.pendingActions), 0)

        self.get.close()

        self.assertEqual(len(self.chan._circ.pendingActions), 0)

        del self.get
Ejemplo n.º 2
0
    def test_canceldead(self):
        """Connect, lose connection, cancel
        """

        g = self.get = CAGet(self.chan)
        self.check = ref(self.get)

        self.chan.doCon()
        pkt, _ = self.chan._circ._sent.pop(0)
        self.assertEqual(len(pkt), 16)
        pkt, extra = CAmessage.unpack(pkt)

        self.assertEqual(len(extra), 0)
        self.assertEqual(pkt.cmd, 15)

        self.chan.doLost()

        self.get.close()

        del self.get
Ejemplo n.º 3
0
    def test_cancellive(self):
        """Connect but cancel after data request sent
        """

        g = self.get = CAGet(self.chan)
        self.check = ref(self.get)

        self.chan.doCon()
        self.assertEqual(len(self.chan._circ._sent), 1)
        self.assertEqual(len(self.chan._circ.pendingActions), 1)

        pkt, _ = self.chan._circ._sent[0]
        self.assertEqual(len(pkt), 16)
        pkt, extra = CAmessage.unpack(pkt)

        self.assertEqual(len(extra), 0)
        self.assertEqual(pkt.cmd, 15)
        self.assertEqual(pkt.p1, self.chan.sid)
        self.assertIn(pkt.p2, self.chan._circ.pendingActions)

        self.get.close()

        del self.get
Ejemplo n.º 4
0
def getUpdated(sts):
    if sts!=ECA_NORMAL:
        print 'Error:', sts

    d2=CAGet(chan, dbf_conv=DBF.STRING)
    return d2.data
Ejemplo n.º 5
0
    try:
        reactor.stop()
    except ReactorNotRunning:
        pass

if opt.tmo >=0.00001:
    reactor.callLater(opt.tmo, timeout)

client=CAClient()

chan=CAClientChannel(pv, client)



# request native type and convert to string locally
g=CAGet(chan, dbf_conv=DBF.STRING)
d=g.data

@d.addCallback
def startSet((data,_)):
    print 'Before:',
    for d in data:
        print d,
    print
    
    s=CASet(chan, args, dbf=dbr, wait=not opt.nowait)

    return s.complete

@d.addCallback
def getUpdated(sts):
Ejemplo n.º 6
0
    return x


def timeout():
    log.fatal('Timeout!')
    try:
        reactor.stop()
    except ReactorNotRunning:
        pass


if opt.tmo >= 0.00001:
    reactor.callLater(opt.tmo, timeout)

gets = []

client = CAClient()

for pv in pvs:
    chan = CAClientChannel(pv, client)

    g = CAGet(chan, dbf_req, count, meta=meta_req, dbf_conv=dbf_dis)
    g.data.addCallback(data, pv, meta_req)
    g.data.addErrback(nodata, pv)
    gets.append(g.data)

done = DeferredList(gets)
done.addBoth(stop)

reactor.run()
Ejemplo n.º 7
0
class TestGet(unittest.TestCase):

    timeout = 2

    def setUp(self):
        self.chan = MockChannel()
        self.chan._circ = MockCircuit()
        self.chan.dbr = DBR.STRING
        self.chan.maxcount = 1

    def tearDown(self):
        if hasattr(self, 'get'):
            self.get.close()
            del self.get
        import gc
        gc.collect()
        if hasattr(self, 'check'):
            # Ensure no remaining references
            self.assertTrue(self.check() is None)

    def test_noop(self):
        """Setup and tear down without running reactor.
        """

        self.get = CAGet(self.chan)
        self.check = ref(self.get)

        # circuit not connected
        self.assertEqual(len(self.chan._circ.pendingActions), 0)

        self.get.close()

        self.assertEqual(len(self.chan._circ.pendingActions), 0)

        del self.get

    def test_cancellive(self):
        """Connect but cancel after data request sent
        """

        g = self.get = CAGet(self.chan)
        self.check = ref(self.get)

        self.chan.doCon()
        self.assertEqual(len(self.chan._circ._sent), 1)
        self.assertEqual(len(self.chan._circ.pendingActions), 1)

        pkt, _ = self.chan._circ._sent[0]
        self.assertEqual(len(pkt), 16)
        pkt, extra = CAmessage.unpack(pkt)

        self.assertEqual(len(extra), 0)
        self.assertEqual(pkt.cmd, 15)
        self.assertEqual(pkt.p1, self.chan.sid)
        self.assertIn(pkt.p2, self.chan._circ.pendingActions)

        self.get.close()

        del self.get

    def test_canceldead(self):
        """Connect, lose connection, cancel
        """

        g = self.get = CAGet(self.chan)
        self.check = ref(self.get)

        self.chan.doCon()
        pkt, _ = self.chan._circ._sent.pop(0)
        self.assertEqual(len(pkt), 16)
        pkt, extra = CAmessage.unpack(pkt)

        self.assertEqual(len(extra), 0)
        self.assertEqual(pkt.cmd, 15)

        self.chan.doLost()

        self.get.close()

        del self.get