From 121f39acc9d40e1d69cb0bcc213a2556cc7ade70 Mon Sep 17 00:00:00 2001 From: Tuan Pham Date: Fri, 30 Oct 2026 15:15:04 +0800 Subject: [PATCH] test(sap): check the token refreshes inside the expiry buffer --- tests/unit/llms/sap/test_sap_fetch_creds.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/unit/llms/sap/test_sap_fetch_creds.py b/tests/unit/llms/sap/test_sap_fetch_creds.py index cc52c8991f3..bc4507082a5 100644 --- a/tests/unit/llms/sap/test_sap_fetch_creds.py +++ b/tests/unit/llms/sap/test_sap_fetch_creds.py @@ -160,3 +160,17 @@ def test_credentials_without_authentication_mode(monkeypatch): # validate_credentials should raise because no authentication mode is provided with pytest.raises(ValueError, match="SAP AI Core credentials are incomplete"): sap_credentials.validate_credentials(**creds) + + +@pytest.mark.parametrize( + "expires_in, expected_token_requests", + [(43200, 1), (3000, 3)], + ids=["reused-while-valid", "refreshed-inside-60-minute-buffer"], +) +def test_token_is_shared_across_token_creators_until_refresh_buffer(aicore, expires_in, expected_token_requests): + aicore.token.respond(json={"access_token": "mock-token", "expires_in": expires_in}) + + tokens = tuple(sap_credentials.get_token_creator()[0]() for _ in range(3)) + + assert tokens == ("Bearer mock-token",) * 3 + assert aicore.token.call_count == expected_token_requests