From 30381423333c54e1df98d7721dd72697fc5406dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= <2493377+askpt@users.noreply.github.com> Date: Mon, 11 Nov 2024 23:16:41 +0000 Subject: [PATCH] fix: Fix unit test clean context (#313) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## This PR - It fixes an issue where the context sometimes needs to be cleared correctly. - It should eliminate any further race conditions in the unit tests. ### Notes Following an investigation on xUnit shared contexts, I found we should use `IDisposable` to clear data between tests. See https://xunit.net/docs/shared-context for reference. --------- Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com> --- .../ClearOpenFeatureInstanceFixture.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs b/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs index 5f31c71a..5a620214 100644 --- a/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs +++ b/test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs @@ -1,13 +1,14 @@ -namespace OpenFeature.Tests +using System; + +namespace OpenFeature.Tests; + +public class ClearOpenFeatureInstanceFixture : IDisposable { - public class ClearOpenFeatureInstanceFixture + // Make sure the singleton is cleared between tests + public void Dispose() { - // Make sure the singleton is cleared between tests - public ClearOpenFeatureInstanceFixture() - { - Api.Instance.SetContext(null); - Api.Instance.ClearHooks(); - Api.Instance.SetProviderAsync(new NoOpFeatureProvider()).Wait(); - } + Api.Instance.SetContext(null); + Api.Instance.ClearHooks(); + Api.Instance.SetProviderAsync(new NoOpFeatureProvider()).Wait(); } }