startDoQServer starts a test DoQ server. Note that it adds its own shutdown to cleanup of t.
(t *testing.T, tlsConf *tls.Config, port int)
| 488 | // startDoQServer starts a test DoQ server. Note that it adds its own shutdown |
| 489 | // to cleanup of t. |
| 490 | func startDoQServer(t *testing.T, tlsConf *tls.Config, port int) (s *testDoQServer) { |
| 491 | tlsConf.NextProtos = []string{NextProtoDQ} |
| 492 | |
| 493 | udpAddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("127.0.0.1:%d", port)) |
| 494 | require.NoError(t, err) |
| 495 | |
| 496 | conn, err := net.ListenUDP("udp", udpAddr) |
| 497 | require.NoError(t, err) |
| 498 | testutil.CleanupAndRequireSuccess(t, conn.Close) |
| 499 | |
| 500 | transport := &quic.Transport{ |
| 501 | Conn: conn, |
| 502 | // Necessary for 0-RTT. |
| 503 | VerifySourceAddress: func(a net.Addr) bool { |
| 504 | return true |
| 505 | }, |
| 506 | } |
| 507 | |
| 508 | listen, err := transport.ListenEarly( |
| 509 | tlsConf, |
| 510 | &quic.Config{ |
| 511 | Allow0RTT: true, |
| 512 | }, |
| 513 | ) |
| 514 | require.NoError(t, err) |
| 515 | testutil.CleanupAndRequireSuccess(t, transport.Close) |
| 516 | |
| 517 | s = &testDoQServer{ |
| 518 | addr: listen.Addr().String(), |
| 519 | listener: listen, |
| 520 | // TODO(d.kolyshev): Add a concurrent safe [slog.Handler] wrapper for |
| 521 | // [testing.TB] log function. |
| 522 | logger: testLogger, |
| 523 | conns: map[*quic.Conn]struct{}{}, |
| 524 | connsMu: &sync.Mutex{}, |
| 525 | } |
| 526 | |
| 527 | go s.Serve() |
| 528 | testutil.CleanupAndRequireSuccess(t, s.Shutdown) |
| 529 | |
| 530 | return s |
| 531 | } |
no test coverage detected
searching dependent graphs…