MCPcopy
hub / github.com/aio-libs/aiohttp / test_connect_queued_operation_tracing

Function test_connect_queued_operation_tracing

tests/test_connector.py:3172–3215  ·  view source on GitHub ↗
(loop, key)

Source from the content-addressed store, hash-verified

3170
3171
3172async def test_connect_queued_operation_tracing(loop, key) -> None:
3173 session = mock.Mock()
3174 trace_config_ctx = mock.Mock()
3175 on_connection_queued_start = mock.AsyncMock()
3176 on_connection_queued_end = mock.AsyncMock()
3177
3178 trace_config = aiohttp.TraceConfig(
3179 trace_config_ctx_factory=mock.Mock(return_value=trace_config_ctx)
3180 )
3181 trace_config.on_connection_queued_start.append(on_connection_queued_start)
3182 trace_config.on_connection_queued_end.append(on_connection_queued_end)
3183 trace_config.freeze()
3184 traces = [Trace(session, trace_config, trace_config.trace_config_ctx())]
3185
3186 proto = create_mocked_conn()
3187 proto.is_connected.return_value = True
3188
3189 req = ClientRequest(
3190 "GET", URL("http://localhost1:80"), loop=loop, response_class=mock.Mock()
3191 )
3192
3193 conn = aiohttp.BaseConnector(loop=loop, limit=1)
3194 conn._conns[key] = deque([(proto, loop.time())])
3195 conn._create_connection = mock.Mock()
3196 conn._create_connection.return_value = loop.create_future()
3197 conn._create_connection.return_value.set_result(proto)
3198
3199 connection1 = await conn.connect(req, traces, ClientTimeout())
3200
3201 async def f():
3202 connection2 = await conn.connect(req, traces, ClientTimeout())
3203 on_connection_queued_start.assert_called_with(
3204 session, trace_config_ctx, aiohttp.TraceConnectionQueuedStartParams()
3205 )
3206 on_connection_queued_end.assert_called_with(
3207 session, trace_config_ctx, aiohttp.TraceConnectionQueuedEndParams()
3208 )
3209 connection2.release()
3210
3211 task = asyncio.ensure_future(f(), loop=loop)
3212 await asyncio.sleep(0.01)
3213 connection1.release()
3214 await task
3215 await conn.close()
3216
3217
3218async def test_connect_reuseconn_tracing(loop, key) -> None:

Callers

nothing calls this directly

Calls 11

freezeMethod · 0.95
trace_config_ctxMethod · 0.95
connectMethod · 0.95
closeMethod · 0.95
TraceClass · 0.90
ClientRequestClass · 0.90
ClientTimeoutClass · 0.90
appendMethod · 0.80
create_mocked_connFunction · 0.70
fFunction · 0.70
releaseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…