MCPcopy
hub / github.com/cloudflare/cloudflared / TestDatagramConnServe

Function TestDatagramConnServe

quic/v3/muxer_test.go:345–391  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

343}
344
345func TestDatagramConnServe(t *testing.T) {
346 defer leaktest.Check(t)()
347 log := zerolog.Nop()
348 connCtx, connCancel := context.WithCancelCause(t.Context())
349 defer connCancel(context.Canceled)
350 quic := newMockQuicConn(connCtx)
351 session := newMockSession()
352 sessionManager := mockSessionManager{session: &session}
353 conn := v3.NewDatagramConn(quic, &sessionManager, &noopICMPRouter{}, 0, &noopMetrics{}, &log)
354
355 // Setup the muxer
356 ctx, cancel := context.WithCancelCause(t.Context())
357 defer cancel(errors.New("other error"))
358 done := make(chan error, 1)
359 go func() {
360 done <- conn.Serve(ctx)
361 }()
362
363 // Send new session registration
364 datagram := newRegisterSessionDatagram(testRequestID)
365 quic.send <- datagram
366
367 // Wait for session registration response with success
368 datagram = <-quic.recv
369 var resp v3.UDPSessionRegistrationResponseDatagram
370 err := resp.UnmarshalBinary(datagram)
371 if err != nil {
372 t.Fatal(err)
373 }
374
375 if resp.RequestID != testRequestID || resp.ResponseType != v3.ResponseOk {
376 t.Fatalf("expected registration response ok")
377 }
378
379 // We expect the session to be served
380 timer := time.NewTimer(15 * time.Second)
381 defer timer.Stop()
382 select {
383 case <-session.served:
384 break
385 case <-timer.C:
386 t.Fatalf("expected session serve to be called")
387 }
388
389 // Cancel the muxer Serve context and make sure it closes with the expected error
390 assertContextClosed(t, ctx, done, cancel)
391}
392
393// This test exists because decoding multiple packets in parallel with the same decoder
394// instances causes inteference resulting in multiple different raw packets being decoded

Callers

nothing calls this directly

Calls 10

ServeMethod · 0.95
UnmarshalBinaryMethod · 0.95
NewDatagramConnFunction · 0.92
newMockQuicConnFunction · 0.85
newMockSessionFunction · 0.85
assertContextClosedFunction · 0.85
CheckMethod · 0.65
ContextMethod · 0.65
StopMethod · 0.45

Tested by

no test coverage detected