Skip to content

Commit 411beba

Browse files
committed
fix: Fix unit test clean context (#313)
<!-- Please use this template for your pull request. --> <!-- Please use the sections that you need and delete other sections --> ## This PR <!-- add the description of the PR here --> - 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 <!-- any additional notes for this PR --> 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 <[email protected]>
1 parent 43e3012 commit 411beba

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
namespace OpenFeature.Tests
1+
using System;
2+
3+
namespace OpenFeature.Tests;
4+
5+
public class ClearOpenFeatureInstanceFixture : IDisposable
26
{
3-
public class ClearOpenFeatureInstanceFixture
7+
// Make sure the singleton is cleared between tests
8+
public void Dispose()
49
{
5-
// Make sure the singleton is cleared between tests
6-
public ClearOpenFeatureInstanceFixture()
7-
{
8-
Api.Instance.SetContext(null);
9-
Api.Instance.ClearHooks();
10-
Api.Instance.SetProviderAsync(new NoOpFeatureProvider()).Wait();
11-
}
10+
Api.Instance.SetContext(null);
11+
Api.Instance.ClearHooks();
12+
Api.Instance.SetProviderAsync(new NoOpFeatureProvider()).Wait();
1213
}
1314
}

0 commit comments

Comments
 (0)