Skip to content

Commit fa3fc6f

Browse files
committed
fix: only shut down active providers
The spec says that shutdown must shut down active providers, but the current logic shuts down inactive providers. This change fixes that. Separately, the spec might also need to be modified to say "only" active providers. Signed-off-by: Brandon Duffany <[email protected]>
1 parent 9908b97 commit fa3fc6f

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

openfeature/openfeature.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,5 @@ func RemoveHandler(eventType EventType, callback EventCallback) {
8989
// Shutdown active providers
9090
func Shutdown() {
9191
api.Shutdown()
92+
initSingleton()
9293
}

openfeature/openfeature_test.go

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -558,29 +558,50 @@ func TestRequirement_1_1_7(t *testing.T) {
558558
func TestRequirement_1_6_1(t *testing.T) {
559559
defer t.Cleanup(initSingleton)
560560

561-
provider, initSem, shutdownSem := setupProviderWithSemaphores()
561+
provider1, _, shutdownSem1 := setupProviderWithSemaphores()
562562

563563
// Setup provider and wait for initialization done
564-
err := SetProvider(provider)
564+
err := SetProviderAndWait(provider1)
565565
if err != nil {
566566
t.Errorf("error setting up provider %v", err)
567567
}
568568

569+
Shutdown()
570+
571+
// Shutdown should be synchronous. Try a non-blocking receive and fail
572+
// immediately if there is not a value in the channel.
569573
select {
570-
// short enough wait time, but not too long
571-
case <-time.After(100 * time.Millisecond):
572-
t.Errorf("intialization timeout")
573-
case <-initSem:
574+
case <-shutdownSem1:
574575
break
576+
default:
577+
t.Fatalf("shutdown not invoked")
578+
}
579+
580+
// After shutting down the first provider, it should be inactive.
581+
//
582+
// The spec says that shutdown must shut down *active* providers. To test
583+
// this, try shutting down again, and make sure that provider1 is not shut
584+
// down again, since it is now inactive.
585+
provider2, _, shutdownSem2 := setupProviderWithSemaphores()
586+
587+
err = SetProviderAndWait(provider2)
588+
if err != nil {
589+
t.Errorf("error setting up provider %v", err)
575590
}
576591

577592
Shutdown()
578593

579594
select {
580-
// short enough wait time, but not too long
595+
case <-shutdownSem2:
596+
break
597+
default:
598+
t.Fatalf("shutdown not invoked")
599+
}
600+
601+
select {
602+
case <-shutdownSem1:
603+
t.Fatalf("provider1 should not have been shut down again, since it is inactive")
581604
case <-time.After(100 * time.Millisecond):
582-
t.Errorf("shutdown not invoked")
583-
case <-shutdownSem:
584605
break
585606
}
586607
}

0 commit comments

Comments
 (0)