@@ -87,8 +87,12 @@ async def do_request():
8787 await runnable (server )
8888 return netloc
8989
90- loop = asyncio .get_event_loop ()
91- return loop .run_until_complete (do_request ())
90+ loop = asyncio .new_event_loop ()
91+ asyncio .set_event_loop (loop )
92+ try :
93+ return loop .run_until_complete (do_request ())
94+ finally :
95+ loop .close ()
9296
9397
9498SCOPE = "opentelemetry.instrumentation.aiohttp_client"
@@ -487,9 +491,8 @@ async def do_request(url):
487491 async with session .get (url ):
488492 pass
489493
490- loop = asyncio .get_event_loop ()
491494 with self .assertRaises (aiohttp .ClientConnectorError ):
492- loop . run_until_complete (do_request (url ))
495+ asyncio . run (do_request (url ))
493496
494497 self ._assert_spans (
495498 [
@@ -710,8 +713,7 @@ async def do_request(url):
710713 async with session .request ("NONSTANDARD" , url ):
711714 pass
712715
713- loop = asyncio .get_event_loop ()
714- loop .run_until_complete (do_request (url ))
716+ asyncio .run (do_request (url ))
715717
716718 self ._assert_spans (
717719 [
@@ -752,8 +754,7 @@ async def do_request(url):
752754 async with session .request ("NONSTANDARD" , url ):
753755 pass
754756
755- loop = asyncio .get_event_loop ()
756- loop .run_until_complete (do_request (url ))
757+ asyncio .run (do_request (url ))
757758
758759 self ._assert_spans (
759760 [
@@ -797,8 +798,7 @@ async def do_request(url):
797798 async with session .get (url ):
798799 pass
799800
800- loop = asyncio .get_event_loop ()
801- loop .run_until_complete (do_request (url ))
801+ asyncio .run (do_request (url ))
802802
803803 self ._assert_spans (
804804 [
0 commit comments