MCPcopy Index your code
hub / github.com/coder/coder / TestTunnelSrcCoordController_AddDestination

Function TestTunnelSrcCoordController_AddDestination

tailnet/controllers_test.go:125–192  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

123}
124
125func TestTunnelSrcCoordController_AddDestination(t *testing.T) {
126 t.Parallel()
127 ctx := testutil.Context(t, testutil.WaitShort)
128 logger := testutil.Logger(t)
129
130 fConn := &fakeCoordinatee{}
131 uut := tailnet.NewTunnelSrcCoordController(logger, fConn)
132
133 // GIVEN: client already connected
134 client1 := newFakeCoordinatorClient(ctx, t)
135 cw1 := uut.New(client1)
136
137 // WHEN: we add 2 destinations
138 dest1 := uuid.UUID{1}
139 dest2 := uuid.UUID{2}
140 addDone := make(chan struct{})
141 go func() {
142 defer close(addDone)
143 uut.AddDestination(dest1)
144 uut.AddDestination(dest2)
145 }()
146
147 // THEN: Controller sends AddTunnel for the destinations
148 for i := range 2 {
149 b0 := byte(i + 1)
150 call := testutil.TryReceive(ctx, t, client1.reqs)
151 require.Equal(t, b0, call.req.GetAddTunnel().GetId()[0])
152 testutil.RequireSend(ctx, t, call.err, nil)
153 }
154 _ = testutil.TryReceive(ctx, t, addDone)
155
156 // THEN: Controller sets destinations on Coordinatee
157 require.Contains(t, fConn.tunnelDestinations, dest1)
158 require.Contains(t, fConn.tunnelDestinations, dest2)
159
160 // WHEN: Closed from server side and reconnects
161 respCall := testutil.TryReceive(ctx, t, client1.resps)
162 testutil.RequireSend(ctx, t, respCall.err, io.EOF)
163 closeCall := testutil.TryReceive(ctx, t, client1.close)
164 testutil.RequireSend(ctx, t, closeCall, nil)
165 err := testutil.TryReceive(ctx, t, cw1.Wait())
166 require.ErrorIs(t, err, io.EOF)
167 client2 := newFakeCoordinatorClient(ctx, t)
168 cws := make(chan tailnet.CloserWaiter)
169 go func() {
170 cws <- uut.New(client2)
171 }()
172
173 // THEN: should immediately send both destinations
174 var dests []byte
175 for range 2 {
176 call := testutil.TryReceive(ctx, t, client2.reqs)
177 dests = append(dests, call.req.GetAddTunnel().GetId()[0])
178 testutil.RequireSend(ctx, t, call.err, nil)
179 }
180 slices.Sort(dests)
181 require.Equal(t, dests, []byte{1, 2})
182

Callers

nothing calls this directly

Calls 13

NewMethod · 0.95
AddDestinationMethod · 0.95
ContextFunction · 0.92
LoggerFunction · 0.92
TryReceiveFunction · 0.92
RequireSendFunction · 0.92
newFakeCoordinatorClientFunction · 0.85
GetAddTunnelMethod · 0.80
WaitMethod · 0.65
EqualMethod · 0.45
GetIdMethod · 0.45

Tested by

no test coverage detected