Skip to content

Commit

Permalink
Merge branch 'main' into askpt/243-feature-implement-transaction-context
Browse files Browse the repository at this point in the history
  • Loading branch information
askpt authored Dec 19, 2024
2 parents 9f75a44 + e14ab39 commit e473ccc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
10 changes: 9 additions & 1 deletion src/OpenFeature/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public sealed class Api : IEventBus
/// <summary>
/// Singleton instance of Api
/// </summary>
public static Api Instance { get; } = new Api();
public static Api Instance { get; private set; } = new Api();

// Explicit static constructor to tell C# compiler
// not to mark type as beforeFieldInit
Expand Down Expand Up @@ -355,5 +355,13 @@ private async Task AfterError(FeatureProvider provider, Exception? ex)

await this._eventExecutor.EventChannel.Writer.WriteAsync(new Event { Provider = provider, EventPayload = eventPayload }).ConfigureAwait(false);
}

/// <summary>
/// This method should only be using for testing purposes. It will reset the singleton instance of the API.
/// </summary>
internal static void ResetApi()
{
Instance = new Api();
}
}
}
18 changes: 12 additions & 6 deletions test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
using System;
using System.Threading.Tasks;
using Xunit;

namespace OpenFeature.Tests;

public class ClearOpenFeatureInstanceFixture : IDisposable
public class ClearOpenFeatureInstanceFixture : IAsyncLifetime
{
public Task InitializeAsync()
{
Api.ResetApi();

return Task.CompletedTask;
}

// Make sure the singleton is cleared between tests
public void Dispose()
public async Task DisposeAsync()
{
Api.Instance.SetContext(null);
Api.Instance.ClearHooks();
Api.Instance.SetProviderAsync(new NoOpFeatureProvider()).Wait();
await Api.Instance.ShutdownAsync().ConfigureAwait(false);
}
}

0 comments on commit e473ccc

Please sign in to comment.