Skip to content

Commit

Permalink
Work around npgsql/efcore.pg#2891
Browse files Browse the repository at this point in the history
  • Loading branch information
eerhardt committed Oct 10, 2023
1 parent 69f1ed8 commit 807c00c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/Aspire.Components.Common.Tests/ConformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ private void SkipIfJsonSchemaPathNotSet()
[InlineData(false)]
public void ConnectionInformationIsDelayValidated(bool useKey)
{
SetupConnectionInformationIsDelayValidated();

var builder = Host.CreateEmptyApplicationBuilder(null);

string? key = useKey ? "key" : null;
Expand All @@ -387,6 +389,8 @@ private static string GetRepoRoot()
return directory!;
}

protected virtual void SetupConnectionInformationIsDelayValidated() { }

// This method can have side effects (setting AppContext switch, enabling activity source by name).
// That is why it needs to be executed in a standalone process.
// We use RemoteExecutor for that, but it does not support abstract classes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections;
using Aspire.Components.Common.Tests;
using Aspire.Components.ConformanceTests;
using Microsoft.AspNetCore.Diagnostics;
Expand Down Expand Up @@ -108,6 +109,18 @@ protected override void TriggerActivity(TestDbContext service)
}
}

// workaround https://github.com/npgsql/efcore.pg/issues/2891 by clearing the cache so the test is fresh
protected override void SetupConnectionInformationIsDelayValidated()
{
#pragma warning disable EF1001 // Internal EF Core API usage.
var cache = (IDictionary)typeof(ServiceProviderCache)
.GetField("_configurations", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)!
.GetValue(ServiceProviderCache.Instance)!;
#pragma warning restore EF1001 // Internal EF Core API usage.

cache.Clear();
}

[Theory]
[InlineData(true)]
[InlineData(false)]
Expand Down

0 comments on commit 807c00c

Please sign in to comment.