mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-10-12 20:26:37 +08:00
fix(agent): retire replaced tunnel sessions (#541)
This commit is contained in:
@@ -28,7 +28,13 @@ func (r *chainRegistry) Register(name string, v chain.Chainer) error {
|
||||
}
|
||||
|
||||
func (r *chainRegistry) replace(name string, v chain.Chainer) {
|
||||
r.m.Store(name, v)
|
||||
old, loaded := r.m.Swap(name, v)
|
||||
if !loaded {
|
||||
return
|
||||
}
|
||||
if retirer, ok := old.(interface{ Retire() }); ok {
|
||||
retirer.Retire()
|
||||
}
|
||||
}
|
||||
|
||||
func (r *chainRegistry) Get(name string) chain.Chainer {
|
||||
|
||||
@@ -16,6 +16,15 @@ func (c testChainer) Route(context.Context, string, string, ...chain.RouteOption
|
||||
return c.route
|
||||
}
|
||||
|
||||
type retiringTestChainer struct {
|
||||
testChainer
|
||||
retired bool
|
||||
}
|
||||
|
||||
func (c *retiringTestChainer) Retire() {
|
||||
c.retired = true
|
||||
}
|
||||
|
||||
type testRoute struct {
|
||||
nodes []*chain.Node
|
||||
}
|
||||
@@ -49,3 +58,20 @@ func TestReplaceChainOverwritesExistingRegistration(t *testing.T) {
|
||||
t.Fatalf("expected replacement chain route, got %#v", route)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplaceChainRetiresPreviousRegistration(t *testing.T) {
|
||||
name := "replace_chain_retire_tdd"
|
||||
ChainRegistry().Unregister(name)
|
||||
defer ChainRegistry().Unregister(name)
|
||||
|
||||
old := &retiringTestChainer{}
|
||||
if err := ChainRegistry().Register(name, old); err != nil {
|
||||
t.Fatalf("register old chain: %v", err)
|
||||
}
|
||||
if err := ReplaceChain(name, testChainer{}); err != nil {
|
||||
t.Fatalf("replace chain: %v", err)
|
||||
}
|
||||
if !old.retired {
|
||||
t.Fatal("previous chain was not retired")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user