detached 644a9a8

test(broker): cover adopted probe idle retirement

commit
644a9a8e966c6c1af01b6111b8e5d3af19ce09db
author
brice · · 2026-09-22 21:20 UTC
parent
9c5858a
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · 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) {
551551 continue
552552 case <-expiry:
553553 p.mu.Lock()
554- if e.refs == 0 {
554+ if e.refs == 0 && e.idleOrder != 0 {
555555 e.retiring = true
556556 p.mu.Unlock()
557557 goto retire
@@ -551,7 +551,7 @@ func (p *Pool) watchAdopted(e *poolEntry) {
551 continue551 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 = true555 e.retiring = true
556 p.mu.Unlock()556 p.mu.Unlock()
557 goto retire557 goto retire
M internal/usecase/broker/pool_warm_test.go +8 -2
@@ -198,13 +198,15 @@ func TestPoolAdoptProbePhysical(t *testing.T) {
198198 for _, tt := range []struct {
199199 name string
200200 warm int
201+ idle time.Duration
201202 want bool
202203 }{
203204 {name: "warm probe is reused", warm: 2, want: true},
205+ {name: "warm probe has idle deadline", warm: 2, idle: time.Minute, want: true},
204206 {name: "warm disabled refuses probe", warm: 0},
205207 } {
206208 t.Run(tt.name, func(t *testing.T) {
207- h := newWarmHarness(t, tt.warm, 0)
209+ h := newWarmHarness(t, tt.warm, tt.idle)
208210 physical := &fakePhysical{endpoint: ports.BrokerDialTarget{Policy: poolPolicy(), ExpectedIdentity: ports.BrokerExpectedIdentity{Identity: "alpha", Bound: true}}, done: make(chan struct{})}
209211 require.Equal(t, tt.want, h.pool.AdoptPhysical(physical, poolPolicy()))
210212 if !tt.want {
@@ -217,7 +219,11 @@ func TestPoolAdoptProbePhysical(t *testing.T) {
217219 h.visit(t, "alpha")
218220 require.Empty(t, h.physicals("alpha"), "attach must not redial after a first probe")
219221 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+ }
221227 require.True(t, closed(physical))
222228 })
223229 }
@@ -198,13 +198,15 @@ func TestPoolAdoptProbePhysical(t *testing.T) {
198 for _, tt := range []struct {198 for _, tt := range []struct {
199 name string199 name string
200 warm int200 warm int
201+ idle time.Duration
201 want bool202 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 }

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 12

Tags 11

↑↓ moveenter openesc close