Skip to content

Commit 161aa73

Browse files
Copilotjosecolella
andcommitted
Improve shutdown functionality to clear providers and reset state
Based on OpenFeature specification review, the shutdown method now: - Calls shutdown on all registered providers - Clears all providers from configuration - Resets SDK to initial state for proper cleanup Updated tests to verify providers are properly cleared after shutdown. Updated documentation to reflect complete shutdown behavior. Co-authored-by: josecolella <[email protected]>
1 parent 195978e commit 161aa73

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,13 @@ end
223223
OpenFeature::SDK.shutdown
224224
```
225225

226-
When you call `OpenFeature::SDK.shutdown`, it will automatically call the `shutdown` method on all registered providers that support it. If a provider doesn't have a `shutdown` method, it will be safely ignored.
226+
When you call `OpenFeature::SDK.shutdown`, it will:
227+
228+
1. Call the `shutdown` method on all registered providers that support it
229+
2. Clear all registered providers from the configuration
230+
3. Reset the SDK to its initial state
231+
232+
After shutdown, no providers will be available and the SDK will need to be reconfigured if you want to continue using it.
227233

228234
To implement shutdown in your custom provider:
229235

lib/open_feature/sdk/configuration.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ def set_provider(provider, domain: nil)
3737
end
3838
end
3939

40-
# Shutdown all registered providers
40+
# Shutdown all registered providers and clear the configuration
4141
def shutdown
4242
@provider_mutex.synchronize do
4343
@providers.each_value do |provider|
4444
provider.shutdown if provider.respond_to?(:shutdown)
4545
end
46+
@providers.clear
4647
end
4748
end
4849
end

spec/open_feature/sdk/configuration_spec.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,30 @@
6161
let(:provider1) { OpenFeature::SDK::Provider::InMemoryProvider.new }
6262
let(:provider2) { OpenFeature::SDK::Provider::InMemoryProvider.new }
6363

64-
it "calls shutdown on all providers" do
64+
it "calls shutdown on all providers and clears them" do
6565
configuration.set_provider(provider1)
6666
configuration.set_provider(provider2, domain: "testing")
6767

6868
expect(provider1).to receive(:shutdown)
6969
expect(provider2).to receive(:shutdown)
7070

7171
configuration.shutdown
72+
73+
# Verify providers are cleared
74+
expect(configuration.provider).to be_nil
75+
expect(configuration.provider(domain: "testing")).to be_nil
7276
end
7377
end
7478

7579
context "when providers do not have shutdown methods" do
76-
it "does not raise errors for providers without shutdown" do
80+
it "does not raise errors for providers without shutdown and clears them" do
7781
provider_without_shutdown = OpenFeature::SDK::Provider::NoOpProvider.new
7882
configuration.set_provider(provider_without_shutdown)
7983

8084
expect { configuration.shutdown }.not_to raise_error
85+
86+
# Verify providers are cleared
87+
expect(configuration.provider).to be_nil
8188
end
8289
end
8390

spec/specification/flag_evaluation_api_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,20 @@
140140
expect(provider2).to receive(:shutdown)
141141

142142
expect { OpenFeature::SDK.shutdown }.not_to raise_error
143+
144+
# Verify providers are cleared after shutdown
145+
expect(OpenFeature::SDK.provider).to be_nil
146+
expect(OpenFeature::SDK.provider(domain: "testing")).to be_nil
143147
end
144148

145149
specify "Shutdown does not raise errors when providers don't have shutdown methods" do
146150
provider_without_shutdown = OpenFeature::SDK::Provider::NoOpProvider.new
147151
OpenFeature::SDK.set_provider(provider_without_shutdown)
148152

149153
expect { OpenFeature::SDK.shutdown }.not_to raise_error
154+
155+
# Verify providers are cleared after shutdown
156+
expect(OpenFeature::SDK.provider).to be_nil
150157
end
151158
end
152159
end

0 commit comments

Comments
 (0)