def store(request, event_loop, context, direct_resources, serializer): if request.param == 'sqlalchemy': engine = create_engine('sqlite:///:memory:', connect_args={'check_same_thread': False}, poolclass=StaticPool) context.add_teardown_callback(engine.dispose) if not direct_resources: context.add_resource(engine) engine = 'default' store_ = SQLAlchemyStore(engine=engine, serializer=serializer) elif request.param == 'redis': address = (os.getenv('REDIS_HOST', 'localhost'), 6379) redis = event_loop.run_until_complete( create_reconnecting_redis(address)) context.add_teardown_callback(redis.close) if not direct_resources: context.add_resource(redis) redis = 'default' store_ = RedisStore(client=redis, serializer=serializer) elif request.param == 'mongodb': host = os.getenv('MONGODB_HOST', 'localhost') client = AsyncIOMotorClient(host=host) context.add_teardown_callback(client.close) if not direct_resources: context.add_resource(client) client = 'default' store_ = MongoDBStore(client=client, serializer=serializer) event_loop.run_until_complete(store_.start(context)) return store_
def test_multi_exec(self): redis = yield from create_reconnecting_redis( ('localhost', self.redis_port), db=1, loop=self.loop) self.assertEqual(repr(redis), '<Redis <AutoConnector None>>') m = redis.multi_exec() m.echo('ECHO') res = yield from m.execute() self.assertEqual(res, [b'ECHO'])
def test_multi_exec(server, loop): redis = yield from create_reconnecting_redis( server.tcp_address, db=1, loop=loop) assert repr(redis) == '<Redis <AutoConnector None>>' m = redis.multi_exec() m.echo('ECHO') res = yield from m.execute() assert res == [b'ECHO'] # FIXME: bad interface conn = yield from redis.connection.get_atomic_connection() conn.close() yield from conn.wait_closed()
def test_multi_exec(self): redis = yield from create_reconnecting_redis( ('localhost', self.redis_port), db=1, loop=self.loop) self.assertEqual(repr(redis), '<Redis <AutoConnector None>>') m = redis.multi_exec() m.echo('ECHO') res = yield from m.execute() self.assertEqual(res, [b'ECHO']) # FIXME: bad interface conn = yield from redis.connection.get_atomic_connection() conn.close() yield from conn.wait_closed()
def test_multi_exec(server, loop): redis = yield from create_reconnecting_redis(server.tcp_address, db=1, loop=loop) assert repr(redis) == '<Redis <AutoConnector None>>' m = redis.multi_exec() m.echo('ECHO') res = yield from m.execute() assert res == [b'ECHO'] # FIXME: bad interface conn = yield from redis.connection.get_atomic_connection() conn.close() yield from conn.wait_closed()
def test_recon(self): redis = yield from create_reconnecting_redis( ('localhost', self.redis_port), db=1, loop=self.loop) self.assertEqual(repr(redis), '<Redis <AutoConnector None>>') resp = yield from redis.echo('ECHO') self.assertEqual(resp, b'ECHO') self.assertEqual(repr(redis), '<Redis <AutoConnector <RedisConnection [db:1]>>>') conn_id = id(redis._conn._conn) redis._conn._conn._do_close(ValueError("Emulate connection close")) resp = yield from redis.echo('ECHO') self.assertEqual(resp, b'ECHO') self.assertNotEqual(conn_id, id(redis._conn._conn))
def test_recon(server, loop): redis = yield from create_reconnecting_redis( server.tcp_address, db=1, loop=loop) assert repr(redis) == '<Redis <AutoConnector None>>' resp = yield from redis.echo('ECHO') assert resp == b'ECHO' assert repr(redis) == '<Redis <AutoConnector <RedisConnection [db:1]>>>' conn_id = id(redis._conn._conn) redis._conn._conn._do_close(ValueError("Emulate connection close")) resp = yield from redis.echo('ECHO') assert resp == b'ECHO' assert conn_id != id(redis._conn._conn) # FIXME: bad interface conn = yield from redis.connection.get_atomic_connection() conn.close() yield from conn.wait_closed()
def test_recon(self): redis = yield from create_reconnecting_redis( ('localhost', self.redis_port), db=1, loop=self.loop) self.assertEqual(repr(redis), '<Redis <AutoConnector None>>') resp = yield from redis.echo('ECHO') self.assertEqual(resp, b'ECHO') self.assertEqual(repr(redis), '<Redis <AutoConnector <RedisConnection [db:1]>>>') conn_id = id(redis._conn._conn) redis._conn._conn._do_close(ValueError("Emulate connection close")) resp = yield from redis.echo('ECHO') self.assertEqual(resp, b'ECHO') self.assertNotEqual(conn_id, id(redis._conn._conn)) # FIXME: bad interface conn = yield from redis.connection.get_atomic_connection() conn.close() yield from conn.wait_closed()
def test_recon(server, loop): redis = yield from create_reconnecting_redis(server.tcp_address, db=1, loop=loop) assert repr(redis) == '<Redis <AutoConnector None>>' resp = yield from redis.echo('ECHO') assert resp == b'ECHO' assert repr(redis) == '<Redis <AutoConnector <RedisConnection [db:1]>>>' conn_id = id(redis._conn._conn) redis._conn._conn._do_close(ValueError("Emulate connection close")) resp = yield from redis.echo('ECHO') assert resp == b'ECHO' assert conn_id != id(redis._conn._conn) # FIXME: bad interface conn = yield from redis.connection.get_atomic_connection() conn.close() yield from conn.wait_closed()