-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add public API method to disable ADAL cache. Add if checks around ADAL cache operations. * Update if AdalCacheEnabled checks. * Add benchmark for SaveToken method. * Renaming and comment updates. Add app option. * Add GetRefreshToken test. * Fix FindToken test. Move helper methods into LegacyTokenCacheHelper for reusability. * Cleanup. * Add RemoveUser and GetAllUsers benchmarks. * Add unit tests. * Update XML comment. * Rename AdalCache to LegacyCache
- Loading branch information
Showing
14 changed files
with
419 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
tests/Microsoft.Identity.Client.Performance/LegacyCacheOperationsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Configs; | ||
using BenchmarkDotNet.Engines; | ||
using Microsoft.Identity.Client; | ||
using Microsoft.Identity.Client.Instance; | ||
using Microsoft.Identity.Client.Instance.Discovery; | ||
using Microsoft.Identity.Client.Internal; | ||
using Microsoft.Identity.Client.Internal.Requests; | ||
using Microsoft.Identity.Client.OAuth2; | ||
using Microsoft.Identity.Test.Common; | ||
using Microsoft.Identity.Test.Common.Core.Mocks; | ||
using Microsoft.Identity.Test.Unit; | ||
|
||
namespace Microsoft.Identity.Test.Performance | ||
{ | ||
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByMethod)] | ||
public class LegacyCacheOperationsTests | ||
{ | ||
private ITokenCacheInternal _cache; | ||
private MsalTokenResponse _response; | ||
private AuthenticationRequestParameters _requestParams; | ||
private RequestContext _requestContext; | ||
private readonly Consumer _consumer = new Consumer(); | ||
|
||
[Params(1, 100, 1000)] | ||
public int TokenCacheSize { get; set; } | ||
|
||
[ParamsAllValues] | ||
public bool EnableLegacyCache { get; set; } | ||
|
||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
var serviceBundle = TestCommon.CreateServiceBundleWithCustomHttpManager(null, isLegacyCacheEnabled: EnableLegacyCache); | ||
|
||
_requestContext = new RequestContext(serviceBundle, Guid.NewGuid()); | ||
_cache = new TokenCache(serviceBundle, false); | ||
_response = TestConstants.CreateMsalTokenResponse(); | ||
|
||
_requestParams = TestCommon.CreateAuthenticationRequestParameters(serviceBundle); | ||
_requestParams.TenantUpdatedCanonicalAuthority = Authority.CreateAuthorityWithTenant( | ||
_requestParams.AuthorityInfo, | ||
TestConstants.Utid); | ||
_requestParams.Account = new Account(TestConstants.s_userIdentifier, $"1{TestConstants.DisplayableId}", TestConstants.ProductionPrefNetworkEnvironment); | ||
|
||
AddHostToInstanceCache(serviceBundle, TestConstants.ProductionPrefCacheEnvironment); | ||
|
||
LegacyTokenCacheHelper.PopulateLegacyCache(serviceBundle.DefaultLogger, _cache.LegacyPersistence, TokenCacheSize); | ||
TokenCacheHelper.AddRefreshTokensToCache(_cache.Accessor, TokenCacheSize); | ||
} | ||
|
||
[Benchmark(Description = "SaveToken")] | ||
public async Task<string> SaveTokenResponseTestAsync() | ||
{ | ||
var result = await _cache.SaveTokenResponseAsync(_requestParams, _response).ConfigureAwait(true); | ||
return result.Item1.ClientId; | ||
} | ||
|
||
[Benchmark(Description = "FindToken")] | ||
public async Task<string> FindRefreshTokenTestAsync() | ||
{ | ||
var result = await _cache.FindRefreshTokenAsync(_requestParams).ConfigureAwait(true); | ||
return result?.ClientId; | ||
} | ||
|
||
[Benchmark(Description = "GetAllUsers")] | ||
public async Task GetAllAdalUsersTestAsync() | ||
{ | ||
var result = await _cache.GetAccountsAsync(_requestParams).ConfigureAwait(true); | ||
result.Consume(_consumer); | ||
} | ||
|
||
[Benchmark(Description = "RemoveUser")] | ||
public async Task RemoveAdalUserTestAsync() | ||
{ | ||
await _cache.RemoveAccountAsync(_requestParams.Account, _requestContext).ConfigureAwait(true); | ||
} | ||
|
||
private void AddHostToInstanceCache(IServiceBundle serviceBundle, string host) | ||
{ | ||
(serviceBundle.InstanceDiscoveryManager as InstanceDiscoveryManager) | ||
.AddTestValueToStaticProvider( | ||
host, | ||
new InstanceDiscoveryMetadataEntry | ||
{ | ||
PreferredNetwork = host, | ||
PreferredCache = host, | ||
Aliases = new string[] | ||
{ | ||
host | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.