Changeset 9822
- Timestamp:
- 06/19/08 01:58:19 (6 months ago)
- Location:
- branches/bosh_support
- Files:
-
- 3 added
- 4 modified
-
src/common/xmpp/debug.py (modified) (1 diff)
-
src/common/xmpp/idlequeue.py (modified) (2 diffs)
-
src/common/xmpp/transports_nb.py (modified) (5 diffs)
-
src/common/xmpp/transports_new.py (added)
-
test/test_client_nb.py (modified) (9 diffs)
-
test/test_nonblockingtcp.py (added)
-
test/xmpp_mocks.py (added)
Legend:
- Unmodified
- Added
- Removed
-
branches/bosh_support/src/common/xmpp/debug.py
r9487 r9822 155 155 # show(), set this to 0 156 156 # 157 validate_flags = 1,157 validate_flags = 0, 158 158 # 159 159 # If you dont want the welcome message, set to 0 -
branches/bosh_support/src/common/xmpp/idlequeue.py
r8704 r9822 54 54 55 55 def remove_timeout(self, fd): 56 print 'read timeout removed for fd %s' % fd 56 57 if self.read_timeouts.has_key(fd): 57 58 del(self.read_timeouts[fd]) … … 69 70 ''' set a new timeout, if it is not removed after 'seconds', 70 71 then obj.read_timeout() will be called ''' 72 print 'read timeout set for fd %s on %s seconds' % (fd, seconds) 71 73 timeout = self.current_time() + seconds 72 74 self.read_timeouts[fd] = timeout -
branches/bosh_support/src/common/xmpp/transports_nb.py
r9794 r9822 338 338 339 339 def _plug_idle(self): 340 # readable if socket is connected or disconnecting 340 341 readable = self.state != 0 342 # writeable if sth to send 341 343 if self.sendqueue or self.sendbuff: 342 344 writable = True … … 347 349 348 350 def pollout(self): 351 print 'pollout called - send possible' 349 352 if self.state == 0: 350 353 self.connect_to_next_ip() … … 360 363 361 364 def pollin(self): 365 print 'pollin called - receive possible' 362 366 self._do_receive() 363 367 … … 584 588 585 589 try: 590 print "==============sock.connect called" 586 591 self._sock.connect(self._server) 587 592 self._sock.setblocking(False) … … 589 594 (errnum, errstr) = ee 590 595 # in progress, or would block 596 print "errnum: %s" % errnum 591 597 if errnum in (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK): 592 598 self.state = 1 -
branches/bosh_support/test/test_client_nb.py
r9794 r9822 1 import unittest , threading2 from mock import Mock1 import unittest 2 from xmpp_mocks import * 3 3 4 import sys, time,os.path4 import sys, os.path 5 5 6 6 gajim_root = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..') … … 8 8 sys.path.append(gajim_root + '/src/common/xmpp') 9 9 10 import client_nb , idlequeue10 import client_nb 11 11 12 12 ''' … … 16 16 ''' 17 17 18 idlequeue_interval = 0.219 '''20 IdleQueue polling interval. 200ms is used in Gajim as default21 '''22 18 23 19 xmpp_server_port = ('xmpp.example.org',5222) … … 27 23 ''' 28 24 29 credentials = [' primus', 'l0v3', 'testclient']25 credentials = ['login', 'pass', 'testclient'] 30 26 ''' 31 27 [username, password, passphrase] 32 28 Script will autheticate itself with this credentials on above mentioned server. 33 29 ''' 34 35 36 class MockConnectionClass(Mock):37 '''38 Class simulating Connection class from src/common/connection.py39 40 It is derived from Mock in order to avoid defining all methods41 from real Connection that are called from NBClient or Dispatcher42 ( _event_dispatcher for example)43 '''44 45 def __init__(self, *args):46 self.event = threading.Event()47 '''48 is used for waiting on connect, auth and disconnect callbacks49 '''50 51 self.event.clear()52 Mock.__init__(self, *args)53 54 def on_connect(self, *args):55 '''56 Method called on succesful connecting - after receiving <stream:features>57 from server (NOT after TLS stream restart).58 '''59 60 #print 'on_connect - args:'61 #for i in args:62 # print ' %s' % i63 self.connect_failed = False64 self.event.set()65 66 def on_connect_failure(self, *args):67 '''68 Method called on failure while connecting - on everything from TCP error69 to error during TLS handshake70 '''71 72 #print 'on_connect failure - args:'73 #for i in args:74 # print ' %s' % i75 self.connect_failed = True76 self.event.set()77 78 def on_auth(self, con, auth):79 '''80 Method called after authentication is done regardless on the result.81 82 :Parameters:83 con : NonBlockingClient84 reference to authenticated object85 auth : string86 type of authetication in case of success ('old_auth', 'sasl') or87 None in case of auth failure88 '''89 90 #print 'on_auth - args:'91 #print ' con: %s' % con92 #print ' auth: %s' % auth93 self.auth_connection = con94 self.auth = auth95 self.event.set()96 97 def wait(self):98 '''99 Waiting until some callback sets the event and clearing the event subsequently.100 '''101 102 self.event.wait()103 self.event.clear()104 105 106 107 108 class IdleQueueThread(threading.Thread):109 '''110 Thread for regular processing of idlequeue.111 '''112 def __init__(self):113 self.iq = idlequeue.IdleQueue()114 self.stop = threading.Event()115 '''116 Event used to stopping the thread main loop.117 '''118 119 self.stop.clear()120 threading.Thread.__init__(self)121 122 def run(self):123 while not self.stop.isSet():124 self.iq.process()125 time.sleep(idlequeue_interval)126 self.iq.process()127 128 def stop_thread(self):129 self.stop.set()130 131 132 133 30 134 31 class TestNonBlockingClient(unittest.TestCase): … … 148 45 server=xmpp_server_port[0], 149 46 port=xmpp_server_port[1], 150 on_connect= self.connection.on_connect,151 on_connect_failure= self.connection.on_connect_failure,47 on_connect=lambda *args: self.connection.on_connect(True, *args), 48 on_connect_failure=lambda *args: self.connection.on_connect(False, *args), 152 49 caller=self.connection 153 50 ) … … 181 78 182 79 # if on_connect was called, client has to be connected and vice versa 183 if self.connection.connect_failed: 80 if self.connection.connect_succeeded: 81 self.assert_(self.client.isConnected()) 82 else: 184 83 self.assert_(not self.client.isConnected()) 185 else:186 self.assert_(self.client.isConnected())187 84 188 85 def client_auth(self, username, password, resource, sasl): … … 204 101 Does disconnecting of connected client. Returns when TCP connection is closed. 205 102 ''' 206 self.client.start_disconnect(None, on_disconnect=self.connection. event.set)103 self.client.start_disconnect(None, on_disconnect=self.connection.set_event) 207 104 208 105 print 'waiting for disconnecting...' … … 261 158 self.open_stream(xmpp_server_port) 262 159 self.assert_(self.client.isConnected()) 263 self.client_auth(credentials[0], "wrong pass", credentials[2], sasl= 0)160 self.client_auth(credentials[0], "wrong pass", credentials[2], sasl=1) 264 161 self.assert_(self.connection.auth is None) 265 162 self.do_disconnect() … … 272 169 if __name__ == '__main__': 273 170 274 suite = unittest.TestLoader().loadTestsFromTestCase(TestNonBlockingClient) 171 #suite = unittest.TestLoader().loadTestsFromTestCase(TestNonBlockingClient) 172 suite = unittest.TestSuite() 173 suite.addTest(TestNonBlockingClient('test_proper_connect_sasl')) 174 275 175 unittest.TextTestRunner(verbosity=2).run(suite) 276 176
