Skip to content

Commit 20f7784

Browse files
committed
Merge branch 'main' into renovate/major-xunit-dotnet-monorepo
# Conflicts: # test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs
2 parents 34a7359 + e14ab39 commit 20f7784

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

.github/workflows/code-coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Run Test
3737
run: dotnet test --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
3838

39-
- uses: codecov/codecov-action@v4.6.0
39+
- uses: codecov/codecov-action@v5.1.2
4040
with:
4141
name: Code Coverage for ${{ matrix.os }}
4242
fail_ci_if_error: true

src/OpenFeature/Api.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public sealed class Api : IEventBus
2929
/// <summary>
3030
/// Singleton instance of Api
3131
/// </summary>
32-
public static Api Instance { get; } = new Api();
32+
public static Api Instance { get; private set; } = new Api();
3333

3434
// Explicit static constructor to tell C# compiler
3535
// not to mark type as beforeFieldInit
@@ -300,5 +300,13 @@ private async Task AfterError(FeatureProvider provider, Exception? ex)
300300

301301
await this._eventExecutor.EventChannel.Writer.WriteAsync(new Event { Provider = provider, EventPayload = eventPayload }).ConfigureAwait(false);
302302
}
303+
304+
/// <summary>
305+
/// This method should only be using for testing purposes. It will reset the singleton instance of the API.
306+
/// </summary>
307+
internal static void ResetApi()
308+
{
309+
Instance = new Api();
310+
}
303311
}
304312
}
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
using System;
1+
using System.Threading.Tasks;
2+
using Xunit;
23
using System.Threading;
34
using Xunit;
45

56
namespace OpenFeature.Tests;
67

7-
public class ClearOpenFeatureInstanceFixture : IDisposable
8+
public class ClearOpenFeatureInstanceFixture : IAsyncLifetime
89
{
910
protected readonly CancellationToken TestCancellationToken;
1011

@@ -13,11 +14,16 @@ protected ClearOpenFeatureInstanceFixture()
1314
this.TestCancellationToken = TestContext.Current.CancellationToken;
1415
}
1516

17+
public Task InitializeAsync()
18+
{
19+
Api.ResetApi();
20+
21+
return Task.CompletedTask;
22+
}
23+
1624
// Make sure the singleton is cleared between tests
17-
public void Dispose()
25+
public async Task DisposeAsync()
1826
{
19-
Api.Instance.SetContext(null);
20-
Api.Instance.ClearHooks();
21-
Api.Instance.SetProviderAsync(new NoOpFeatureProvider()).Wait();
27+
await Api.Instance.ShutdownAsync().ConfigureAwait(false);
2228
}
2329
}

0 commit comments

Comments
 (0)