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.
morrowa@51
     1
# CloseTestPing.py
morrowa@51
     2
# Tests the closing negotiation facilities of the BLIP 1.1 protocol
morrowa@51
     3
morrowa@51
     4
from BLIP import Connection, OutgoingRequest
morrowa@51
     5
morrowa@51
     6
import unittest
morrowa@51
     7
import asyncore
morrowa@51
     8
import logging
morrowa@51
     9
morrowa@51
    10
class CloseTestPing(unittest.TestCase):
morrowa@51
    11
    
morrowa@51
    12
    def handleCloseRefusal(self, resp):
morrowa@51
    13
        logging.info("Close request was refused!")
morrowa@51
    14
    
morrowa@51
    15
    def setUp(self):
morrowa@51
    16
        self.connection = Connection( ('localhost', 1337) )
morrowa@51
    17
        self.connection.onCloseRefused = self.handleCloseRefusal
morrowa@51
    18
    
morrowa@51
    19
    def handleResponse(self, resp):
morrowa@51
    20
        logging.info("Got response...")
morrowa@51
    21
    
morrowa@51
    22
    def testClose(self):
morrowa@51
    23
        req = OutgoingRequest(self.connection, "Ping")
morrowa@51
    24
        req.response.onComplete = self.handleResponse
morrowa@51
    25
        req.send()
morrowa@51
    26
        
morrowa@51
    27
        asyncore.loop(timeout=1, count=5)
morrowa@51
    28
        
morrowa@51
    29
        self.connection.close()
morrowa@51
    30
        
morrowa@51
    31
        asyncore.loop()
morrowa@51
    32
morrowa@51
    33
morrowa@51
    34
if __name__ == '__main__':
morrowa@51
    35
    logging.basicConfig(level=logging.DEBUG)
morrowa@51
    36
    unittest.main()