- def setUp(self):
- self.a = AirhookConnection(StringIO(), (None, 'localhost', 4040), None)
- self.b = AirhookConnection(StringIO(), (None, 'localhost', 4040), None)
- self.noisy = 0
- def testSimple(self):
- a = self.a
- b = self.b
-
- TESTMSG = "Howdy, Y'All!"
- a.omsgq.append(TESTMSG)
- a.sendNext()
- msg = swap(a, '>', self.noisy)
-
- b.datagramReceived(msg)
- msg = swap(b, '<', self.noisy)
- a.datagramReceived(msg)
- msg = swap(a, '>', self.noisy)
- b.datagramReceived(msg)
-
- self.assertEqual(b.inMsg, 1)
- self.assertEqual(len(b.imsgq), 1)
- self.assertEqual(b.imsgq[0], TESTMSG)
-
- msg = swap(b, '<', self.noisy)
-
- a.datagramReceived(msg)
- msg = swap(a, '>', self.noisy)
- b.datagramReceived(msg)
-
- def testLostFirst(self):
- a = self.a
- b = self.b
-
- TESTMSG = "Howdy, Y'All!"
- TESTMSG2 = "Yee Haw"
-
- a.omsgq.append(TESTMSG)
- msg = swap(a, '>', self.noisy)
- b.datagramReceived(msg)
- msg = swap(b, '<', self.noisy)
- self.assertEqual(b.state, sent)
- a.datagramReceived(msg)
- msg = swap(a, '>', self.noisy)
-
- del(msg) # dropping first message
-
- a.omsgq.append(TESTMSG2)
- msg = swap(a, '>', self.noisy)
-
- b.datagramReceived(msg)
- self.assertEqual(b.state, confirmed)
- self.assertEqual(len(b.imsgq), 1)
- self.assertEqual(b.imsgq[0], TESTMSG2)
- self.assertEqual(b.weMissed, [(1, 0)])
- msg = swap(b, '<', self.noisy)
-
- a.datagramReceived(msg)
-
- msg = swap(a, '>', self.noisy)
-
- b.datagramReceived(msg)
- self.assertEqual(len(b.imsgq), 2)
- b.imsgq.sort()
- l = [TESTMSG2, TESTMSG]
- l.sort()
- self.assertEqual(b.imsgq,l)
-
- msg = swap(b, '<', self.noisy)
-
- a.datagramReceived(msg)
- msg = swap(a, '>', self.noisy)
- b.datagramReceived(msg)
-
- msg = swap(b, '<', self.noisy)
- a.datagramReceived(msg)
- msg = swap(a, '>', self.noisy)
- b.datagramReceived(msg)
-
- msg = swap(b, '<', self.noisy)
- a.datagramReceived(msg)
- msg = swap(a, '>', self.noisy)
-
- self.assertEqual(len(b.imsgq), 2)
- b.imsgq.sort()
- l = [TESTMSG2, TESTMSG]
- l.sort()
- self.assertEqual(b.imsgq,l)
-
- def testLostSecond(self):
- a = self.a
- b = self.b
-
- TESTMSG = "Howdy, Y'All!"
- TESTMSG2 = "Yee Haw"
-
- a.omsgq.append(TESTMSG)
- msg = swap(a, '>', self.noisy)
- b.datagramReceived(msg)
- msg = swap(b, '<', self.noisy)
- self.assertEqual(b.state, sent)
- a.datagramReceived(msg)
- msg = swap(a, '>', self.noisy)
-
- a.omsgq.append(TESTMSG2)
- msg2 = swap(a, '>', self.noisy)
- del(msg2) # dropping second message
-
- assert(a.outMsgs[1] != None)
-
- b.datagramReceived(msg)
- self.assertEqual(b.state, confirmed)
- self.assertEqual(len(b.imsgq), 1)
- self.assertEqual(b.imsgq[0], TESTMSG)
- self.assertEqual(b.inMsg, 1)
- self.assertEqual(b.weMissed, [])
- msg = swap(b, '<', self.noisy)
-
- a.datagramReceived(msg)
- assert(a.outMsgs[1] != None)
- msg = swap(a, '>', self.noisy)
-
- b.datagramReceived(msg)
- self.assertEqual(b.state, confirmed)
- self.assertEqual(len(b.imsgq), 1)
- self.assertEqual(b.imsgq[0], TESTMSG)
- self.assertEqual(b.weMissed, [(2, 1)])
- msg = swap(b, '<', self.noisy)
-
- a.datagramReceived(msg)
- msg = swap(a, '>', self.noisy)
-
- b.datagramReceived(msg)
- self.assertEqual(len(b.imsgq), 2)
- b.imsgq.sort()
- l = [TESTMSG2, TESTMSG]
- l.sort()
- self.assertEqual(b.imsgq,l)
-
- msg = swap(b, '<', self.noisy)
-
- a.datagramReceived(msg)
- msg = swap(a, '>', self.noisy)
-
- b.datagramReceived(msg)
-
- msg = swap(b, '<', self.noisy)
-
- a.datagramReceived(msg)
- msg = swap(a, '>', self.noisy)
-
- b.datagramReceived(msg)
-
- msg = swap(b, '<', self.noisy)
-
- a.datagramReceived(msg)
-
-
- msg = swap(a, '>', self.noisy)
-
- self.assertEqual(len(b.imsgq), 2)
- b.imsgq.sort()
- l = [TESTMSG2, TESTMSG]
- l.sort()
- self.assertEqual(b.imsgq,l)
-
- def testDoubleDouble(self):
- a = self.a
- b = self.b
-
- TESTMSGA = "Howdy, Y'All!"
- TESTMSGB = "Yee Haw"
- TESTMSGC = "FOO BAR"
- TESTMSGD = "WING WANG"
-
- a.omsgq.append(TESTMSGA)
- a.omsgq.append(TESTMSGB)
-
- b.omsgq.append(TESTMSGC)
- b.omsgq.append(TESTMSGD)
-
-
- msg = swap(a, '>', self.noisy)
-
-
- b.datagramReceived(msg)
- self.assertEqual(b.state, sent)
-
- msg = swap(b, '<', self.noisy)
- a.datagramReceived(msg)
-
- msg = swap(a, '>', self.noisy)
-
- b.datagramReceived(msg)
- self.assertEqual(len(b.imsgq), 2)
- l = [TESTMSGA, TESTMSGB]
- l.sort();b.imsgq.sort()
- self.assertEqual(b.imsgq, l)
- self.assertEqual(b.inMsg, 2)
-
- msg = swap(b, '<', self.noisy)
- a.datagramReceived(msg)
-
- self.assertEqual(len(a.imsgq), 2)
- l = [TESTMSGC, TESTMSGD]
- l.sort();a.imsgq.sort()
- self.assertEqual(a.imsgq, l)
- self.assertEqual(a.inMsg, 2)
-
- def testDoubleDoubleProb(self, prob=0.25):
- a = self.a
- b = self.b
- TESTMSGA = "Howdy, Y'All!"
- TESTMSGB = "Yee Haw"
- TESTMSGC = "FOO BAR"
- TESTMSGD = "WING WANG"
-
- a.omsgq.append(TESTMSGA)
- a.omsgq.append(TESTMSGB)
-
- b.omsgq.append(TESTMSGC)
- b.omsgq.append(TESTMSGD)
-
- while a.state != confirmed or b.state != confirmed or ord(msga[0]) & FLAG_NEXT or ord(msgb[0]) & FLAG_NEXT :
- msga = swap(a, '>', self.noisy)
-
- if rand(0,1) < prob:
- b.datagramReceived(msga)
-
- msgb = swap(b, '<', self.noisy)
-
- if rand(0,1) < prob:
- a.datagramReceived(msgb)
-
- self.assertEqual(a.state, confirmed)
- self.assertEqual(b.state, confirmed)
- self.assertEqual(len(b.imsgq), 2)
- l = [TESTMSGA, TESTMSGB]
- l.sort();b.imsgq.sort()
- self.assertEqual(b.imsgq, l)
-
- self.assertEqual(len(a.imsgq), 2)
- l = [TESTMSGC, TESTMSGD]
- l.sort();a.imsgq.sort()
- self.assertEqual(a.imsgq, l)
-
- def testOneWayBlast(self, num = 2**8):
- a = self.a
- b = self.b
- import sha
-
-
- for i in xrange(num):
- a.omsgq.append(sha.sha(`i`).digest())
- msg = swap(a, '>', self.noisy)
- while a.state != confirmed or ord(msg[0]) & FLAG_NEXT:
- b.datagramReceived(msg)
- msg = swap(b, '<', self.noisy)
-
- a.datagramReceived(msg)
- msg = swap(a, '>', self.noisy)
-
- self.assertEqual(len(b.imsgq), num)
-
- def testTwoWayBlast(self, num = 2**9, prob=0.5):
- a = self.a
- b = self.b
- import sha
-
-
- for i in xrange(num):
- a.omsgq.append(sha.sha('a' + `i`).digest())
- b.omsgq.append(sha.sha('b' + `i`).digest())
-
- while a.omsgq or b.omsgq or a.weMissed or b.weMissed or ord(msga[0]) & (FLAG_NEXT | FLAG_MISSED) or ord(msgb[0]) & (FLAG_NEXT | FLAG_MISSED):
- if rand(0,1) < prob:
- msga = swap(a, '>', self.noisy)
- b.datagramReceived(msga)
- else:
- msga = swap(a, '>', 0)
- if rand(0,1) < prob:
- msgb = swap(b, '<', self.noisy)
- a.datagramReceived(msgb)
- else:
- msgb = swap(b, '<', 0)
-
-
-
- self.assertEqual(len(a.imsgq), num)
- self.assertEqual(len(b.imsgq), num)
-
- def testLimitMessageNumbers(self):
- a = self.a
- b = self.b
- import sha
-
- msg = swap(a, noisy=self.noisy)
- b.datagramReceived(msg)
-
- msg = swap(b, noisy=self.noisy)
- a.datagramReceived(msg)
-
-
- for i in range(5000):
- a.omsgq.append(sha.sha('a' + 'i').digest())
-
- for i in range(31):
- msg = swap(a, noisy=self.noisy)
- self.assertEqual(a.obSeq, 0)
- self.assertEqual(a.outMsgNums[a.obSeq], 0)
- self.assertEqual(a.next, 254)
- self.assertEqual(a.outMsgNums[19], 254)
-
-class OrderedTests(unittest.TestCase):
- def setUp(self):
- self.noisy = 0
- class queuer:
- def __init__(self):
- self.msg = ""
- def dataCameIn(self, host, port, data):
- self.msg+= data
- self.A = queuer()
- self.B = queuer()
- self.a = OrderedConnection(StringIO(), (None, 'localhost', 4040), self.A)
- self.b = OrderedConnection(StringIO(), (None, 'localhost', 4040), self.B)
-
- def testOrderedSimple(self, num = 2**17, prob=1.0):
- f = open('/dev/urandom', 'r')
- a = self.a
- b = self.b
- A = self.A
- B = self.B
-
- MSGA = f.read(num)
- MSGB = f.read(num)
- self.a.sendSomeData(MSGA)
- self.b.sendSomeData(MSGB)
-
- while a.omsgq or b.omsgq or a.weMissed or b.weMissed or ord(msga[0]) & (FLAG_NEXT | FLAG_MISSED) or ord(msgb[0]) & (FLAG_NEXT | FLAG_MISSED):
- if rand(0,1) < prob:
- msga = swap(a, '>', self.noisy)
- b.datagramReceived(msga)
- else:
- msga = swap(a, '>', 0)
- if rand(0,1) < prob:
- msgb = swap(b, '<', self.noisy)
- a.datagramReceived(msgb)
- else:
- msgb = swap(b, '<', 0)
- self.assertEqual(self.A.msg, MSGB)
- self.assertEqual(self.B.msg, MSGA)
-
- def testOrderedLossy(self, num = 2**17, prob=0.5):
- self.testOrderedSimple(num, prob)
+ def setUp(self):
+ self.noisy = 0
+ self.a = AirhookConnection()
+ self.a.makeConnection(DummyTransport())
+ self.a.addr = ('127.0.0.1', 4444)
+ self.b = AirhookConnection()
+ self.b.makeConnection(DummyTransport())
+ self.b.addr = ('127.0.0.1', 4444)
+ self.a.protocol = Receiver()
+ self.b.protocol = Receiver()
+
+ def testSimple(self):
+ a = self.a
+ b = self.b
+
+ TESTMSG = "Howdy, Y'All!"
+ a.omsgq.append(TESTMSG)
+ a.sendNext()
+ msg = swap(a, '>', self.noisy)
+
+ b.datagramReceived(msg)
+ msg = swap(b, '<', self.noisy)
+ a.datagramReceived(msg)
+ msg = swap(a, '>', self.noisy)
+ b.datagramReceived(msg)
+
+ self.assertEqual(b.inMsg, 1)
+ self.assertEqual(len(b.protocol.q), 1)
+ self.assertEqual(b.protocol.q[0], TESTMSG)
+
+ msg = swap(b, '<', self.noisy)
+
+ a.datagramReceived(msg)
+ msg = swap(a, '>', self.noisy)
+ b.datagramReceived(msg)
+
+ def testLostFirst(self):
+ a = self.a
+ b = self.b
+
+ TESTMSG = "Howdy, Y'All!"
+ TESTMSG2 = "Yee Haw"
+
+ a.omsgq.append(TESTMSG)
+ msg = swap(a, '>', self.noisy)
+ b.datagramReceived(msg)
+ msg = swap(b, '<', self.noisy)
+ self.assertEqual(b.state, sent)
+ a.datagramReceived(msg)
+ msg = swap(a, '>', self.noisy)
+
+ del(msg) # dropping first message
+
+ a.omsgq.append(TESTMSG2)
+ msg = swap(a, '>', self.noisy)
+
+ b.datagramReceived(msg)
+ self.assertEqual(b.state, confirmed)
+ self.assertEqual(len(b.protocol.q), 1)
+ self.assertEqual(b.protocol.q[0], TESTMSG2)
+ self.assertEqual(b.weMissed, [(1, 0)])
+ msg = swap(b, '<', self.noisy)
+
+ a.datagramReceived(msg)
+
+ msg = swap(a, '>', self.noisy)
+
+ b.datagramReceived(msg)
+ self.assertEqual(len(b.protocol.q), 2)
+ b.protocol.q.sort()
+ l = [TESTMSG2, TESTMSG]
+ l.sort()
+ self.assertEqual(b.protocol.q,l)
+
+ msg = swap(b, '<', self.noisy)
+
+ a.datagramReceived(msg)
+ msg = swap(a, '>', self.noisy)
+ b.datagramReceived(msg)
+
+ msg = swap(b, '<', self.noisy)
+ a.datagramReceived(msg)
+ msg = swap(a, '>', self.noisy)
+ b.datagramReceived(msg)
+
+ msg = swap(b, '<', self.noisy)
+ a.datagramReceived(msg)
+ msg = swap(a, '>', self.noisy)
+
+ self.assertEqual(len(b.protocol.q), 2)
+ b.protocol.q.sort()
+ l = [TESTMSG2, TESTMSG]
+ l.sort()
+ self.assertEqual(b.protocol.q,l)
+
+ def testLostSecond(self):
+ a = self.a
+ b = self.b
+
+ TESTMSG = "Howdy, Y'All!"
+ TESTMSG2 = "Yee Haw"
+
+ a.omsgq.append(TESTMSG)
+ msg = swap(a, '>', self.noisy)
+ b.datagramReceived(msg)
+ msg = swap(b, '<', self.noisy)
+ self.assertEqual(b.state, sent)
+ a.datagramReceived(msg)
+ msg = swap(a, '>', self.noisy)
+
+ a.omsgq.append(TESTMSG2)
+ msg2 = swap(a, '>', self.noisy)
+ del(msg2) # dropping second message
+
+ assert(a.outMsgs[1] != None)
+
+ b.datagramReceived(msg)
+ self.assertEqual(b.state, confirmed)
+ self.assertEqual(len(b.protocol.q), 1)
+ self.assertEqual(b.protocol.q[0], TESTMSG)
+ self.assertEqual(b.inMsg, 1)
+ self.assertEqual(b.weMissed, [])
+ msg = swap(b, '<', self.noisy)
+
+ a.datagramReceived(msg)
+ assert(a.outMsgs[1] != None)
+ msg = swap(a, '>', self.noisy)
+
+ b.datagramReceived(msg)
+ self.assertEqual(b.state, confirmed)
+ self.assertEqual(len(b.protocol.q), 1)
+ self.assertEqual(b.protocol.q[0], TESTMSG)
+ self.assertEqual(b.weMissed, [(2, 1)])
+ msg = swap(b, '<', self.noisy)
+
+ a.datagramReceived(msg)
+ msg = swap(a, '>', self.noisy)
+
+ b.datagramReceived(msg)
+ self.assertEqual(len(b.protocol.q), 2)
+ b.protocol.q.sort()
+ l = [TESTMSG2, TESTMSG]
+ l.sort()
+ self.assertEqual(b.protocol.q,l)
+
+ msg = swap(b, '<', self.noisy)
+
+ a.datagramReceived(msg)
+ msg = swap(a, '>', self.noisy)
+
+ b.datagramReceived(msg)
+
+ msg = swap(b, '<', self.noisy)
+
+ a.datagramReceived(msg)
+ msg = swap(a, '>', self.noisy)
+
+ b.datagramReceived(msg)
+
+ msg = swap(b, '<', self.noisy)
+
+ a.datagramReceived(msg)
+
+
+ msg = swap(a, '>', self.noisy)
+
+ self.assertEqual(len(b.protocol.q), 2)
+ b.protocol.q.sort()
+ l = [TESTMSG2, TESTMSG]
+ l.sort()
+ self.assertEqual(b.protocol.q,l)
+
+ def testDoubleDouble(self):
+ a = self.a
+ b = self.b
+
+ TESTMSGA = "Howdy, Y'All!"
+ TESTMSGB = "Yee Haw"
+ TESTMSGC = "FOO BAR"
+ TESTMSGD = "WING WANG"
+
+ a.omsgq.append(TESTMSGA)
+ a.omsgq.append(TESTMSGB)
+
+ b.omsgq.append(TESTMSGC)
+ b.omsgq.append(TESTMSGD)
+
+
+ msg = swap(a, '>', self.noisy)
+
+
+ b.datagramReceived(msg)
+
+ msg = swap(b, '<', self.noisy)
+ self.assertEqual(b.state, sent)
+ a.datagramReceived(msg)
+
+ msg = swap(a, '>', self.noisy)
+
+ b.datagramReceived(msg)
+ self.assertEqual(len(b.protocol.q), 2)
+ l = [TESTMSGA, TESTMSGB]
+ l.sort();b.protocol.q.sort()
+ self.assertEqual(b.protocol.q, l)
+ self.assertEqual(b.inMsg, 2)
+
+ msg = swap(b, '<', self.noisy)
+ a.datagramReceived(msg)
+
+ self.assertEqual(len(a.protocol.q), 2)
+ l = [TESTMSGC, TESTMSGD]
+ l.sort();a.protocol.q.sort()
+ self.assertEqual(a.protocol.q, l)
+ self.assertEqual(a.inMsg, 2)
+
+ def testDoubleDoubleProb(self, prob=0.25):
+ a = self.a
+ b = self.b
+
+ TESTMSGA = "Howdy, Y'All!"
+ TESTMSGB = "Yee Haw"
+ TESTMSGC = "FOO BAR"
+ TESTMSGD = "WING WANG"
+
+ a.omsgq.append(TESTMSGA)
+ a.omsgq.append(TESTMSGB)
+
+ b.omsgq.append(TESTMSGC)
+ b.omsgq.append(TESTMSGD)
+
+ runTillEmpty(a, b, prob, self.noisy)
+
+ self.assertEqual(a.state, confirmed)
+ self.assertEqual(b.state, confirmed)
+ self.assertEqual(len(b.protocol.q), 2)
+ l = [TESTMSGA, TESTMSGB]
+ l.sort();b.protocol.q.sort()
+ self.assertEqual(b.protocol.q, l)
+
+ self.assertEqual(len(a.protocol.q), 2)
+ l = [TESTMSGC, TESTMSGD]
+ l.sort();a.protocol.q.sort()
+ self.assertEqual(a.protocol.q, l)
+
+ def testOneWayBlast(self, num = 2**12):
+ a = self.a
+ b = self.b
+
+ import sha
+
+
+ for i in xrange(num):
+ a.omsgq.append(sha.sha(`i`).digest())
+ runTillEmpty(a, b, noisy=self.noisy)
+
+ self.assertEqual(len(b.protocol.q), num)
+
+ def testTwoWayBlast(self, num = 2**12, prob=0.5):
+ a = self.a
+ b = self.b
+
+ import sha
+
+
+ for i in xrange(num):
+ a.omsgq.append(sha.sha('a' + `i`).digest())
+ b.omsgq.append(sha.sha('b' + `i`).digest())
+
+ runTillEmpty(a, b, prob, self.noisy)
+
+
+ self.assertEqual(len(a.protocol.q), num)
+ self.assertEqual(len(b.protocol.q), num)
+
+ def testLimitMessageNumbers(self):
+ a = self.a
+ b = self.b
+ import sha
+
+ msg = swap(a, noisy=self.noisy)
+ b.datagramReceived(msg)
+
+ msg = swap(b, noisy=self.noisy)
+ a.datagramReceived(msg)
+
+
+ for i in range(5000):
+ a.omsgq.append(sha.sha('a' + 'i').digest())
+
+ for i in range(5000 / 255):
+ msg = swap(a, noisy=self.noisy)
+ self.assertEqual(a.obSeq, 0)
+ self.assertEqual(a.next, 255)
+ self.assertEqual(a.outMsgNums[(a.outSeq-1) % 256], 254)
+
+ def testConnectionReset(self):
+ a = self.a
+ b = self.b
+ msg = swap(a, noisy=self.noisy)
+ b.datagramReceived(msg)
+
+ msg = swap(b, noisy=self.noisy)
+ a.datagramReceived(msg)
+
+ a.omsgq.append("TESTING")
+ msg = swap(a, noisy=self.noisy)
+ b.datagramReceived(msg)
+
+ msg = swap(b, noisy=self.noisy)
+ a.datagramReceived(msg)
+
+ self.assertEqual(b.protocol.q[0], "TESTING")
+ self.assertEqual(b.state, confirmed)
+
+ self.a = AirhookConnection()
+ self.a.makeConnection(DummyTransport())
+ self.a.addr = ('127.0.0.1', 4444)
+ a = self.a
+
+ a.omsgq.append("TESTING2")
+ msg = swap(a, noisy=self.noisy)
+ b.datagramReceived(msg)
+
+ msg = swap(b, noisy=self.noisy)
+ a.datagramReceived(msg)
+
+ self.assertEqual(len(b.protocol.q), 1)
+ msg = swap(a, noisy=self.noisy)
+ b.datagramReceived(msg)
+
+ msg = swap(b, noisy=self.noisy)
+ a.datagramReceived(msg)
+
+ self.assertEqual(len(b.protocol.q), 2)
+ self.assertEqual(b.protocol.q[1], "TESTING2")
+
+
+class StreamTests(unittest.TestCase):
+ def setUp(self):
+ self.noisy = 0
+ self.a = StreamConnection()
+ self.a.makeConnection(DummyTransport())
+ self.a.addr = ('127.0.0.1', 4444)
+ self.b = StreamConnection()
+ self.b.makeConnection(DummyTransport())
+ self.b.addr = ('127.0.0.1', 4444)
+ self.a.protocol = StreamReceiver()
+ self.b.protocol = StreamReceiver()
+
+ def testStreamSimple(self, num = 2**12, prob=1.0):
+ f = open('/dev/urandom', 'r')
+ a = self.a
+ b = self.b
+
+ MSGA = f.read(num)
+ MSGB = f.read(num)
+ self.a.write(MSGA)
+ self.b.write(MSGB)
+
+ runTillEmpty(a, b, prob, self.noisy)
+
+ self.assertEqual(len(a.protocol.buf), len(MSGB))
+ self.assertEqual(len(b.protocol.buf), len(MSGA))
+ self.assertEqual(a.protocol.buf, MSGB)
+ self.assertEqual(b.protocol.buf, MSGA)
+
+ def testStreamLossy(self, num = 2**12, prob=0.5):
+ self.testStreamSimple(num, prob)
+
+class SimpleReactor(unittest.TestCase):
+ def setUp(self):
+ self.noisy = 0
+ self.a = makeReceiver(2020)
+ self.b = makeReceiver(2021)
+ self.ac = self.a.connectionForAddr(('127.0.0.1', 2021))
+ self.bc = self.b.connectionForAddr(('127.0.0.1', 2020))
+ self.ac.noisy = self.noisy
+ self.bc.noisy = self.noisy
+ def testSimple(self):
+ msg = "Testing 1, 2, 3"
+ self.ac.write(msg)
+ reactor.iterate()
+ reactor.iterate()
+ reactor.iterate()
+ self.assertEqual(self.bc.state, confirmed)
+ self.assertEqual(self.bc.protocol.q, [msg])
+
+class SimpleReactorEcho(unittest.TestCase):
+ def setUp(self):
+ self.noisy = 0
+ self.a = makeReceiver(2022)
+ self.b = makeEcho(2023)
+ self.ac = self.a.connectionForAddr(('127.0.0.1', 2023))
+ self.bc = self.b.connectionForAddr(('127.0.0.1', 2022))
+ def testSimple(self):
+ msg = "Testing 1, 2, 3"
+ self.ac.write(msg)
+ reactor.iterate()
+ reactor.iterate()
+ reactor.iterate()
+ reactor.iterate()
+ self.assertEqual(self.ac.protocol.q, [msg])
+ reactor.iterate()
+ reactor.iterate()
+ reactor.iterate()
+ self.assertEqual(self.ac.protocol.q, [msg])
+
+
+class SimpleReactorStream(unittest.TestCase):
+ def setUp(self):
+ self.noisy = 0
+ self.a = makeStreamReceiver(2024)
+ self.b = makeStreamReceiver(2025)
+ self.ac = self.a.connectionForAddr(('127.0.0.1', 2025))
+ self.bc = self.b.connectionForAddr(('127.0.0.1', 2024))
+ def testSimple(self):
+ msg = "Testing 1, 2, 3"
+ self.ac.write(msg)
+ reactor.iterate()
+ reactor.iterate()
+ reactor.iterate()
+ self.assertEqual(self.bc.protocol.buf, msg)
+
+class SimpleReactorStreamBig(unittest.TestCase):
+ def setUp(self):
+ self.noisy = 0
+ self.a = makeStreamReceiver(2026)
+ self.b = makeStreamReceiver(2027)
+ self.ac = self.a.connectionForAddr(('127.0.0.1', 2027))
+ self.bc = self.b.connectionForAddr(('127.0.0.1', 2026))
+ def testBig(self):
+ msg = open('/dev/urandom').read(4096)
+ self.ac.write(msg)
+ reactor.iterate()
+ reactor.iterate()
+ reactor.iterate()
+ reactor.iterate()
+ reactor.iterate()
+ reactor.iterate()
+ reactor.iterate()
+ self.assertEqual(self.bc.protocol.buf, msg)
+
+class EchoReactorStreamBig(unittest.TestCase):
+ def setUp(self):
+ self.noisy = 0
+ self.a = makeStreamReceiver(2028)
+ self.b = makeEcho(2029)
+ self.ac = self.a.connectionForAddr(('127.0.0.1', 2029))
+ def testBig(self):
+ msg = open('/dev/urandom').read(256)
+ self.ac.write(msg)
+ reactor.iterate()
+ reactor.iterate()
+ reactor.iterate()
+ reactor.iterate()
+ reactor.iterate()
+ self.assertEqual(self.ac.protocol.buf, msg)
+
+
\ No newline at end of file