Esempio n. 1
0
 def test_server_close_connection(self):
     c = Client()
     c2 = Client()
     yield c.connect()
     yield c2.connect()
     future1 = c.call('BLPOP', 'test_server_close_connection', 0)
     future2 = self._close_connection(c2)
     res = yield [future1, future2]
     self.assertTrue(isinstance(res[0], ConnectionError))
     self.assertFalse(c.is_connected())
     yield c.connect()
     res2 = yield c.call("PING")
     self.assertEqual(res2, b"PONG")
     c.disconnect()
     c2.disconnect()
Esempio n. 2
0
 def test_server_close_connection(self):
     c = Client()
     c2 = Client()
     yield c.connect()
     yield c2.connect()
     future1 = c.call('BLPOP', 'test_server_close_connection', 0)
     future2 = self._close_connection(c2)
     res = yield [future1, future2]
     self.assertTrue(isinstance(res[0], ConnectionError))
     self.assertFalse(c.is_connected())
     yield c.connect()
     res2 = yield c.call("PING")
     self.assertEqual(res2, b"PONG")
     c.disconnect()
     c2.disconnect()
Esempio n. 3
0
 def test_empty_pipeline(self):
     c = Client()
     yield c.connect()
     p = Pipeline()
     res = yield c.call(p)
     self.assertTrue(isinstance(res, ClientError))
     c.disconnect()
Esempio n. 4
0
 def test_client_close_connection(self):
     c = Client()
     yield c.connect()
     connection = c._Client__connection
     socket = connection._Connection__socket
     socket.close()
     res = yield c.call("PING")
     self.assertTrue(isinstance(res, ConnectionError))
     self.assertFalse(c.is_connected())
     c.disconnect()
Esempio n. 5
0
 def test_empty_pipeline(self):
     c = Client()
     yield c.connect()
     p = Pipeline()
     try:
         yield c.call(p)
         raise Exception("not raised ClientError")
     except ClientError:
         pass
     c.disconnect()
Esempio n. 6
0
 def test_client_close_connection(self):
     c = Client()
     yield c.connect()
     connection = c._Client__connection
     socket = connection._Connection__socket
     socket.close()
     res = yield c.call("PING")
     self.assertTrue(isinstance(res, ConnectionError))
     self.assertFalse(c.is_connected())
     c.disconnect()
Esempio n. 7
0
 def test_read_timeout2(self):
     c = Client(read_timeout=1, autoconnect=False)
     res = yield c.connect()
     self.assertTrue(res)
     res2 = yield c.call('PING')
     self.assertEqual(res2, b"PONG")
     yield tornado.gen.sleep(2)
     res3 = yield c.call('PING')
     self.assertTrue(isinstance(res3, ConnectionError))
     c.disconnect()
Esempio n. 8
0
 def test_basic_pipeline(self):
     c = Client()
     yield c.connect()
     p = Pipeline()
     p.stack_call('PING')
     p.stack_call('PING')
     res = yield c.call(p)
     self.assertEqual(len(res), 2)
     self.assertEqual(res[0], b'PONG')
     self.assertEqual(res[1], b'PONG')
     c.disconnect()
Esempio n. 9
0
 def test_read_timeout1(self):
     orig_constructor = socket.socket
     socket.socket = functools.partial(fake_socket_constructor,
                                       FakeSocketObject5)
     c = Client(read_timeout=1)
     res = yield c.connect()
     self.assertTrue(res)
     res2 = yield c.call('PING')
     self.assertTrue(isinstance(res2, ConnectionError))
     c.disconnect()
     socket.socket = orig_constructor
Esempio n. 10
0
 def test_pubsub(self):
     c = PubSubClient()
     c2 = Client()
     yield c.connect()
     yield c2.connect()
     try:
         yield c.pubsub_pop_message()
         raise Exception("exception not raised")
     except Exception:
         pass
     res = yield c.pubsub_subscribe("foo1", "foo2")
     self.assertTrue(res)
     self.assertTrue(c.subscribed)
     self.assertFalse(c2.subscribed)
     try:
         yield c.call("PING")
         raise Exception("exception not raised")
     except Exception:
         pass
     res = yield c.pubsub_psubscribe("bar1*", "bar2*")
     self.assertTrue(res)
     tornado.ioloop.IOLoop.instance().add_future(self.publish(c2), None)
     msg = yield c.pubsub_pop_message()
     self.assertEqual(msg[2], b"value1")
     msg = yield c.pubsub_pop_message()
     self.assertEqual(msg[2], b"value2")
     msg = yield c.pubsub_pop_message()
     self.assertEqual(msg[3], b"value3")
     msg = yield c.pubsub_pop_message()
     self.assertEqual(msg[3], b"value4")
     msg = yield c.pubsub_pop_message(deadline=1)
     self.assertEqual(msg, None)
     yield c.pubsub_unsubscribe("foo1")
     yield c2.call("PUBLISH", "foo1", "value1")
     c2.disconnect()
     msg = yield c.pubsub_pop_message(deadline=1)
     self.assertEqual(msg, None)
     yield c.pubsub_unsubscribe("foo2")
     yield c.pubsub_unsubscribe("foobar")
     yield c.pubsub_punsubscribe("foobar*")
     yield c.pubsub_punsubscribe("bar1*")
     yield c.pubsub_punsubscribe("bar2*")
     self.assertFalse(c.subscribed)
     c.disconnect()
Esempio n. 11
0
 def test_init(self):
     c = Client()
     yield c.connect()
     c.disconnect()
Esempio n. 12
0
 def test_reply_error(self):
     c = Client()
     yield c.connect()
     res = yield c.call('BADCOMMAND')
     self.assertTrue(isinstance(res, ClientError))
     c.disconnect()
Esempio n. 13
0
 def test_ping(self):
     c = Client()
     yield c.connect()
     res = yield c.call('PING')
     self.assertEqual(res, b"PONG")
     c.disconnect()
Esempio n. 14
0
 def test_init_with_db(self):
     c = Client(db=2)
     yield c.connect()
     self.assertEqual(c.db, 2)
     c.disconnect()
Esempio n. 15
0
 def test_discard(self):
     c = Client()
     yield c.connect()
     c.async_call('PING')
     c.disconnect()
Esempio n. 16
0
 def test_init(self):
     c = Client()
     yield c.connect()
     c.disconnect()
Esempio n. 17
0
 def test_discard(self):
     c = Client()
     yield c.connect()
     c.async_call('PING')
     c.disconnect()