def test_transport_registry_get_rpc_transports(redis_default_config): registry = TransportRegistry().load_config(redis_default_config) # Note how we set a config value below. We do this because # we need this transport to appear different from the default # transport for the purposes of this test. Also note that these # are not actual transports, but transport pools which wrap transports. # We are therefore actually comparing transport pools. Transport # pools are considered equal if they have the same transport class # and config. It is for this reason we modify the config below. registry.set_rpc_transport("redis1", RedisRpcTransport, RedisRpcTransport.Config(rpc_timeout=99), Config.default()) registry.set_rpc_transport("redis2", RedisRpcTransport, RedisRpcTransport.Config(rpc_timeout=99), Config.default()) registry.set_rpc_transport("debug1", DebugRpcTransport, DebugRpcTransport.Config(), Config.default()) registry.set_rpc_transport("debug2", DebugRpcTransport, DebugRpcTransport.Config(), Config.default()) transport_pools = registry.get_rpc_transports( ["default", "foo", "bar", "redis1", "redis2", "debug1", "debug2"]) default_transport = registry.get_rpc_transport("default") redis_transport = registry.get_rpc_transport("redis1") debug_transport = registry.get_rpc_transport("debug1") assert set(transport_pools[default_transport]) == {"default", "foo", "bar"} assert set(transport_pools[debug_transport]) == {"debug1", "debug2"} assert set(transport_pools[redis_transport]) == {"redis1", "redis2"}
def dummy_bus(loop, redis_server_url): # fmt: off dummy_bus = lightbus.creation.create( config=RootConfig( apis={ 'default': ApiConfig( rpc_transport=RpcTransportSelector( debug=DebugRpcTransport.Config()), result_transport=ResultTransportSelector( debug=DebugResultTransport.Config()), event_transport=EventTransportSelector( debug=DebugEventTransport.Config()), ) }, bus=BusConfig( schema=SchemaConfig(transport=SchemaTransportSelector( redis=RedisSchemaTransport.Config( url=redis_server_url)), ))), plugins=[], ) # fmt: on yield dummy_bus try: dummy_bus.client.close() except BusAlreadyClosed: pass
def test_transport_registry_get_rpc_transports(redis_default_config): registry = TransportRegistry().load_config(redis_default_config) debug_transport = DebugRpcTransport() redis_transport = RedisRpcTransport() registry.set_rpc_transport("redis1", redis_transport) registry.set_rpc_transport("redis2", redis_transport) registry.set_rpc_transport("debug1", debug_transport) registry.set_rpc_transport("debug2", debug_transport) transports = registry.get_rpc_transports( ["default", "foo", "bar", "redis1", "redis2", "debug1", "debug2"]) default_redis_transport = registry.get_rpc_transport("default") transports = dict(transports) assert set( transports[default_redis_transport]) == {"default", "foo", "bar"} assert set(transports[debug_transport]) == {"debug1", "debug2"} assert set(transports[redis_transport]) == {"redis1", "redis2"}