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

Function TestServer_MultipleConnections

agent/boundarylogproxy/proxy_test.go:232–291  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

230}
231
232func TestServer_MultipleConnections(t *testing.T) {
233 t.Parallel()
234
235 socketPath := filepath.Join(testutil.TempDirUnixSocket(t), "boundary.sock")
236 srv := boundarylogproxy.NewServer(testutil.Logger(t), socketPath, prometheus.NewRegistry())
237
238 ctx, cancel := context.WithCancel(context.Background())
239 defer cancel()
240
241 err := srv.Start()
242 require.NoError(t, err)
243 t.Cleanup(func() { require.NoError(t, srv.Close()) })
244
245 reporter := &fakeReporter{}
246
247 forwarderDone := make(chan error, 1)
248 go func() {
249 forwarderDone <- srv.RunForwarder(ctx, reporter)
250 }()
251
252 // Create multiple connections and send from each.
253 const numConns = 3
254 var wg sync.WaitGroup
255 wg.Add(numConns)
256 for i := range numConns {
257 go func(connID int) {
258 defer wg.Done()
259 conn, err := net.Dial("unix", socketPath)
260 if err != nil {
261 t.Errorf("conn %d dial: %s", connID, err)
262 }
263 defer conn.Close()
264
265 req := &agentproto.ReportBoundaryLogsRequest{
266 Logs: []*agentproto.BoundaryLog{
267 {
268 Allowed: true,
269 Time: timestamppb.Now(),
270 Resource: &agentproto.BoundaryLog_HttpRequest_{
271 HttpRequest: &agentproto.BoundaryLog_HttpRequest{
272 Method: "GET",
273 Url: "https://example.com",
274 },
275 },
276 },
277 },
278 }
279 sendLogs(t, conn, req)
280 }(i)
281 }
282 wg.Wait()
283
284 require.Eventually(t, func() bool {
285 logs := reporter.getLogs()
286 return len(logs) == numConns
287 }, testutil.WaitShort, testutil.IntervalFast)
288
289 cancel()

Callers

nothing calls this directly

Calls 15

StartMethod · 0.95
CloseMethod · 0.95
RunForwarderMethod · 0.95
getLogsMethod · 0.95
TempDirUnixSocketFunction · 0.92
NewServerFunction · 0.92
LoggerFunction · 0.92
sendLogsFunction · 0.85
CleanupMethod · 0.65
AddMethod · 0.65
DialMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected