阶段七:完成 React Feature 化与前置重构收口
This commit is contained in:
1 parent
375e84d663
commit
1a228dc35c
305 files changed
+14179
-5431
No files matched your search
@@ -141,13 +141,16 @@ type batchManagementRuntimeFake struct {
|
||||
started []string
|
||||
// canceled 保存取消 worker 的参数。
|
||||
canceled []string
|
||||
// startErr 模拟生命周期协调器登记 worker 失败。
|
||||
startErr error
|
||||
}
|
||||
|
||||
// StartBatch 记录批次 worker 启动。
|
||||
func (runtime *batchManagementRuntimeFake) StartBatch(userID int64, batchID, workerToken string) {
|
||||
func (runtime *batchManagementRuntimeFake) StartBatch(userID int64, batchID, workerToken string) error {
|
||||
// command 保存便于断言的 worker 启动参数。
|
||||
command := batchID + ":" + workerToken
|
||||
runtime.started = append(runtime.started, command)
|
||||
return runtime.startErr
|
||||
}
|
||||
|
||||
// CancelBatch 记录批次 worker 取消。
|
||||
@@ -282,6 +285,40 @@ func TestBatchManagementRetryFailed(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestBatchManagementStartFailureReleasesClaim 验证批次 worker 登记失败时会释放刚声明的租约。
|
||||
func TestBatchManagementStartFailureReleasesClaim(t *testing.T) {
|
||||
// startErr 是生命周期协调器拒绝 worker 的原始错误。
|
||||
startErr := errors.New("worker 启动失败")
|
||||
// repository、runtime 和 service 保存批次启动失败测试依赖。
|
||||
repository := &batchManagementRepositoryFake{batch: BatchInfo{ID: "batch-start-fail", Status: "preview"}, claimed: true, pending: []BatchRow{{ID: 1}}}
|
||||
// runtime 模拟协调器在登记批次 worker 时返回错误。
|
||||
runtime := &batchManagementRuntimeFake{startErr: startErr}
|
||||
// service 使用测试端口执行租约声明和 worker 登记编排。
|
||||
service := newBatchManagementServiceForTest(t, repository, runtime)
|
||||
// batchID、err 保存 worker 登记失败后的批次启动结果。
|
||||
batchID, err := service.StartBatch(context.Background(), 7, "batch-start-fail", time.Minute)
|
||||
if batchID != "" || !errors.Is(err, startErr) || !repository.released {
|
||||
t.Fatalf("start result=%q err=%v released=%v", batchID, err, repository.released)
|
||||
}
|
||||
}
|
||||
|
||||
// TestBatchManagementRetryStartFailureReleasesClaim 验证重试 worker 登记失败时也会释放新租约。
|
||||
func TestBatchManagementRetryStartFailureReleasesClaim(t *testing.T) {
|
||||
// startErr 是重试 worker 生命周期登记失败的原始错误。
|
||||
startErr := errors.New("重试 worker 启动失败")
|
||||
// repository、runtime 和 service 保存批次重试失败测试依赖。
|
||||
repository := &batchManagementRepositoryFake{batch: BatchInfo{ID: "batch-retry-fail", Status: "completed"}, claimed: true, pending: []BatchRow{{ID: 2}}}
|
||||
// runtime 模拟协调器在登记重试 worker 时返回错误。
|
||||
runtime := &batchManagementRuntimeFake{startErr: startErr}
|
||||
// service 使用测试端口执行重试租约和 worker 登记编排。
|
||||
service := newBatchManagementServiceForTest(t, repository, runtime)
|
||||
// batchID、err 保存重试 worker 登记失败后的结果。
|
||||
batchID, err := service.RetryFailedBatch(context.Background(), 7, "batch-retry-fail", time.Minute)
|
||||
if batchID != "" || !errors.Is(err, startErr) || !repository.released {
|
||||
t.Fatalf("retry result=%q err=%v released=%v", batchID, err, repository.released)
|
||||
}
|
||||
}
|
||||
|
||||
// TestBatchManagementCleanupExpiredUploads 验证过期目录清理的成功、失败聚合与取消语义。
|
||||
func TestBatchManagementCleanupExpiredUploads(t *testing.T) {
|
||||
// repository 保存过期批次和清理错误替身。
|
||||
|
||||
Reference in new issue
Block a user