From d5e6ca2f148c5ed35db76dbb18395b83ccbe7aa8 Mon Sep 17 00:00:00 2001 From: stdrickforce Date: Fri, 6 Dec 2024 16:25:08 +0800 Subject: [PATCH] remove initialized tcs --- .../Auth/MicrosoftEntra/MicrosoftEntraAccessKey.cs | 5 ----- .../Auth/MicrosoftEntraAccessKeyTests.cs | 11 ----------- 2 files changed, 16 deletions(-) diff --git a/src/Microsoft.Azure.SignalR.Common/Auth/MicrosoftEntra/MicrosoftEntraAccessKey.cs b/src/Microsoft.Azure.SignalR.Common/Auth/MicrosoftEntra/MicrosoftEntraAccessKey.cs index 74850c2e1..7f77fc9e2 100644 --- a/src/Microsoft.Azure.SignalR.Common/Auth/MicrosoftEntra/MicrosoftEntraAccessKey.cs +++ b/src/Microsoft.Azure.SignalR.Common/Auth/MicrosoftEntra/MicrosoftEntraAccessKey.cs @@ -40,8 +40,6 @@ internal class MicrosoftEntraAccessKey : IAccessKey private static readonly TimeSpan AccessKeyExpireTime = TimeSpan.FromMinutes(120); - private readonly TaskCompletionSource _initializedTcs = new(TaskCreationOptions.RunContinuationsAsynchronously); - private readonly IHttpClientFactory _httpClientFactory; private volatile bool _isAuthorized = false; @@ -52,8 +50,6 @@ internal class MicrosoftEntraAccessKey : IAccessKey private volatile byte[]? _keyBytes; - public bool Initialized => _initializedTcs.Task.IsCompleted; - public bool NeedRefresh => DateTime.UtcNow - _updateAt > (Available ? GetAccessKeyInterval : GetAccessKeyIntervalUnavailable); public bool Available @@ -68,7 +64,6 @@ private set } _updateAt = DateTime.UtcNow; _isAuthorized = value; - _initializedTcs.TrySetResult(null); } } diff --git a/test/Microsoft.Azure.SignalR.Common.Tests/Auth/MicrosoftEntraAccessKeyTests.cs b/test/Microsoft.Azure.SignalR.Common.Tests/Auth/MicrosoftEntraAccessKeyTests.cs index d9f61049c..f833db860 100644 --- a/test/Microsoft.Azure.SignalR.Common.Tests/Auth/MicrosoftEntraAccessKeyTests.cs +++ b/test/Microsoft.Azure.SignalR.Common.Tests/Auth/MicrosoftEntraAccessKeyTests.cs @@ -170,12 +170,8 @@ public async Task TestLazyLoadAccessKey() }); var key = new MicrosoftEntraAccessKey(DefaultEndpoint, credential, httpClientFactory: httpClientFactory); - Assert.False(key.Initialized); - var token = await key.GenerateAccessTokenAsync("https://localhost", [], TimeSpan.FromMinutes(1), AccessTokenAlgorithm.HS256); Assert.NotNull(token); - - Assert.True(key.Initialized); } [Fact] @@ -186,16 +182,12 @@ public async Task TestLazyLoadAccessKeyFailed() GetAccessKeyRetryInterval = TimeSpan.FromSeconds(1), }; - Assert.False(key.Initialized); - var task1 = key.GenerateAccessTokenAsync(DefaultAudience, [], TimeSpan.FromMinutes(1), AccessTokenAlgorithm.HS256); var task2 = key.UpdateAccessKeyAsync(); Assert.False(task2.IsCompleted); await Assert.ThrowsAsync(async () => await task1); Assert.False(await task2); - - Assert.True(key.Initialized); } [Fact] @@ -213,7 +205,6 @@ public async Task TestRefreshAccessKey() var credential = new TestTokenCredential(TokenType.MicrosoftEntra); var key = new MicrosoftEntraAccessKey(DefaultEndpoint, credential, httpClientFactory: httpClientFactory); - Assert.False(key.Initialized); Assert.False(key.Available); Assert.True(key.NeedRefresh); @@ -221,7 +212,6 @@ public async Task TestRefreshAccessKey() Assert.True(TokenUtilities.TryParseIssuer(token, out var issuer)); Assert.Equal(Constants.AsrsTokenIssuer, issuer); - Assert.True(key.Initialized); Assert.True(key.Available); Assert.False(key.NeedRefresh); @@ -259,7 +249,6 @@ public async Task TestRefreshAccessKeyUnauthorized() { GetAccessKeyRetryInterval = TimeSpan.FromSeconds(1) }; - Assert.False(key.Initialized); Assert.False(key.Available); Assert.True(key.NeedRefresh);