Skip to content
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

Fixed flaky tests #3122

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions tests/Microsoft.Identity.Web.Test/L1L2CacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace Microsoft.Identity.Web.Test
{
[CollectionDefinition(nameof(L1L2CacheTests), DisableParallelization = true)]
public class L1L2CacheTests
{
private const string DefaultCacheKey = "default-key";
Expand Down Expand Up @@ -51,12 +52,12 @@ public async Task WriteCache_WritesInL1L2_TestAsync(bool enableAsyncL2Write)
Assert.Empty(L2Cache._dict);

// Act
TestDistributedCache.ResetEvent.Reset();
L2Cache.ResetEvent.Reset();
await _testCacheAdapter.TestWriteCacheBytesAsync(DefaultCacheKey, cache);

// Assert
Assert.Equal(1, _testCacheAdapter._memoryCache.Count);
TestDistributedCache.ResetEvent.Wait();
L2Cache.ResetEvent.Wait();
Assert.Single(L2Cache._dict);
}

Expand Down Expand Up @@ -168,12 +169,12 @@ private async Task CreateL1L2TestWithSerializerHintsAsync(
cacheSerializerHints.SuggestedCacheExpiry = dateTimeOffset;

// Act
TestDistributedCache.ResetEvent.Reset();
L2Cache.ResetEvent.Reset();
await _testCacheAdapter.TestWriteCacheBytesAsync(DefaultCacheKey, cache, cacheSerializerHints);

// Assert
Assert.Equal(memoryCacheExpectedCount, _testCacheAdapter._memoryCache.Count);
TestDistributedCache.ResetEvent.Wait();
L2Cache.ResetEvent.Wait();
Assert.Single(L2Cache._dict);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.Identity.Web.Test
public class TestDistributedCache : IDistributedCache
{
internal readonly ConcurrentDictionary<string, Entry> _dict = new ConcurrentDictionary<string, Entry>();
internal static ManualResetEventSlim ResetEvent { get; set; } = new ManualResetEventSlim(initialState: false);
internal ManualResetEventSlim ResetEvent { get; set; } = new ManualResetEventSlim(initialState: false);

public byte[]? Get(string key)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class TestTokenAcquisitionHost
[Fact]
public void TestTokenAcquisitionHostNotAspNetCore()
{
TokenAcquirerFactory.ResetDefaultInstance();

// When not adding Services.AddAuthentication, the host should be
TokenAcquirerFactory tokenAcquirerFactory = TokenAcquirerFactory.GetDefaultInstance();
var host = tokenAcquirerFactory.Services.First(s => s.ServiceType.FullName == "Microsoft.Identity.Web.ITokenAcquisitionHost");
Expand Down
Loading