chore: 初始开源发布
iotlcm-worker-svr:异步执行中枢(RabbitMQ 消费者 + 全量同步编排)。 - Go module:iotlcm-worker-svr → git.5iot.com/iotlcm-public/iotlcm-worker-svr(214 文件) - 凭据与内部标识脱敏:MySQL/Redis 凭据、私网与生产 IP、内网域名、 库名 xiujie_admin → iotlcm、哨兵名占位 - 159 处真实手机号 → 合法 11 位编造号(保留号段与后 4 位,维持互异, 不破坏「校验 MSISDN 格式」等测试断言) - 移除内部资产:CI 触发器、Jenkins 触发测试文档、预演门禁与镜像 digest 记录 - Dockerfile 改用公共基础镜像(golang:1.25-alpine → alpine:3.23), 移除写死的 git 凭据 - README 重写(架构/全量同步模型/配置/已知失败),补 Apache-2.0 LICENSE,LF 行尾 + .gitattributes 已知:3 个测试包在源仓同一提交上同样失败(client/upstream、 service/allocate、service/inbound),属既有缺陷,本仓未引入亦未修复。
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/queue/zset"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/testutil"
|
||||
)
|
||||
|
||||
// Exercise the real task -> failure pool -> replayed task path for both
|
||||
// TDengine usage chains; a producer-only assertion misses lost package codes.
|
||||
func TestReplayDailyAndMonthlyFailurePoolPreservesPackageCode(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name, operation, period string
|
||||
}{
|
||||
{"daily", "previous_day_usage_full_sync", "20261009"},
|
||||
{"monthly", "previous_month_usage_full_sync", "202609"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
redis := testutil.Redis(t)
|
||||
ctx := context.Background()
|
||||
store, err := zset.New(redis, tc.name+":")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sourceID := tc.name + "-source"
|
||||
if err := store.CreateRun(ctx, zset.RunMeta{RunID: sourceID, Operation: tc.operation, QueryMonth: tc.period}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
task := zset.Task{TaskID: sourceID + ":card-42", RunID: sourceID, Operation: tc.operation, QueryMonth: tc.period, CardID: 42, ICCID: "89860042", ChanKey: "217", TempKey: "sim_yd_v5", PackageCode: "PKG-42"}
|
||||
if n, err := store.EnqueueRunBatch(ctx, sourceID, task.ChanKey, []zset.Task{task}, time.Now().Add(-time.Second)); err != nil || n != 1 {
|
||||
t.Fatalf("enqueue source task: %d, %v", n, err)
|
||||
}
|
||||
if err := store.MarkProducerDone(ctx, sourceID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
now := time.Now()
|
||||
claimed, err := store.ClaimRun(ctx, sourceID, task.ChanKey, now, now.Add(time.Minute), 1)
|
||||
if err != nil || len(claimed) != 1 {
|
||||
t.Fatalf("claim source task: %d, %v", len(claimed), err)
|
||||
}
|
||||
if done, err := store.FinalizeRunTask(ctx, claimed[0], zset.TaskOutcome{ErrorClass: "business", Code: 500, Message: "retry by pool"}); err != nil || !done {
|
||||
t.Fatalf("write failure pool: %v, %v", done, err)
|
||||
}
|
||||
failedKey, _ := store.FailedKey(sourceID)
|
||||
value, err := redis.Do(ctx, "HGET", failedKey, task.TaskID)
|
||||
if err != nil || value == nil {
|
||||
t.Fatalf("failure record missing: %v", err)
|
||||
}
|
||||
var failure zset.FailureRecord
|
||||
if err := json.Unmarshal([]byte(value.String()), &failure); err != nil || failure.PackageCode != task.PackageCode {
|
||||
t.Fatalf("failure pool package code: %+v, %v", failure, err)
|
||||
}
|
||||
if done, err := store.CompleteRunIfIdle(ctx, sourceID); err != nil || !done {
|
||||
t.Fatalf("complete failed source: %v, %v", done, err)
|
||||
}
|
||||
svc, err := NewSimpleReplay(store)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
receipt, err := svc.Request(ctx, sourceID, "42", 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := awaitTargetMaxRound(t, svc, store, receipt.ReplayRunID); got != DefaultReplayMaxRounds {
|
||||
t.Fatalf("unexpected replay budget: %d", got)
|
||||
}
|
||||
now = time.Now()
|
||||
replayed, err := store.ClaimRun(ctx, receipt.ReplayRunID, task.ChanKey, now, now.Add(time.Minute), 1)
|
||||
if err != nil || len(replayed) != 1 {
|
||||
t.Fatalf("claim replayed task: %d, %v", len(replayed), err)
|
||||
}
|
||||
got := replayed[0].Task
|
||||
if got.PackageCode != task.PackageCode || got.QueryMonth != tc.period || got.Operation != tc.operation {
|
||||
t.Fatalf("replayed task lost package or period: %+v", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user