@@ -137,7 +137,7 @@ def test_live_connection_cram_failure(
137137 test_api_key : str ,
138138) -> None :
139139 """
140- Test that a failed auth message due to an incorrect CRAM raies a
140+ Test that a failed auth message due to an incorrect CRAM raises a
141141 BentoError.
142142 """
143143 # Dork up the API key in the mock client to fail CRAM
@@ -1029,3 +1029,38 @@ async def test_live_stream_with_reconnect(
10291029 records = list (data )
10301030 for record in records :
10311031 assert isinstance (record , schema .get_record_type ())
1032+
1033+ def test_live_connection_reconnect_cram_failure (
1034+ mock_live_server : MockLiveServer ,
1035+ monkeypatch : pytest .MonkeyPatch ,
1036+ test_api_key : str ,
1037+ ) -> None :
1038+ """
1039+ Test that a failed connection can reconnect.
1040+ """
1041+ # Dork up the API key in the mock client to fail CRAM
1042+ bucket_id = test_api_key [- BUCKET_ID_LENGTH :]
1043+ invalid_key = "db-invalidkey00000000000000FFFFF"
1044+ monkeypatch .setitem (mock_live_server ._user_api_keys , bucket_id , invalid_key )
1045+
1046+ live_client = client .Live (
1047+ key = test_api_key ,
1048+ gateway = mock_live_server .host ,
1049+ port = mock_live_server .port ,
1050+ )
1051+
1052+ with pytest .raises (BentoError ) as exc :
1053+ live_client .subscribe (
1054+ dataset = Dataset .GLBX_MDP3 ,
1055+ schema = Schema .MBO ,
1056+ )
1057+
1058+ # Ensure this was an authentication error
1059+ exc .match (r"User authentication failed:" )
1060+
1061+ # Fix the key in the mock live server to connect
1062+ monkeypatch .setitem (mock_live_server ._user_api_keys , bucket_id , test_api_key )
1063+ live_client .subscribe (
1064+ dataset = Dataset .GLBX_MDP3 ,
1065+ schema = Schema .MBO ,
1066+ )
0 commit comments