Skip to content

Commit

Permalink
remove initialized tcs
Browse files Browse the repository at this point in the history
  • Loading branch information
terencefan committed Dec 6, 2024
1 parent df1675c commit d5e6ca2
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ internal class MicrosoftEntraAccessKey : IAccessKey

private static readonly TimeSpan AccessKeyExpireTime = TimeSpan.FromMinutes(120);

private readonly TaskCompletionSource<object?> _initializedTcs = new(TaskCreationOptions.RunContinuationsAsynchronously);

private readonly IHttpClientFactory _httpClientFactory;

private volatile bool _isAuthorized = false;
Expand All @@ -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
Expand All @@ -68,7 +64,6 @@ private set
}
_updateAt = DateTime.UtcNow;
_isAuthorized = value;
_initializedTcs.TrySetResult(null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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<AzureSignalRAccessTokenNotAuthorizedException>(async () => await task1);
Assert.False(await task2);

Assert.True(key.Initialized);
}

[Fact]
Expand All @@ -213,15 +205,13 @@ 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);

var token = await key.GenerateAccessTokenAsync(DefaultAudience, [], TimeSpan.FromMinutes(1), AccessTokenAlgorithm.HS256);
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);

Expand Down Expand Up @@ -259,7 +249,6 @@ public async Task TestRefreshAccessKeyUnauthorized()
{
GetAccessKeyRetryInterval = TimeSpan.FromSeconds(1)
};
Assert.False(key.Initialized);
Assert.False(key.Available);
Assert.True(key.NeedRefresh);

Expand Down

0 comments on commit d5e6ca2

Please sign in to comment.