MCPcopy
hub / github.com/yusing/godoxy / BenchmarkEntrypointReal

Function BenchmarkEntrypointReal

internal/entrypoint/entrypoint_benchmark_test.go:49–109  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

47}
48
49func BenchmarkEntrypointReal(b *testing.B) {
50 ep := NewTestEntrypoint(b, nil)
51 req := http.Request{
52 Method: http.MethodGet,
53 URL: &url.URL{Path: "/", RawPath: "/"},
54 Host: "test.domain.tld",
55 }
56 ep.SetFindRouteDomains([]string{})
57
58 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
59 w.Header().Set("Content-Length", "1")
60 w.Write([]byte("1"))
61 }))
62 defer srv.Close()
63
64 url, err := url.Parse(srv.URL)
65 if err != nil {
66 b.Fatal(err)
67 }
68
69 host, port, err := net.SplitHostPort(url.Host)
70 if err != nil {
71 b.Fatal(err)
72 }
73
74 portInt, err := strconv.Atoi(port)
75 if err != nil {
76 b.Fatal(err)
77 }
78
79 r, err := route.NewStartedTestRoute(b, &route.Route{
80 Alias: "test",
81 Scheme: routeTypes.SchemeHTTP,
82 Host: host,
83 Port: route.Port{Listening: 18080, Proxy: portInt},
84 HealthCheck: types.HealthCheckConfig{Disable: true},
85 })
86
87 require.NoError(b, err)
88 require.False(b, r.ShouldExclude())
89
90 var w noopResponseWriter
91
92 server, ok := ep.GetServer(":18080")
93 if !ok {
94 b.Fatal("server not found")
95 }
96
97 server.ServeHTTP(&w, &req)
98 if w.statusCode != http.StatusOK {
99 b.Fatalf("status code is not 200: %d", w.statusCode)
100 }
101 if string(w.written) != "1" {
102 b.Fatalf("written is not 1: %s", string(w.written))
103 }
104
105 b.ResetTimer()
106 for b.Loop() {

Callers

nothing calls this directly

Calls 11

HeaderMethod · 0.95
WriteMethod · 0.95
NewStartedTestRouteFunction · 0.92
NewTestEntrypointFunction · 0.85
SetFindRouteDomainsMethod · 0.80
GetServerMethod · 0.80
CloseMethod · 0.65
ShouldExcludeMethod · 0.65
ServeHTTPMethod · 0.65
SetMethod · 0.45
ParseMethod · 0.45

Tested by

no test coverage detected