From 5740120736141481279afa5f36719a2c22c1d740 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Silva?=
<2493377+askpt@users.noreply.github.com>
Date: Wed, 18 Dec 2024 15:19:41 +0000
Subject: [PATCH 1/3] Adding Async Lifetime method.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
---
.../ClearOpenFeatureInstanceFixture.cs | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs b/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs
index 5a620214..aeb62ee7 100644
--- a/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs
+++ b/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs
@@ -1,14 +1,21 @@
-using System;
+using System.Threading.Tasks;
+using Xunit;
namespace OpenFeature.Tests;
-public class ClearOpenFeatureInstanceFixture : IDisposable
+public class ClearOpenFeatureInstanceFixture : IAsyncLifetime
{
+ public Task InitializeAsync()
+ {
+ 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);
+ // Api.Instance.SetContext(null);
+ // Api.Instance.ClearHooks();
+ // Api.Instance.SetProviderAsync(new NoOpFeatureProvider()).Wait();
}
}
From 3b336e0fb90d4630eec2ed48627f7d1d76a1271f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Silva?=
<2493377+askpt@users.noreply.github.com>
Date: Wed, 18 Dec 2024 15:41:55 +0000
Subject: [PATCH 2/3] Removed comments.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
---
test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs | 3 ---
1 file changed, 3 deletions(-)
diff --git a/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs b/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs
index aeb62ee7..ae624e31 100644
--- a/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs
+++ b/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs
@@ -14,8 +14,5 @@ public Task InitializeAsync()
public async Task DisposeAsync()
{
await Api.Instance.ShutdownAsync().ConfigureAwait(false);
- // Api.Instance.SetContext(null);
- // Api.Instance.ClearHooks();
- // Api.Instance.SetProviderAsync(new NoOpFeatureProvider()).Wait();
}
}
From 50be0d21413b6052c50cd380ae2ca51695643c5c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Silva?=
<2493377+askpt@users.noreply.github.com>
Date: Wed, 18 Dec 2024 16:17:09 +0000
Subject: [PATCH 3/3] Adding a reset before the test initialisation.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
---
src/OpenFeature/Api.cs | 10 +++++++++-
.../ClearOpenFeatureInstanceFixture.cs | 2 ++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/OpenFeature/Api.cs b/src/OpenFeature/Api.cs
index fae9916b..bc0499dd 100644
--- a/src/OpenFeature/Api.cs
+++ b/src/OpenFeature/Api.cs
@@ -29,7 +29,7 @@ public sealed class Api : IEventBus
///
/// Singleton instance of Api
///
- 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
@@ -300,5 +300,13 @@ private async Task AfterError(FeatureProvider provider, Exception? ex)
await this._eventExecutor.EventChannel.Writer.WriteAsync(new Event { Provider = provider, EventPayload = eventPayload }).ConfigureAwait(false);
}
+
+ ///
+ /// This method should only be using for testing purposes. It will reset the singleton instance of the API.
+ ///
+ internal static void ResetApi()
+ {
+ Instance = new Api();
+ }
}
}
diff --git a/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs b/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs
index ae624e31..c3351801 100644
--- a/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs
+++ b/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs
@@ -7,6 +7,8 @@ public class ClearOpenFeatureInstanceFixture : IAsyncLifetime
{
public Task InitializeAsync()
{
+ Api.ResetApi();
+
return Task.CompletedTask;
}