refactor: use nginx -s reload instead of systemd

- doc: add comment
This commit is contained in:
2026-08-17 10:10:14 +08:00
parent 79f18fcdea
commit f536987a7e
62 changed files with 2216 additions and 598 deletions
+26
View File
@@ -10,6 +10,8 @@ import (
"testing"
)
// TestCoordinatorRecoversIntentWithoutRepeatingAppliedOperation 验证崩溃恢复时,
// 若已记录意图的外部副作用经 Inspect 确认为已生效,则直接补记成功而不再重复 Apply。
func TestCoordinatorRecoversIntentWithoutRepeatingAppliedOperation(t *testing.T) {
t.Parallel()
ctx := context.Background()
@@ -30,6 +32,8 @@ func TestCoordinatorRecoversIntentWithoutRepeatingAppliedOperation(t *testing.T)
}
}
// TestCoordinatorRecoversNotAppliedIntentThenExecutesOnce 验证已记录意图但 Inspect
// 确认副作用未发生时,恢复流程会重新 Apply 且只执行一次,最终补记成功。
func TestCoordinatorRecoversNotAppliedIntentThenExecutesOnce(t *testing.T) {
t.Parallel()
ctx := context.Background()
@@ -50,6 +54,8 @@ func TestCoordinatorRecoversNotAppliedIntentThenExecutesOnce(t *testing.T) {
}
}
// TestCoordinatorLeavesIntentPendingWhenInspectionIsUnknown 验证 Inspect 无法确认
// 副作用状态时,返回 UncertainStepError 且步骤保留 INTENT_RECORDED 等待后续恢复。
func TestCoordinatorLeavesIntentPendingWhenInspectionIsUnknown(t *testing.T) {
t.Parallel()
ctx := context.Background()
@@ -72,6 +78,8 @@ func TestCoordinatorLeavesIntentPendingWhenInspectionIsUnknown(t *testing.T) {
}
}
// TestCoordinatorRetriesFailedStepOnlyAfterManualResumeInspection 验证失败的步骤不会
// 自动重试,只有人工恢复后再次调用 ExecuteStep,经 Inspect 确认未生效才重新 Apply。
func TestCoordinatorRetriesFailedStepOnlyAfterManualResumeInspection(t *testing.T) {
t.Parallel()
ctx := context.Background()
@@ -99,6 +107,8 @@ func TestCoordinatorRetriesFailedStepOnlyAfterManualResumeInspection(t *testing.
}
}
// TestCoordinatorCompletesFailedStepAlreadyAppliedBeforeManualResume 验证失败步骤在
// 人工恢复时经 Inspect 发现副作用其实已生效,则直接补记成功而不重复 Apply。
func TestCoordinatorCompletesFailedStepAlreadyAppliedBeforeManualResume(t *testing.T) {
t.Parallel()
ctx := context.Background()
@@ -122,6 +132,8 @@ func TestCoordinatorCompletesFailedStepAlreadyAppliedBeforeManualResume(t *testi
}
}
// TestCoordinatorExclusiveExecutionHonorsContext 验证 RunExclusive 的互斥与上下文取消:
// 已有流程占用执行区时,后续取消的上下文会立即返回 context.Canceled,且不进入执行区。
func TestCoordinatorExclusiveExecutionHonorsContext(t *testing.T) {
t.Parallel()
store := openTestStore(t)
@@ -152,6 +164,10 @@ func TestCoordinatorExclusiveExecutionHonorsContext(t *testing.T) {
}
}
// fakeOperation 测试用的 Operation 实现,可编程地模拟 Apply 与 Inspect 行为。
//
// 字段 applied 表示副作用是否已生效,result 为核对结果,applyErr 与 inspectErr 分别
// 模拟执行与核对失败;applyCalls 与 inspectCalls 用于断言调用次数。
type fakeOperation struct {
applied bool
result json.RawMessage
@@ -161,6 +177,7 @@ type fakeOperation struct {
inspectCalls atomic.Int32
}
// Apply 模拟执行外部副作用:递增 applyCalls 计数,成功时把 applied 置为 true。
func (o *fakeOperation) Apply(context.Context) error {
o.applyCalls.Add(1)
if o.applyErr == nil {
@@ -169,6 +186,8 @@ func (o *fakeOperation) Apply(context.Context) error {
return o.applyErr
}
// Inspect 模拟核对外部副作用:递增 inspectCalls 计数,根据 applied 返回
// APPLIED 或 NOT_APPLIED;若设置了 inspectErr 则返回该错误。
func (o *fakeOperation) Inspect(context.Context) (Inspection, error) {
o.inspectCalls.Add(1)
if o.inspectErr != nil {
@@ -180,6 +199,10 @@ func (o *fakeOperation) Inspect(context.Context) (Inspection, error) {
return Inspection{Status: InspectionNotApplied}, nil
}
// createTestTransaction 创建一条用于测试的事务记录。
//
// 参数 store 为目标存储,suffix 用于生成唯一的事务 ID 与幂等键。创建失败时以
// t.Fatalf 终止测试并返回错误说明。
func createTestTransaction(t *testing.T, store *Store, suffix string) Transaction {
t.Helper()
record, _, err := store.CreateTransaction(context.Background(), CreateRequest{
@@ -194,6 +217,9 @@ func createTestTransaction(t *testing.T, store *Store, suffix string) Transactio
return record
}
// newTestCoordinator 创建用于测试的 Coordinator,日志输出丢弃到 io.Discard。
//
// 参数 store 为底层存储。创建失败时以 t.Fatalf 终止测试。
func newTestCoordinator(t *testing.T, store *Store) *Coordinator {
t.Helper()
coordinator, err := NewCoordinator(store, slog.New(slog.NewTextHandler(io.Discard, nil)))