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

Function TestServer_ForwarderContinuesAfterError

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

Source from the content-addressed store, hash-verified

319}
320
321func TestServer_ForwarderContinuesAfterError(t *testing.T) {
322 t.Parallel()
323
324 socketPath := filepath.Join(testutil.TempDirUnixSocket(t), "boundary.sock")
325 srv := boundarylogproxy.NewServer(testutil.Logger(t), socketPath, prometheus.NewRegistry())
326
327 err := srv.Start()
328 require.NoError(t, err)
329 t.Cleanup(func() { require.NoError(t, srv.Close()) })
330
331 reportNotify := make(chan struct{}, 1)
332 reporter := &fakeReporter{
333 // Simulate an error on the first call.
334 err: context.DeadlineExceeded,
335 errOnce: true,
336 reportCb: func() {
337 reportNotify <- struct{}{}
338 },
339 }
340
341 ctx, cancel := context.WithCancel(context.Background())
342 defer cancel()
343 forwarderDone := make(chan error, 1)
344 go func() {
345 forwarderDone <- srv.RunForwarder(ctx, reporter)
346 }()
347
348 conn, err := net.Dial("unix", socketPath)
349 require.NoError(t, err)
350 defer conn.Close()
351
352 // Send the first message to be processed and wait for failure.
353 req1 := &agentproto.ReportBoundaryLogsRequest{
354 Logs: []*agentproto.BoundaryLog{
355 {
356 Allowed: true,
357 Time: timestamppb.Now(),
358 Resource: &agentproto.BoundaryLog_HttpRequest_{
359 HttpRequest: &agentproto.BoundaryLog_HttpRequest{
360 Method: "GET",
361 Url: "https://example.com/first",
362 },
363 },
364 },
365 },
366 }
367 sendLogs(t, conn, req1)
368
369 select {
370 case <-reportNotify:
371 case <-time.After(testutil.WaitShort):
372 t.Fatal("timed out waiting for first message to be processed")
373 }
374
375 // Send the second message, which should succeed.
376 req2 := &agentproto.ReportBoundaryLogsRequest{
377 Logs: []*agentproto.BoundaryLog{
378 {

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
FatalMethod · 0.80
GetHttpRequestMethod · 0.80
CleanupMethod · 0.65
DialMethod · 0.65

Tested by

no test coverage detected