Python/CloseTestPing.py
author morrowa@betelgeuse.local
Tue Jun 23 11:44:30 2009 -0700 (2009-06-23)
changeset 51 de59ce19f42e
child 53 e9f209a24d53
permissions -rw-r--r--
BROKEN COMMIT. Majority of code to handle closing has been added. Listeners do not close correctly.
     1 # CloseTestPing.py
     2 # Tests the closing negotiation facilities of the BLIP 1.1 protocol
     3 
     4 from BLIP import Connection, OutgoingRequest
     5 
     6 import unittest
     7 import asyncore
     8 import logging
     9 
    10 class CloseTestPing(unittest.TestCase):
    11     
    12     def handleCloseRefusal(self, resp):
    13         logging.info("Close request was refused!")
    14     
    15     def setUp(self):
    16         self.connection = Connection( ('localhost', 1337) )
    17         self.connection.onCloseRefused = self.handleCloseRefusal
    18     
    19     def handleResponse(self, resp):
    20         logging.info("Got response...")
    21     
    22     def testClose(self):
    23         req = OutgoingRequest(self.connection, "Ping")
    24         req.response.onComplete = self.handleResponse
    25         req.send()
    26         
    27         asyncore.loop(timeout=1, count=5)
    28         
    29         self.connection.close()
    30         
    31         asyncore.loop()
    32 
    33 
    34 if __name__ == '__main__':
    35     logging.basicConfig(level=logging.DEBUG)
    36     unittest.main()