(t *testing.T, plan *tailcfg.ControlDialPlan, want []netip.Addr, allowFallback bool, maxDuration time.Duration)
| 652 | } |
| 653 | |
| 654 | func 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 |
no test coverage detected
searching dependent graphs…