1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ import asyncio
1516import socket
1617import ssl
17- from tempfile import TemporaryDirectory
1818from threading import Thread
1919from typing import Generator
2020
21+ from aiofiles .tempfile import TemporaryDirectory
2122from mocks import FakeAlloyDBClient
2223from mocks import FakeCredentials
2324from mocks import FakeInstance
@@ -42,7 +43,7 @@ def fake_client(fake_instance: FakeInstance) -> FakeAlloyDBClient:
4243 return FakeAlloyDBClient (fake_instance )
4344
4445
45- def start_proxy_server (instance : FakeInstance ) -> None :
46+ async def start_proxy_server (instance : FakeInstance ) -> None :
4647 """Run local proxy server capable of performing metadata exchange"""
4748 ip_address = "127.0.0.1"
4849 port = 5433
@@ -55,8 +56,8 @@ def start_proxy_server(instance: FakeInstance) -> None:
5556 # tmpdir and its contents are automatically deleted after the CA cert
5657 # and cert chain are loaded into the SSLcontext. The values
5758 # need to be written to files in order to be loaded by the SSLContext
58- with TemporaryDirectory () as tmpdir :
59- _ , cert_chain_filename , key_filename = _write_to_file (
59+ async with TemporaryDirectory () as tmpdir :
60+ _ , cert_chain_filename , key_filename = await _write_to_file (
6061 tmpdir , server , [server , root ], instance .server_key
6162 )
6263 context .load_cert_chain (cert_chain_filename , key_filename )
@@ -76,7 +77,15 @@ def start_proxy_server(instance: FakeInstance) -> None:
7677@pytest .fixture (scope = "session" )
7778def proxy_server (fake_instance : FakeInstance ) -> Generator :
7879 """Run local proxy server capable of performing metadata exchange"""
79- thread = Thread (target = start_proxy_server , args = (fake_instance ,), daemon = True )
80+ thread = Thread (
81+ target = asyncio .run ,
82+ args = (
83+ start_proxy_server (
84+ fake_instance ,
85+ ),
86+ ),
87+ daemon = True ,
88+ )
8089 thread .start ()
8190 yield thread
8291 thread .join ()
0 commit comments