refactor: use nginx -s reload instead of systemd
- doc: add comment
This commit is contained in:
@@ -11,8 +11,10 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// healthyActuatorSample 与线上抓包结果一致的 Actuator 健康响应样例。
|
||||
const healthyActuatorSample = `{"status":"UP","components":{"db":{"status":"UP","components":{"dorisDataSource":{"status":"UP"},"postgresqlDataSource":{"status":"UP"}}},"diskSpace":{"status":"UP"},"ping":{"status":"UP"},"redis":{"status":"UP"}}}`
|
||||
|
||||
// TestActuatorCheckerAcceptsConfirmedResponseShape 验证检查器能接受与真实抓包一致的健康响应并正确解析各组件状态。
|
||||
func TestActuatorCheckerAcceptsConfirmedResponseShape(t *testing.T) {
|
||||
t.Parallel()
|
||||
client := newHTTPClient(func(request *http.Request) *http.Response {
|
||||
@@ -31,6 +33,7 @@ func TestActuatorCheckerAcceptsConfirmedResponseShape(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestActuatorCheckerChecksOnceForTransactionRecovery 验证事务恢复路径中单次采样即可确认已记录的健康步骤。
|
||||
func TestActuatorCheckerChecksOnceForTransactionRecovery(t *testing.T) {
|
||||
t.Parallel()
|
||||
client := newHTTPClient(func(*http.Request) *http.Response {
|
||||
@@ -43,6 +46,7 @@ func TestActuatorCheckerChecksOnceForTransactionRecovery(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestActuatorCheckerSamplesReadinessWithoutRestarting 验证在服务暂未就绪时会持续采样直到就绪,且不会触发重启。
|
||||
func TestActuatorCheckerSamplesReadinessWithoutRestarting(t *testing.T) {
|
||||
t.Parallel()
|
||||
var requests atomic.Int32
|
||||
@@ -61,6 +65,7 @@ func TestActuatorCheckerSamplesReadinessWithoutRestarting(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestActuatorCheckerStopsImmediatelyWhenContainerStops 验证容器停止时等待立即以 ErrWorkloadStopped 失败。
|
||||
func TestActuatorCheckerStopsImmediatelyWhenContainerStops(t *testing.T) {
|
||||
t.Parallel()
|
||||
checker := newTestChecker(t, http.DefaultClient)
|
||||
@@ -71,6 +76,7 @@ func TestActuatorCheckerStopsImmediatelyWhenContainerStops(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestActuatorCheckerHonorsOverallTimeout 验证整体超时到达后返回 DeadlineExceeded 错误。
|
||||
func TestActuatorCheckerHonorsOverallTimeout(t *testing.T) {
|
||||
t.Parallel()
|
||||
client := newHTTPClient(func(*http.Request) *http.Response {
|
||||
@@ -83,6 +89,7 @@ func TestActuatorCheckerHonorsOverallTimeout(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// newTestChecker 以固定短间隔创建测试用检查器。
|
||||
func newTestChecker(t *testing.T, client *http.Client) *ActuatorChecker {
|
||||
t.Helper()
|
||||
checker, err := NewActuatorChecker(client, 5*time.Millisecond)
|
||||
@@ -92,22 +99,27 @@ func newTestChecker(t *testing.T, client *http.Client) *ActuatorChecker {
|
||||
return checker
|
||||
}
|
||||
|
||||
// alwaysRunning 表示工作负载始终处于运行状态,用于大多数测试场景。
|
||||
func alwaysRunning(context.Context) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// roundTripFunc 将普通函数适配为 http.RoundTripper,便于在测试中模拟响应。
|
||||
type roundTripFunc func(*http.Request) (*http.Response, error)
|
||||
|
||||
// RoundTrip 直接调用底层的处理函数返回响应。
|
||||
func (f roundTripFunc) RoundTrip(request *http.Request) (*http.Response, error) {
|
||||
return f(request)
|
||||
}
|
||||
|
||||
// newHTTPClient 返回一个使用给定处理函数生成响应的测试 HTTP 客户端。
|
||||
func newHTTPClient(handle func(*http.Request) *http.Response) *http.Client {
|
||||
return &http.Client{Transport: roundTripFunc(func(request *http.Request) (*http.Response, error) {
|
||||
return handle(request), nil
|
||||
})}
|
||||
}
|
||||
|
||||
// response 构造一个带指定状态码与响应体的最小 HTTP 响应。
|
||||
func response(statusCode int, body string) *http.Response {
|
||||
return &http.Response{
|
||||
StatusCode: statusCode,
|
||||
|
||||
Reference in New Issue
Block a user