test(broker): cover adopted probe idle retirement
- commit
- 644a9a8e966c6c1af01b6111b8e5d3af19ce09db
- author
- brice · · 2026-09-22 21:20 UTC
- parent
- 9c5858a
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +9 -3
M internal/usecase/broker/pool.go +1 -1
| @@ -551,7 +551,7 @@ func (p *Pool) watchAdopted(e *poolEntry) { | |||
| 551 | 551 | continue | |
| 552 | 552 | case <-expiry: | |
| 553 | 553 | p.mu.Lock() | |
| 554 | - | if e.refs == 0 { | |
| 554 | + | if e.refs == 0 && e.idleOrder != 0 { | |
| 555 | 555 | e.retiring = true | |
| 556 | 556 | p.mu.Unlock() | |
| 557 | 557 | goto retire | |
| @@ -551,7 +551,7 @@ func (p *Pool) watchAdopted(e *poolEntry) { | |||||
| 551 | continue | 551 | continue | ||
| 552 | case <-expiry: | 552 | case <-expiry: | ||
| 553 | p.mu.Lock() | 553 | p.mu.Lock() | ||
| 554 | - | if e.refs == 0 { | 554 | + | if e.refs == 0 && e.idleOrder != 0 { |
| 555 | e.retiring = true | 555 | e.retiring = true | ||
| 556 | p.mu.Unlock() | 556 | p.mu.Unlock() | ||
| 557 | goto retire | 557 | goto retire | ||
M internal/usecase/broker/pool_warm_test.go +8 -2
| @@ -198,13 +198,15 @@ func TestPoolAdoptProbePhysical(t *testing.T) { | |||
| 198 | 198 | for _, tt := range []struct { | |
| 199 | 199 | name string | |
| 200 | 200 | warm int | |
| 201 | + | idle time.Duration | |
| 201 | 202 | want bool | |
| 202 | 203 | }{ | |
| 203 | 204 | {name: "warm probe is reused", warm: 2, want: true}, | |
| 205 | + | {name: "warm probe has idle deadline", warm: 2, idle: time.Minute, want: true}, | |
| 204 | 206 | {name: "warm disabled refuses probe", warm: 0}, | |
| 205 | 207 | } { | |
| 206 | 208 | t.Run(tt.name, func(t *testing.T) { | |
| 207 | - | h := newWarmHarness(t, tt.warm, 0) | |
| 209 | + | h := newWarmHarness(t, tt.warm, tt.idle) | |
| 208 | 210 | physical := &fakePhysical{endpoint: ports.BrokerDialTarget{Policy: poolPolicy(), ExpectedIdentity: ports.BrokerExpectedIdentity{Identity: "alpha", Bound: true}}, done: make(chan struct{})} | |
| 209 | 211 | require.Equal(t, tt.want, h.pool.AdoptPhysical(physical, poolPolicy())) | |
| 210 | 212 | if !tt.want { | |
| @@ -217,7 +219,11 @@ func TestPoolAdoptProbePhysical(t *testing.T) { | |||
| 217 | 219 | h.visit(t, "alpha") | |
| 218 | 220 | require.Empty(t, h.physicals("alpha"), "attach must not redial after a first probe") | |
| 219 | 221 | require.False(t, h.pool.AdoptPhysical(&fakePhysical{endpoint: physical.endpoint, done: make(chan struct{})}, poolPolicy()), "duplicate probe cannot replace the attachment") | |
| 220 | - | require.NoError(t, h.pool.Close()) | |
| 222 | + | if tt.idle > 0 { | |
| 223 | + | h.reap(t, physical, tt.idle) | |
| 224 | + | } else { | |
| 225 | + | require.NoError(t, h.pool.Close()) | |
| 226 | + | } | |
| 221 | 227 | require.True(t, closed(physical)) | |
| 222 | 228 | }) | |
| 223 | 229 | } | |
| @@ -198,13 +198,15 @@ func TestPoolAdoptProbePhysical(t *testing.T) { | |||||
| 198 | for _, tt := range []struct { | 198 | for _, tt := range []struct { | ||
| 199 | name string | 199 | name string | ||
| 200 | warm int | 200 | warm int | ||
| 201 | + | idle time.Duration | |||
| 201 | want bool | 202 | want bool | ||
| 202 | }{ | 203 | }{ | ||
| 203 | {name: "warm probe is reused", warm: 2, want: true}, | 204 | {name: "warm probe is reused", warm: 2, want: true}, | ||
| 205 | + | {name: "warm probe has idle deadline", warm: 2, idle: time.Minute, want: true}, | |||
| 204 | {name: "warm disabled refuses probe", warm: 0}, | 206 | {name: "warm disabled refuses probe", warm: 0}, | ||
| 205 | } { | 207 | } { | ||
| 206 | t.Run(tt.name, func(t *testing.T) { | 208 | t.Run(tt.name, func(t *testing.T) { | ||
| 207 | - | h := newWarmHarness(t, tt.warm, 0) | 209 | + | h := newWarmHarness(t, tt.warm, tt.idle) |
| 208 | physical := &fakePhysical{endpoint: ports.BrokerDialTarget{Policy: poolPolicy(), ExpectedIdentity: ports.BrokerExpectedIdentity{Identity: "alpha", Bound: true}}, done: make(chan struct{})} | 210 | physical := &fakePhysical{endpoint: ports.BrokerDialTarget{Policy: poolPolicy(), ExpectedIdentity: ports.BrokerExpectedIdentity{Identity: "alpha", Bound: true}}, done: make(chan struct{})} | ||
| 209 | require.Equal(t, tt.want, h.pool.AdoptPhysical(physical, poolPolicy())) | 211 | require.Equal(t, tt.want, h.pool.AdoptPhysical(physical, poolPolicy())) | ||
| 210 | if !tt.want { | 212 | if !tt.want { | ||
| @@ -217,7 +219,11 @@ func TestPoolAdoptProbePhysical(t *testing.T) { | |||||
| 217 | h.visit(t, "alpha") | 219 | h.visit(t, "alpha") | ||
| 218 | require.Empty(t, h.physicals("alpha"), "attach must not redial after a first probe") | 220 | require.Empty(t, h.physicals("alpha"), "attach must not redial after a first probe") | ||
| 219 | require.False(t, h.pool.AdoptPhysical(&fakePhysical{endpoint: physical.endpoint, done: make(chan struct{})}, poolPolicy()), "duplicate probe cannot replace the attachment") | 221 | require.False(t, h.pool.AdoptPhysical(&fakePhysical{endpoint: physical.endpoint, done: make(chan struct{})}, poolPolicy()), "duplicate probe cannot replace the attachment") | ||
| 220 | - | require.NoError(t, h.pool.Close()) | 222 | + | if tt.idle > 0 { |
| 223 | + | h.reap(t, physical, tt.idle) | |||
| 224 | + | } else { | |||
| 225 | + | require.NoError(t, h.pool.Close()) | |||
| 226 | + | } | |||
| 221 | require.True(t, closed(physical)) | 227 | require.True(t, closed(physical)) | ||
| 222 | }) | 228 | }) | ||
| 223 | } | 229 | } | ||