]> git.mxchange.org Git - quix0rs-apt-p2p.git/blobdiff - test_airhook.py
callbacks now return a dict now that has the _krpc_sender connection information
[quix0rs-apt-p2p.git] / test_airhook.py
index d6cfb13b7f7cfd173557cbc98e1c80f51b0beb3f..407cf1fe5f141ae3ee454055c3c7fa2419f7efc8 100644 (file)
@@ -547,6 +547,8 @@ class BasicTests(unittest.TestCase):
         self.assertEqual(a.outMsgNums[(a.outSeq-1) % 256], 254)
 
     def testConnectionReset(self):
+        self.testTwoWayBlast()
+        self.b.protocol.q = []
         a = self.a
         b = self.b
         msg = swap(a, noisy=self.noisy)
@@ -587,6 +589,57 @@ class BasicTests(unittest.TestCase):
         self.assertEqual(len(b.protocol.q), 2)
         self.assertEqual(b.protocol.q[1], "TESTING2")
 
+    def testRecipientReset(self):
+        self.testTwoWayBlast()
+        self.b.protocol.q = []
+        self.noisy = 1
+        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.b = AirhookConnection()
+        self.b.makeConnection(DummyTransport())
+        self.b.protocol = Receiver()
+        self.b.addr = ('127.0.0.1', 4444)
+        b = self.b
+        
+        msg = swap(a, noisy=self.noisy)
+        b.datagramReceived(msg)
+
+        msg = swap(b, noisy=self.noisy)
+        a.datagramReceived(msg)
+        
+        a.omsgq.append("TESTING2")
+        self.assertEqual(len(b.protocol.q), 0)
+        msg = swap(a, noisy=self.noisy)
+        b.datagramReceived(msg)
+
+        msg = swap(b, noisy=self.noisy)
+        a.datagramReceived(msg)
+
+        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)
+        self.assertEqual(b.protocol.q[0], "TESTING2")
+
         
 class StreamTests(unittest.TestCase):
     def setUp(self):
@@ -709,4 +762,4 @@ class EchoReactorStreamBig(unittest.TestCase):
         reactor.iterate()
         self.assertEqual(self.ac.protocol.buf, msg)
 
-        
\ No newline at end of file
+