Skip to content

Commit

Permalink
fix: Fix unit test clean context (#313)
Browse files Browse the repository at this point in the history
<!-- 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 <2493377+askpt@users.noreply.github.com>
  • Loading branch information
askpt authored Nov 11, 2024
1 parent 9b693f7 commit 3038142
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions test/OpenFeature.Tests/ClearOpenFeatureInstanceFixture.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 3038142

Please sign in to comment.