mirror of
https://github.com/fatedier/frp.git
synced 2026-09-09 03:55:56 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1243db2c50 |
@@ -119,7 +119,6 @@ func (monitor *Monitor) checkWorker() {
|
|||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
xl.Tracef("do one health check success")
|
xl.Tracef("do one health check success")
|
||||||
monitor.failedTimes = 0
|
|
||||||
if !monitor.statusOK && monitor.statusNormalFn != nil {
|
if !monitor.statusOK && monitor.statusNormalFn != nil {
|
||||||
xl.Infof("health check status change to success")
|
xl.Infof("health check status change to success")
|
||||||
monitor.statusOK = true
|
monitor.statusOK = true
|
||||||
|
|||||||
@@ -1,65 +0,0 @@
|
|||||||
// Copyright 2026 The frp Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package health
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"strings"
|
|
||||||
"sync/atomic"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestMonitorResetsFailedTimesAfterSuccess(t *testing.T) {
|
|
||||||
var checkCount atomic.Int32
|
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
|
||||||
count := checkCount.Add(1)
|
|
||||||
if count == 1 || count == 2 || count == 4 {
|
|
||||||
w.WriteHeader(http.StatusServiceUnavailable)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
}))
|
|
||||||
defer server.Close()
|
|
||||||
|
|
||||||
var failedCount atomic.Int32
|
|
||||||
monitor := NewMonitor(
|
|
||||||
context.Background(),
|
|
||||||
v1.HealthCheckConfig{
|
|
||||||
Type: "http",
|
|
||||||
Path: "/health",
|
|
||||||
TimeoutSeconds: 1,
|
|
||||||
IntervalSeconds: 1,
|
|
||||||
MaxFailed: 3,
|
|
||||||
},
|
|
||||||
strings.TrimPrefix(server.URL, "http://"),
|
|
||||||
func() {},
|
|
||||||
func() { failedCount.Add(1) },
|
|
||||||
)
|
|
||||||
monitor.interval = 10 * time.Millisecond
|
|
||||||
monitor.Start()
|
|
||||||
defer monitor.Stop()
|
|
||||||
|
|
||||||
require.Eventually(t, func() bool {
|
|
||||||
return checkCount.Load() >= 5
|
|
||||||
}, time.Second, 10*time.Millisecond)
|
|
||||||
require.Equal(t, int32(0), failedCount.Load())
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user