Skip to content

[Identity] Adjust flaky tests #41634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2025
Merged

Conversation

pvaneck
Copy link
Member

@pvaneck pvaneck commented Jun 17, 2025

In some pipeline runs, over a second may elapse between when a credential is created and when a token request is made. This causes flakiness in the test_cached_token_outside_refresh_window tests. This change increases the time window.

Example failure message:

================================== FAILURES ===================================
__________ test_cached_token_outside_refresh_window[get_token_info] ___________

get_token_method = 'get_token_info'

    @pytest.mark.parametrize("get_token_method", GET_TOKEN_METHODS)
    def test_cached_token_outside_refresh_window(get_token_method):
        """A credential shouldn't request a new token when it has a cached one with sufficient validity remaining"""
    
        credential = MockCredential(
            cached_token=AccessTokenInfo(CACHED_TOKEN, int(time.time() + DEFAULT_REFRESH_OFFSET + 1))
        )
        token = getattr(credential, get_token_method)(SCOPE)
    
        credential.acquire_token_silently.assert_called_once_with(SCOPE, claims=None, enable_cae=False, tenant_id=None)
>       assert credential.request_token.call_count == 0
E       AssertionError: assert 1 == 0
E        +  where 1 = <Mock id='2862391543040'>.call_count
E        +    where <Mock id='2862391543040'> = <test_get_token_mixin.MockCredential object at 0x0000029A73D4DFA0>.request_token

In some pipeline runs, over a second may elapse between when a
credential is created and when a token request is made. This causes
flakiness in the `test_cached_token_outside_refresh_window` tests. This
change increases the time window.

Signed-off-by: Paul Van Eck <[email protected]>
@pvaneck pvaneck marked this pull request as ready for review June 18, 2025 22:24
@Copilot Copilot AI review requested due to automatic review settings June 18, 2025 22:24
@pvaneck pvaneck requested review from xiangyan99 and a team as code owners June 18, 2025 22:24
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses intermittent failures in the cached-token tests by extending the validity buffer before a refresh is triggered.

  • Increases the time buffer in both async and sync tests from DEFAULT_REFRESH_OFFSET + 1 to DEFAULT_REFRESH_OFFSET + 10.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
sdk/identity/azure-identity/tests/test_get_token_mixin_async.py Extended cached token offset from + 1 to + 10 to reduce flakiness
sdk/identity/azure-identity/tests/test_get_token_mixin.py Same change for the synchronous test

@pvaneck pvaneck merged commit 15b975b into Azure:main Jun 18, 2025
29 checks passed
@pvaneck pvaneck deleted the identity-test-adjustment branch June 18, 2025 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

2 participants