11import time
2- from datetime import timedelta
2+ from datetime import datetime , timedelta
33
44from rabbitmq_amqp_python_client import (
55 ConnectionClosed ,
1111)
1212
1313from .http_requests import delete_all_connections
14+ from .utils import token
1415
1516
1617def on_disconnected ():
@@ -44,7 +45,7 @@ def test_connection_ssl(ssl_context) -> None:
4445 environment .close ()
4546
4647
47- def test_connection_auth (environment_auth : Environment ) -> None :
48+ def test_connection_oauth (environment_auth : Environment ) -> None :
4849
4950 connection = environment_auth .connection ()
5051 connection .dial ()
@@ -54,7 +55,7 @@ def test_connection_auth(environment_auth: Environment) -> None:
5455 connection .close ()
5556
5657
57- def test_connection_auth_with_timeout (environment_auth : Environment ) -> None :
58+ def test_connection_oauth_with_timeout (environment_auth : Environment ) -> None :
5859
5960 connection = environment_auth .connection ()
6061 connection .dial ()
@@ -65,10 +66,32 @@ def test_connection_auth_with_timeout(environment_auth: Environment) -> None:
6566 try :
6667 management = connection .management ()
6768 management .declare_queue (QuorumQueueSpecification (name = "test-queue" ))
69+ management .close ()
6870 except Exception :
6971 raised = True
7072
7173 assert raised is True
74+
75+ connection .close ()
76+
77+
78+ def test_connection_oauth_refresh_token (environment_auth : Environment ) -> None :
79+
80+ connection = environment_auth .connection ()
81+ connection .dial ()
82+ # let the token expire
83+ time .sleep (1 )
84+ raised = False
85+ # token expired, refresh
86+ connection .refresh_token (token (datetime .now () + timedelta (milliseconds = 5000 )))
87+ time .sleep (3 )
88+ try :
89+ management = connection .management ()
90+ management .declare_queue (QuorumQueueSpecification (name = "test-queue" ))
91+ except Exception :
92+ raised = True
93+
94+ assert raised is False
7295 connection .close ()
7396
7497
0 commit comments