Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def test_middleware_cleanup_app(tracer):
fut = asyncio.Future()
fut.set_result(None)
with patch.object(tracer, 'close', return_value=fut) as mocked_close:
app = web.Application()
az.setup(app, tracer)
app.freeze()
await app.cleanup()
assert mocked_close.call_count == 1
async def test_middleware_with_invalid_ip(tracer, version, address):
app = web.Application()
az.setup(app, tracer)
# Fake transport
transp = Mock()
transp.get_extra_info.return_value = (address, '0')
async def handler(request):
return web.Response(body=b'data')
req = make_mocked_request('GET', '/',
headers={'token': 'x'},
transport=transp, app=app)
middleware = middleware_maker()
with patch('aiozipkin.span.Span.remote_endpoint') as mocked_remote_ep:
await middleware(req, handler)
assert mocked_remote_ep.call_count == 0
def test_basic_setup(tracer):
app = web.Application()
az.setup(app, tracer)
fetched_tracer = az.get_tracer(app)
assert len(app.middlewares) == 1
assert tracer is fetched_tracer
async def make_app():
app = web.Application()
app.router.add_get('/api/v1/data', handler)
zipkin_address = 'http://127.0.0.1:9411/api/v2/spans'
endpoint = az.create_endpoint('service_b', ipv4=host, port=port)
tracer = await az.create(zipkin_address, endpoint, sample_rate=1.0)
az.setup(app, tracer)
trace_config = az.make_trace_config(tracer)
session = aiohttp.ClientSession(trace_configs=[trace_config])
app['session'] = session
async def close_session(app):
await app['session'].close()
app.on_cleanup.append(close_session)
return app
async def make_app(host, port):
app = web.Application()
app.router.add_get('/', index)
session = aiohttp.ClientSession()
app['session'] = session
zipkin_address = 'http://127.0.0.1:9411/api/v2/spans'
endpoint = az.create_endpoint('frontend', ipv4=host, port=port)
tracer = await az.create(zipkin_address, endpoint, sample_rate=1.0)
az.setup(app, tracer)
return app
async def make_app(host, port):
app = web.Application()
app.router.add_get('/', handle)
# here we aquire reference to route, so later we can command
# aiozipkin not to trace it
skip_route = app.router.add_get('/status', not_traced_handle)
endpoint = az.create_endpoint('aiohttp_server', ipv4=host, port=port)
zipkin_address = 'http://127.0.0.1:9411/api/v2/spans'
tracer = await az.create(zipkin_address, endpoint, sample_rate=1.0)
az.setup(app, tracer, skip_routes=[skip_route])
return app
async def make_app():
app = web.Application()
app.router.add_get('/api/v1/data', handler)
zipkin_address = 'http://127.0.0.1:9411/api/v2/spans'
endpoint = az.create_endpoint('service_d', ipv4=host, port=port)
tracer = await az.create(zipkin_address, endpoint, sample_rate=1.0)
az.setup(app, tracer)
return app
async def make_app(host, port):
app = web.Application()
app.router.add_post('/consume', handler)
aiojobs.aiohttp.setup(app)
zipkin_address = 'http://127.0.0.1:9411/api/v2/spans'
endpoint = az.create_endpoint('backend_broker', ipv4=host, port=port)
tracer = await az.create(zipkin_address, endpoint, sample_rate=1.0)
az.setup(app, tracer)
return app