mirror of
https://github.com/coredns/coredns.git
synced 2026-10-09 03:55:21 -04:00
fix(reload): broadcast shutdown signal (#8504)
* fix(reload): broadcast shutdown signal Signed-off-by: alam0rt <sam@samlockart.com> * fix(reload): scope shutdown state to instances Signed-off-by: alam0rt <sam@samlockart.com> --------- Signed-off-by: alam0rt <sam@samlockart.com>
This commit is contained in:
@@ -30,11 +30,11 @@ func TestParseInvalidCorefile(t *testing.T) {
|
||||
func TestShutdownGate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
q := make(chan bool, 1)
|
||||
q := make(chan struct{})
|
||||
if shutdownRequested(q) {
|
||||
t.Fatalf("expected no shutdown before signal")
|
||||
}
|
||||
q <- true
|
||||
close(q)
|
||||
if !shutdownRequested(q) {
|
||||
t.Fatalf("expected shutdown after signal")
|
||||
}
|
||||
@@ -48,3 +48,64 @@ func TestHookIgnoresNonStartupEvent(t *testing.T) {
|
||||
t.Fatalf("expected no error for non-startup event, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestShutdownRequestedBroadcastsClosedSignal ensures a shutdown remains visible to every observer.
|
||||
func TestShutdownRequestedBroadcastsClosedSignal(t *testing.T) {
|
||||
quit := make(chan struct{})
|
||||
close(quit)
|
||||
|
||||
if !shutdownRequested(quit) {
|
||||
t.Fatal("expected first shutdownRequested call to observe shutdown")
|
||||
}
|
||||
|
||||
if !shutdownRequested(quit) {
|
||||
t.Fatal("expected second shutdownRequested call to observe shutdown as well")
|
||||
}
|
||||
}
|
||||
|
||||
// TestSetupCreatesIndependentReloadStates ensures one instance shutdown does not stop another.
|
||||
func TestSetupCreatesIndependentReloadStates(t *testing.T) {
|
||||
c1 := caddy.NewTestController("dns", `reload 2s 0s`)
|
||||
if err := setup(c1); err != nil {
|
||||
t.Fatalf("expected first setup to succeed, got %v", err)
|
||||
}
|
||||
state1, ok := c1.Get(reloadStorageKey{}).(*reload)
|
||||
if !ok {
|
||||
t.Fatal("expected first controller to own reload state")
|
||||
}
|
||||
|
||||
c2 := caddy.NewTestController("dns", `reload 2s 0s`)
|
||||
if err := setup(c2); err != nil {
|
||||
t.Fatalf("expected second setup to succeed, got %v", err)
|
||||
}
|
||||
state2, ok := c2.Get(reloadStorageKey{}).(*reload)
|
||||
if !ok {
|
||||
t.Fatal("expected second controller to own reload state")
|
||||
}
|
||||
if state1 == state2 {
|
||||
t.Fatal("expected each controller to own independent reload state")
|
||||
}
|
||||
|
||||
if err := state1.shutdown(); err != nil {
|
||||
t.Fatalf("expected first state shutdown to succeed, got %v", err)
|
||||
}
|
||||
if shutdownRequested(state2.quit) {
|
||||
t.Fatal("expected shutting down the first state not to stop the second")
|
||||
}
|
||||
}
|
||||
|
||||
// TestReloadStateShutdownIsIdempotent ensures repeated shutdown callbacks do not panic.
|
||||
func TestReloadStateShutdownIsIdempotent(t *testing.T) {
|
||||
state := newReload()
|
||||
|
||||
if err := state.shutdown(); err != nil {
|
||||
t.Fatalf("expected first shutdown to succeed, got %v", err)
|
||||
}
|
||||
if err := state.shutdown(); err != nil {
|
||||
t.Fatalf("expected second shutdown to succeed, got %v", err)
|
||||
}
|
||||
|
||||
if !shutdownRequested(state.quit) {
|
||||
t.Fatal("expected shutdown after state shutdown")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user