detached e4992c6

test(app): exercise remote probe through the actual pool

commit
e4992c6b3b55ff367914197ba97fab529c765fcd
author
brice · · 2026-09-22 21:26 UTC
parent
d60044d
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
1 file · +20 -19
M internal/app/broker_remote_probe_shared_test.go +20 -19
@@ -5,25 +5,16 @@ import (
55 "errors"
66 "testing"
77
8+ "github.com/bnema/vev/internal/adapters/clock"
89 "github.com/bnema/vev/internal/domain"
910 "github.com/bnema/vev/internal/ports"
1011 portsmocks "github.com/bnema/vev/internal/ports/mocks"
1112 "github.com/bnema/vev/internal/protocol"
13+ "github.com/bnema/vev/internal/usecase/broker"
1214 "github.com/stretchr/testify/mock"
1315 "github.com/stretchr/testify/require"
1416 )
1517
16-// sharedPhysicalsFunc adapts a closure to the probe's pool lending seam.
17-type sharedPhysicalsFunc func(ports.BrokerDaemonIdentity, ports.BrokerPolicy) (ports.BrokerPhysicalConnection, bool)
18-
19-func (f sharedPhysicalsFunc) SharedPhysical(identity ports.BrokerDaemonIdentity, policy ports.BrokerPolicy) (ports.BrokerPhysicalConnection, bool) {
20- return f(identity, policy)
21-}
22-
23-func (sharedPhysicalsFunc) AdoptPhysical(ports.BrokerPhysicalConnection, ports.BrokerPolicy) bool {
24- return false
25-}
26-
2718 // TestBrokerRemoteProbeBorrowsWarmTransport proves observation reuses the
2819 // broker pool's attached or warm transport instead of bootstrapping SSH/QUIC
2920 // again, and redials only when the borrowed transport has retired.
@@ -69,8 +60,10 @@ func TestBrokerRemoteProbeBorrowsWarmTransport(t *testing.T) {
6960 }
7061 if tt.bound && tt.shared {
7162 if tt.openErr != nil {
72- physical.EXPECT().OpenStream(mock.Anything, mock.Anything).Return(nil, tt.openErr)
73- physical.EXPECT().Done().Return(done)
63+ if !tt.retired {
64+ physical.EXPECT().OpenStream(mock.Anything, mock.Anything).Return(nil, tt.openErr)
65+ physical.EXPECT().Done().Return(done)
66+ }
7467 } else {
7568 logical := portsmocks.NewMockBrokerLogicalConnection(t)
7669 var sent protocol.CommandRequest
@@ -91,12 +84,20 @@ func TestBrokerRemoteProbeBorrowsWarmTransport(t *testing.T) {
9184 epoch: 7, routes: routes, binder: portsmocks.NewMockBrokerIdentityBinder(t), connector: connector,
9285 hosts: &routeTestHosts{record: record, found: true},
9386 }
94- probe.shared.share(sharedPhysicalsFunc(func(gotIdentity ports.BrokerDaemonIdentity, gotPolicy ports.BrokerPolicy) (ports.BrokerPhysicalConnection, bool) {
95- if !tt.shared || gotIdentity != identity || gotPolicy != policy {
96- return nil, false
97- }
98- return physical, true
99- }))
87+ // Use the real pool for borrowing. Stateful pool retirement is
88+ // covered with a fake physical in broker's worker tests.
89+ pool, err := broker.NewPool(7, routes, probe.binder, connector, clock.New(), broker.PoolLimits{Physical: 1, Clients: 1, Streams: 2, StreamsPerClient: 2, Warm: 1})
90+ require.NoError(t, err)
91+ t.Cleanup(func() { require.NoError(t, pool.Close()) })
92+ if tt.shared && tt.bound && !tt.retired {
93+ physical.EXPECT().Policy().Return(policy).Maybe()
94+ physical.EXPECT().Identity().Return(identity).Maybe()
95+ physical.EXPECT().Incarnation().Return(ports.BrokerDaemonIncarnation{1}).Maybe()
96+ physical.EXPECT().Done().Return(done).Maybe()
97+ physical.EXPECT().Close().Return(nil).Maybe()
98+ require.True(t, pool.AdoptPhysical(physical, policy))
99+ }
100+ probe.shared.share(pool)
100101
101102 observation, err := probe.Probe(context.Background(), registration)
102103 switch {
@@ -5,25 +5,16 @@ import (
5 "errors"5 "errors"
6 "testing"6 "testing"
7 7
8+ "github.com/bnema/vev/internal/adapters/clock"
8 "github.com/bnema/vev/internal/domain"9 "github.com/bnema/vev/internal/domain"
9 "github.com/bnema/vev/internal/ports"10 "github.com/bnema/vev/internal/ports"
10 portsmocks "github.com/bnema/vev/internal/ports/mocks"11 portsmocks "github.com/bnema/vev/internal/ports/mocks"
11 "github.com/bnema/vev/internal/protocol"12 "github.com/bnema/vev/internal/protocol"
13+ "github.com/bnema/vev/internal/usecase/broker"
12 "github.com/stretchr/testify/mock"14 "github.com/stretchr/testify/mock"
13 "github.com/stretchr/testify/require"15 "github.com/stretchr/testify/require"
14 )16 )
15 17
16-// sharedPhysicalsFunc adapts a closure to the probe's pool lending seam.
17-type sharedPhysicalsFunc func(ports.BrokerDaemonIdentity, ports.BrokerPolicy) (ports.BrokerPhysicalConnection, bool)
18-
19-func (f sharedPhysicalsFunc) SharedPhysical(identity ports.BrokerDaemonIdentity, policy ports.BrokerPolicy) (ports.BrokerPhysicalConnection, bool) {
20- return f(identity, policy)
21-}
22-
23-func (sharedPhysicalsFunc) AdoptPhysical(ports.BrokerPhysicalConnection, ports.BrokerPolicy) bool {
24- return false
25-}
26-
27 // TestBrokerRemoteProbeBorrowsWarmTransport proves observation reuses the18 // TestBrokerRemoteProbeBorrowsWarmTransport proves observation reuses the
28 // broker pool's attached or warm transport instead of bootstrapping SSH/QUIC19 // broker pool's attached or warm transport instead of bootstrapping SSH/QUIC
29 // again, and redials only when the borrowed transport has retired.20 // again, and redials only when the borrowed transport has retired.
@@ -69,8 +60,10 @@ func TestBrokerRemoteProbeBorrowsWarmTransport(t *testing.T) {
69 }60 }
70 if tt.bound && tt.shared {61 if tt.bound && tt.shared {
71 if tt.openErr != nil {62 if tt.openErr != nil {
72- physical.EXPECT().OpenStream(mock.Anything, mock.Anything).Return(nil, tt.openErr)63+ if !tt.retired {
73- physical.EXPECT().Done().Return(done)64+ physical.EXPECT().OpenStream(mock.Anything, mock.Anything).Return(nil, tt.openErr)
65+ physical.EXPECT().Done().Return(done)
66+ }
74 } else {67 } else {
75 logical := portsmocks.NewMockBrokerLogicalConnection(t)68 logical := portsmocks.NewMockBrokerLogicalConnection(t)
76 var sent protocol.CommandRequest69 var sent protocol.CommandRequest
@@ -91,12 +84,20 @@ func TestBrokerRemoteProbeBorrowsWarmTransport(t *testing.T) {
91 epoch: 7, routes: routes, binder: portsmocks.NewMockBrokerIdentityBinder(t), connector: connector,84 epoch: 7, routes: routes, binder: portsmocks.NewMockBrokerIdentityBinder(t), connector: connector,
92 hosts: &routeTestHosts{record: record, found: true},85 hosts: &routeTestHosts{record: record, found: true},
93 }86 }
94- probe.shared.share(sharedPhysicalsFunc(func(gotIdentity ports.BrokerDaemonIdentity, gotPolicy ports.BrokerPolicy) (ports.BrokerPhysicalConnection, bool) {87+ // Use the real pool for borrowing. Stateful pool retirement is
95- if !tt.shared || gotIdentity != identity || gotPolicy != policy {88+ // covered with a fake physical in broker's worker tests.
96- return nil, false89+ pool, err := broker.NewPool(7, routes, probe.binder, connector, clock.New(), broker.PoolLimits{Physical: 1, Clients: 1, Streams: 2, StreamsPerClient: 2, Warm: 1})
97- }90+ require.NoError(t, err)
98- return physical, true91+ t.Cleanup(func() { require.NoError(t, pool.Close()) })
99- }))92+ if tt.shared && tt.bound && !tt.retired {
93+ physical.EXPECT().Policy().Return(policy).Maybe()
94+ physical.EXPECT().Identity().Return(identity).Maybe()
95+ physical.EXPECT().Incarnation().Return(ports.BrokerDaemonIncarnation{1}).Maybe()
96+ physical.EXPECT().Done().Return(done).Maybe()
97+ physical.EXPECT().Close().Return(nil).Maybe()
98+ require.True(t, pool.AdoptPhysical(physical, policy))
99+ }
100+ probe.shared.share(pool)
100 101
101 observation, err := probe.Probe(context.Background(), registration)102 observation, err := probe.Probe(context.Background(), registration)
102 switch {103 switch {

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