@@ -232,3 +232,48 @@ func TestCheckAllBackends_MultipleBackends(t *testing.T) {
232232 }
233233 }
234234}
235+
236+ func TestCheckAllBackends_EmptyBackends (t * testing.T ) {
237+ lb := NewLoadBalancer (nil )
238+
239+ config := & ProxyConfig {
240+ HealthCheckPort : 4723 ,
241+ HealthCheckPath : "/" ,
242+ HealthCheckInterval : 1 * time .Second ,
243+ HealthCheckTimeout : 2 * time .Second ,
244+ ExpectedStatusCode : http .StatusNotFound ,
245+ }
246+ hc := NewHealthChecker (config , lb )
247+
248+ // Should not panic with zero backends.
249+ hc .checkAllBackends (context .Background ())
250+
251+ if primary := lb .GetPrimary (); primary != nil {
252+ t .Errorf ("expected nil primary with no backends, got %v" , primary )
253+ }
254+ }
255+
256+ func TestHealthCheckerUpdateConfig (t * testing.T ) {
257+ server := httptest .NewTLSServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
258+ w .WriteHeader (http .StatusNotFound )
259+ }))
260+ defer server .Close ()
261+
262+ hc , _ := setupSingleBackend (t , server , http .StatusNotFound )
263+
264+ newConfig := & ProxyConfig {
265+ HealthCheckPort : 4723 ,
266+ HealthCheckPath : "/" ,
267+ HealthCheckInterval : 10 * time .Second ,
268+ HealthCheckTimeout : 30 * time .Second ,
269+ ExpectedStatusCode : http .StatusNotFound ,
270+ }
271+ hc .UpdateConfig (newConfig )
272+
273+ if hc .config .HealthCheckInterval != 10 * time .Second {
274+ t .Errorf ("expected interval 10s, got %v" , hc .config .HealthCheckInterval )
275+ }
276+ if hc .httpClient .Timeout != 30 * time .Second {
277+ t .Errorf ("expected timeout 30s, got %v" , hc .httpClient .Timeout )
278+ }
279+ }
0 commit comments