MCPcopy Index your code
hub / github.com/tailscale/tailscale / runDialPlanTest

Function runDialPlanTest

control/controlhttp/http_test.go:654–837  ·  view source on GitHub ↗
(t *testing.T, plan *tailcfg.ControlDialPlan, want []netip.Addr, allowFallback bool, maxDuration time.Duration)

Source from the content-addressed store, hash-verified

652}
653
654func runDialPlanTest(t *testing.T, plan *tailcfg.ControlDialPlan, want []netip.Addr, allowFallback bool, maxDuration time.Duration) {
655 client, server := key.NewMachine(), key.NewMachine()
656
657 const (
658 testProtocolVersion = 1
659 httpPort = "80"
660 httpsPort = "443"
661 )
662
663 memNetwork := &memnet.Network{}
664
665 fallbackAddr := netip.MustParseAddr("10.0.0.1")
666 goodAddr := netip.MustParseAddr("10.0.0.2")
667 otherAddr := netip.MustParseAddr("10.0.0.3")
668 other2Addr := netip.MustParseAddr("10.0.0.4")
669 brokenAddr := netip.MustParseAddr("10.0.0.10")
670 slowAddr := netip.MustParseAddr("10.0.0.12")
671
672 makeHandler := func(t *testing.T, name string, host netip.Addr, wrap func(http.Handler) http.Handler) {
673 done := make(chan struct{})
674 t.Cleanup(func() {
675 close(done)
676 })
677 var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
678 conn, err := controlhttpserver.AcceptHTTP(context.Background(), w, r, server, nil)
679 if err != nil {
680 log.Print(err)
681 } else {
682 defer conn.Close()
683 }
684 w.Header().Set("X-Handler-Name", name)
685 <-done
686 })
687 if wrap != nil {
688 handler = wrap(handler)
689 }
690
691 httpLn := must.Get(memNetwork.Listen("tcp", host.String()+":"+httpPort))
692 httpsLn := must.Get(memNetwork.Listen("tcp", host.String()+":"+httpsPort))
693
694 httpServer := &http.Server{Handler: handler}
695 go httpServer.Serve(httpLn)
696 t.Cleanup(func() {
697 httpServer.Close()
698 })
699
700 httpsServer := &http.Server{
701 Handler: handler,
702 TLSConfig: tlsConfig(t),
703 ErrorLog: logger.StdLogger(logger.WithPrefix(t.Logf, "http.Server.ErrorLog: ")),
704 }
705 go httpsServer.ServeTLS(httpsLn, "", "")
706 t.Cleanup(func() {
707 httpsServer.Close()
708 })
709 }
710
711 // Use synctest's controlled time

Callers 1

TestDialPlanFunction · 0.85

Calls 15

ListenMethod · 0.95
ServeMethod · 0.95
CloseMethod · 0.95
dialMethod · 0.95
NewMachineFunction · 0.92
AcceptHTTPFunction · 0.92
GetFunction · 0.92
StdLoggerFunction · 0.92
WithPrefixFunction · 0.92
NewBusFunction · 0.92
NewTrackerFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…