def test_ack(): # Create environment server, session, transport, conn = _get_test_environment() # Send message with ACK transport.recv(proto.message(None, 'abc', 1)) # Check that message was received by the connection eq_(conn.pop_incoming(), 'abc') # Check for ACK eq_(transport.pop_outgoing(), '3:::abc') eq_(transport.pop_outgoing(), '6:::1') # Send with ACK def handler(message): eq_(message, 'abc') conn.send('yes') conn.send('abc', handler) eq_(transport.pop_outgoing(), '3:1::abc') # Send ACK from client transport.recv('6:::1') # Check if handler was called eq_(transport.pop_outgoing(), '3:::yes')
def run(self): message = {} message['type'] = 'datachanged' message['data'] = copy.copy(self.message) del message['data']['user'] del message['data']['session'] message = ujson.encode(message) for conn in CONNECTIONS: if conn.user and conn.user['username'] == self.message['user'] \ and conn.session_id != self.message['session']: try: conn.send(message) except Exception, e: logging.error( "Failed to send data change notification to session %s: %s" % (conn.session_id, e))
def run(self): message = {} message["type"] = "datachanged" message["data"] = copy.copy(self.message) del message["data"]["user"] del message["data"]["session"] message = ujson.encode(message) for conn in CONNECTIONS: if ( conn.user and conn.user["username"] == self.message["user"] and conn.session_id != self.message["session"] ): try: conn.send(message) except Exception, e: logging.error("Failed to send data change notification to session %s: %s" % (conn.session_id, e))
def test_ack(): # Create environment server, session, transport, conn = _get_test_environment() # Send message with ACK transport.recv(proto.message(None, 'abc', 1)) # Check that message was received by the connection eq_(conn.pop_incoming(), 'abc') # Check for ACK eq_(transport.pop_outgoing(), '3:::abc') eq_(transport.pop_outgoing(), '6:::1') # Send with ACK def handler(msg, data): eq_(msg, 'abc') eq_(data, None) conn.send('yes') conn.send('abc', handler) eq_(transport.pop_outgoing(), '3:1::abc') # Send ACK from client transport.recv('6:::1') # Check if handler was called eq_(transport.pop_outgoing(), '3:::yes') # Test ack with event # Send event with multiple parameters transport.recv(proto.event(None, 'test', 1, a=10, b=20)) # Check outgoing eq_(transport.pop_outgoing(), proto.event(None, 'test', None, a=10, b=20)) eq_(transport.pop_outgoing(), proto.ack(None, 1, 'test'))
def handler(message): eq_(message, 'abc') conn.send('yes')
def handler(msg, data): eq_(msg, 'abc') eq_(data, None) conn.send('yes')
def handler(msg, data): eq_(msg, "abc") eq_(data, None) conn.send("yes")