MCPcopy Index your code
hub / github.com/etcd-io/etcd / testServerHTTP

Function testServerHTTP

pkg/proxy/server_test.go:470–590  ·  view source on GitHub ↗
(t *testing.T, secure, delayTx bool)

Source from the content-addressed store, hash-verified

468func TestServerHTTP_Insecure_DelayRx(t *testing.T) { testServerHTTP(t, false, false) }
469func TestServerHTTP_Secure_DelayRx(t *testing.T) { testServerHTTP(t, true, false) }
470func testServerHTTP(t *testing.T, secure, delayTx bool) {
471 lg := zaptest.NewLogger(t)
472 scheme := "tcp"
473 ln1, ln2 := listen(t, scheme, "localhost:0", transport.TLSInfo{}), listen(t, scheme, "localhost:0", transport.TLSInfo{})
474 srcAddr, dstAddr := ln1.Addr().String(), ln2.Addr().String()
475 ln1.Close()
476 ln2.Close()
477
478 mux := http.NewServeMux()
479 mux.HandleFunc("/hello", func(w http.ResponseWriter, req *http.Request) {
480 d, err := io.ReadAll(req.Body)
481 req.Body.Close()
482 require.NoError(t, err) //nolint:testifylint //FIXME
483 _, err = w.Write([]byte(fmt.Sprintf("%q(confirmed)", string(d))))
484 require.NoError(t, err) //nolint:testifylint //FIXME
485 })
486 tlsInfo := createTLSInfo(lg, secure)
487 var tlsConfig *tls.Config
488 if secure {
489 _, err := tlsInfo.ServerConfig()
490 require.NoError(t, err)
491 }
492 srv := &http.Server{
493 Addr: dstAddr,
494 Handler: mux,
495 TLSConfig: tlsConfig,
496 ErrorLog: log.New(io.Discard, "net/http", 0),
497 }
498
499 donec := make(chan struct{})
500 defer func() {
501 srv.Close()
502 <-donec
503 }()
504 go func() {
505 if !secure {
506 srv.ListenAndServe()
507 } else {
508 srv.ListenAndServeTLS(tlsInfo.CertFile, tlsInfo.KeyFile)
509 }
510 defer close(donec)
511 }()
512 time.Sleep(200 * time.Millisecond)
513
514 cfg := ServerConfig{
515 Logger: lg,
516 From: url.URL{Scheme: scheme, Host: srcAddr},
517 To: url.URL{Scheme: scheme, Host: dstAddr},
518 }
519 if secure {
520 cfg.TLSInfo = tlsInfo
521 }
522 p := NewServer(cfg)
523
524 waitForServer(t, p)
525
526 defer func() {
527 lg.Info("closing Proxy server...")

Calls 15

CloseMethod · 0.95
DelayTxMethod · 0.95
UndelayTxMethod · 0.95
DelayRxMethod · 0.95
UndelayRxMethod · 0.95
listenFunction · 0.85
createTLSInfoFunction · 0.85
waitForServerFunction · 0.85
AddrMethod · 0.80
ReadAllMethod · 0.80
ServerConfigMethod · 0.80
InfoMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…