Debian Codegraph @

modules/caddyhttp/reverseproxy/admin_test.go

raw symbols SCIP
1 // Copyright 2015 Matthew Holt and The Caddy Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package reverseproxyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/
16
17 import (
18 "encoding/jsonscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/"
19 "net/httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/"
20 "net/http/httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/"
21 "testingscip-go gomod github.com/golang/go/src go1.25.1 testing/"
22 "timescip-go gomod github.com/golang/go/src go1.25.1 time/"
23 )
24
25 // adminHandlerFixture sets up the global host state for an admin endpoint test
26 // and returns a cleanup function that must be deferred by the caller.
27 //
28 // staticAddrs are inserted into the UsagePool (as a static upstream would be).
29 // dynamicAddrs are inserted into the dynamicHosts map (as a dynamic upstream would be).
30 func adminHandlerFixturescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/adminHandlerFixture().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#, staticAddrs, dynamicAddrs []string) func() {
31 t.Helperscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Helper().()
32
33 for _, addr := range staticAddrs {
34 u := &Upstreamscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#{Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial.: addr}
35 u.fillHostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#fillHost().()
36 }
37
38 dynamicHostsMuscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/dynamicHostsMu..Lockscip-go gomod github.com/golang/go/src go1.25.1 sync/RWMutex#Lock().()
39 for _, addr := range dynamicAddrs {
40 dynamicHostsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/dynamicHosts.[addr] = dynamicHostEntryscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/dynamicHostEntry#{hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/dynamicHostEntry#host.: new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#), lastSeenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/dynamicHostEntry#lastSeen.: timescip-go gomod github.com/golang/go/src go1.25.1 time/.Nowscip-go gomod github.com/golang/go/src go1.25.1 time/Now().()}
41 }
42 dynamicHostsMuscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/dynamicHostsMu..Unlockscip-go gomod github.com/golang/go/src go1.25.1 sync/RWMutex#Unlock().()
43
44 return func() {
45 // Remove static entries from the UsagePool.
46 for _, addr := range staticAddrs {
47 _, _ = hostsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/hosts..Deletescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/UsagePool#Delete().(addr)
48 }
49 // Remove dynamic entries.
50 dynamicHostsMuscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/dynamicHostsMu..Lockscip-go gomod github.com/golang/go/src go1.25.1 sync/RWMutex#Lock().()
51 for _, addr := range dynamicAddrs {
52 delete(dynamicHostsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/dynamicHosts., addr)
53 }
54 dynamicHostsMuscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/dynamicHostsMu..Unlockscip-go gomod github.com/golang/go/src go1.25.1 sync/RWMutex#Unlock().()
55 }
56 }
57
58 // callAdminUpstreams fires a GET against handleUpstreams and returns the
59 // decoded response body.
60 func callAdminUpstreamsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/callAdminUpstreams().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) []upstreamStatusscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/upstreamStatus# {
61 t.Helperscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Helper().()
62 req := httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/reverse_proxy/upstreams", nil)
63 w := httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRecorderscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRecorder().()
64
65 handler := adminUpstreamsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/adminUpstreams#{}
66 if err := handler.handleUpstreamsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/adminUpstreams#handleUpstreams().(w, req); err != nil {
67 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatalf().("handleUpstreams returned unexpected error: %v", err)
68 }
69 if w.Codescip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/ResponseRecorder#Code. != httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.StatusOKscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/StatusOK. {
70 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatalf().("expected 200, got %d", w.Codescip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/ResponseRecorder#Code.)
71 }
72 if ct := w.Headerscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/ResponseRecorder#Header().().Getscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#Get().("Content-Type"); ct != "application/json" {
73 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatalf().("expected Content-Type application/json, got %q", ct)
74 }
75
76 var results []upstreamStatusscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/upstreamStatus#
77 if err := jsonscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/.NewDecoderscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/NewDecoder().(w.Bodyscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/ResponseRecorder#Body.).Decodescip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/Decoder#Decode().(&results); err != nil {
78 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatalf().("failed to decode response: %v", err)
79 }
80 return results
81 }
82
83 // resultsByAddress indexes a slice of upstreamStatus by address for easier
84 // lookup in assertions.
85 func resultsByAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/resultsByAddress().(statuses []upstreamStatusscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/upstreamStatus#) map[string]upstreamStatusscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/upstreamStatus# {
86 m := make(map[string]upstreamStatusscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/upstreamStatus#, len(statuses))
87 for _, s := range statuses {
88 m[s.Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/upstreamStatus#Address.] = s
89 }
90 return m
91 }
92
93 // TestAdminUpstreamsMethodNotAllowed verifies that non-GET methods are rejected.
94 func TestAdminUpstreamsMethodNotAllowedscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestAdminUpstreamsMethodNotAllowed().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
95 for _, method := range []string{httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodPostscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodPost., httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodPutscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodPut., httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodDeletescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodDelete.} {
96 req := httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(method, "/reverse_proxy/upstreams", nil)
97 w := httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRecorderscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRecorder().()
98 err := (adminUpstreamsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/adminUpstreams#{}).handleUpstreamsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/adminUpstreams#handleUpstreams().(w, req)
99 if err == nil {
100 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("method %s: expected an error, got nil", method)
101 continue
102 }
103 apiErr, ok := err.(interface{ HTTPStatus() int })
104 if !ok {
105 // caddy.APIError stores the code in HTTPStatus field, access via the
106 // exported interface it satisfies indirectly; just check non-nil.
107 continue
108 }
109 if code := apiErr.HTTPStatus(); code != httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.StatusMethodNotAllowedscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/StatusMethodNotAllowed. {
110 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("method %s: expected 405, got %d", method, code)
111 }
112 }
113 }
114
115 // TestAdminUpstreamsEmpty verifies that an empty response is valid JSON when
116 // no upstreams are registered.
117 func TestAdminUpstreamsEmptyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestAdminUpstreamsEmpty().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
118 resetDynamicHostsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/resetDynamicHosts().()
119
120 results := callAdminUpstreamsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/callAdminUpstreams().(t)
121 if results == nil {
122 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("expected non-nil (empty) slice, got nil")
123 }
124 if len(results) != 0 {
125 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("expected 0 results with empty pools, got %d", len(results))
126 }
127 }
128
129 // TestAdminUpstreamsStaticOnly verifies that static upstreams (from the
130 // UsagePool) appear in the response with correct addresses.
131 func TestAdminUpstreamsStaticOnlyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestAdminUpstreamsStaticOnly().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
132 resetDynamicHostsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/resetDynamicHosts().()
133 cleanup := adminHandlerFixturescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/adminHandlerFixture().(t,
134 []string{"10.0.0.1:80", "10.0.0.2:80"},
135 nil,
136 )
137 defer cleanup()
138
139 results := callAdminUpstreamsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/callAdminUpstreams().(t)
140 byAddr := resultsByAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/resultsByAddress().(results)
141
142 for _, addr := range []string{"10.0.0.1:80", "10.0.0.2:80"} {
143 if _, ok := byAddr[addr]; !ok {
144 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("expected static upstream %q in response", addr)
145 }
146 }
147 if len(results) != 2 {
148 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("expected exactly 2 results, got %d", len(results))
149 }
150 }
151
152 // TestAdminUpstreamsDynamicOnly verifies that dynamic upstreams (from
153 // dynamicHosts) appear in the response with correct addresses.
154 func TestAdminUpstreamsDynamicOnlyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestAdminUpstreamsDynamicOnly().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
155 resetDynamicHostsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/resetDynamicHosts().()
156 cleanup := adminHandlerFixturescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/adminHandlerFixture().(t,
157 nil,
158 []string{"10.0.1.1:80", "10.0.1.2:80"},
159 )
160 defer cleanup()
161
162 results := callAdminUpstreamsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/callAdminUpstreams().(t)
163 byAddr := resultsByAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/resultsByAddress().(results)
164
165 for _, addr := range []string{"10.0.1.1:80", "10.0.1.2:80"} {
166 if _, ok := byAddr[addr]; !ok {
167 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("expected dynamic upstream %q in response", addr)
168 }
169 }
170 if len(results) != 2 {
171 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("expected exactly 2 results, got %d", len(results))
172 }
173 }
174
175 // TestAdminUpstreamsBothPools verifies that static and dynamic upstreams are
176 // both present in the same response and that there is no overlap or omission.
177 func TestAdminUpstreamsBothPoolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestAdminUpstreamsBothPools().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
178 resetDynamicHostsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/resetDynamicHosts().()
179 cleanup := adminHandlerFixturescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/adminHandlerFixture().(t,
180 []string{"10.0.2.1:80"},
181 []string{"10.0.2.2:80"},
182 )
183 defer cleanup()
184
185 results := callAdminUpstreamsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/callAdminUpstreams().(t)
186 if len(results) != 2 {
187 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatalf().("expected 2 results (1 static + 1 dynamic), got %d", len(results))
188 }
189
190 byAddr := resultsByAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/resultsByAddress().(results)
191 if _, ok := byAddr["10.0.2.1:80"]; !ok {
192 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("static upstream missing from response")
193 }
194 if _, ok := byAddr["10.0.2.2:80"]; !ok {
195 t.Errorscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Error().("dynamic upstream missing from response")
196 }
197 }
198
199 // TestAdminUpstreamsNoOverlapBetweenPools verifies that an address registered
200 // only as a static upstream does not also appear as a dynamic entry, and
201 // vice-versa.
202 func TestAdminUpstreamsNoOverlapBetweenPoolsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestAdminUpstreamsNoOverlapBetweenPools().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
203 resetDynamicHostsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/resetDynamicHosts().()
204 cleanup := adminHandlerFixturescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/adminHandlerFixture().(t,
205 []string{"10.0.3.1:80"},
206 []string{"10.0.3.2:80"},
207 )
208 defer cleanup()
209
210 results := callAdminUpstreamsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/callAdminUpstreams().(t)
211 seen := make(map[string]int)
212 for _, r := range results {
213 seen[r.Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/upstreamStatus#Address.]++
214 }
215 for addr, count := range seen {
216 if count > 1 {
217 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("address %q appeared %d times; expected exactly once", addr, count)
218 }
219 }
220 }
221
222 // TestAdminUpstreamsReportsFailCounts verifies that fail counts accumulated on
223 // a dynamic upstream's Host are reflected in the response.
224 func TestAdminUpstreamsReportsFailCountsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestAdminUpstreamsReportsFailCounts().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
225 resetDynamicHostsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/resetDynamicHosts().()
226
227 const addr = "10.0.4.1:80"
228 h := new(Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#)
229 _ = h.countFailscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#countFail().(3)
230
231 dynamicHostsMuscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/dynamicHostsMu..Lockscip-go gomod github.com/golang/go/src go1.25.1 sync/RWMutex#Lock().()
232 dynamicHostsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/dynamicHosts.[addr] = dynamicHostEntryscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/dynamicHostEntry#{hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/dynamicHostEntry#host.: h, lastSeenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/dynamicHostEntry#lastSeen.: timescip-go gomod github.com/golang/go/src go1.25.1 time/.Nowscip-go gomod github.com/golang/go/src go1.25.1 time/Now().()}
233 dynamicHostsMuscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/dynamicHostsMu..Unlockscip-go gomod github.com/golang/go/src go1.25.1 sync/RWMutex#Unlock().()
234 defer func() {
235 dynamicHostsMuscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/dynamicHostsMu..Lockscip-go gomod github.com/golang/go/src go1.25.1 sync/RWMutex#Lock().()
236 delete(dynamicHostsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/dynamicHosts., addr)
237 dynamicHostsMuscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/dynamicHostsMu..Unlockscip-go gomod github.com/golang/go/src go1.25.1 sync/RWMutex#Unlock().()
238 }()
239
240 results := callAdminUpstreamsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/callAdminUpstreams().(t)
241 byAddr := resultsByAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/resultsByAddress().(results)
242
243 status, ok := byAddr[addr]
244 if !ok {
245 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatalf().("expected %q in response", addr)
246 }
247 if status.Failsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/upstreamStatus#Fails. != 3 {
248 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("expected Fails=3, got %d", status.Failsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/upstreamStatus#Fails.)
249 }
250 }
251
252 // TestAdminUpstreamsReportsNumRequests verifies that the active request count
253 // for a static upstream is reflected in the response.
254 func TestAdminUpstreamsReportsNumRequestsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TestAdminUpstreamsReportsNumRequests().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) {
255 resetDynamicHostsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/resetDynamicHosts().()
256
257 const addr = "10.0.4.2:80"
258 u := &Upstreamscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#{Dialscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Dial.: addr}
259 u.fillHostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#fillHost().()
260 defer func() { _, _ = hostsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/hosts..Deletescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/UsagePool#Delete().(addr) }()
261
262 _ = u.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host..countRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#countRequest().(2)
263 defer func() { _ = u.Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Upstream#Host..countRequestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/Host#countRequest().(-2) }()
264
265 results := callAdminUpstreamsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/callAdminUpstreams().(t)
266 byAddr := resultsByAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/resultsByAddress().(results)
267
268 status, ok := byAddr[addr]
269 if !ok {
270 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatalf().("expected %q in response", addr)
271 }
272 if status.NumRequestsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/upstreamStatus#NumRequests. != 2 {
273 t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("expected NumRequests=2, got %d", status.NumRequestsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/upstreamStatus#NumRequests.)
274 }
275 }