chore: 并入 iotlcm-worker-svr 历史到 worker-svr/(原提交 96f0f4e)
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/fullsync/runtime"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/queue/zset"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/testutil"
|
||||
)
|
||||
|
||||
func TestSimpleReplayHTTPPrivateNetworkAcceptance(t *testing.T) {
|
||||
redis := testutil.Redis(t)
|
||||
store, _ := zset.New(redis, "sim-status:")
|
||||
service, _ := runtime.NewSimpleReplay(store)
|
||||
ctx := context.Background()
|
||||
key, _ := store.RunMetaKey("source")
|
||||
failed, _ := store.FailedKey("source")
|
||||
_, _ = redis.Do(ctx, "HSET", key, "runId", "source", "status", "completed_with_failures", "producerDone", "1", "currentRound", "1")
|
||||
record := zset.FailureRecord{TaskID: "task", CardID: 1, ICCID: "card", ChanKey: "ch", TempKey: "template"}
|
||||
value, _ := json.Marshal(record)
|
||||
_, _ = redis.Do(ctx, "HSET", failed, "task", string(value))
|
||||
deps := testDependencies()
|
||||
deps.Simple = service
|
||||
handler, err := NewHandler("", deps)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
req := httptest.NewRequest(http.MethodPost, "/internal/v1/full-sync-runs/source/replay", bytes.NewBufferString(`{"requestedBy":"42"}`))
|
||||
w := httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, req)
|
||||
if w.Code != 202 {
|
||||
t.Fatalf("accepted: %d %s", w.Code, w.Body.String())
|
||||
}
|
||||
var receipt runtime.ReplayReceipt
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &receipt); err != nil || receipt.ReplayRunID == "" {
|
||||
t.Fatalf("receipt: %+v %v", receipt, err)
|
||||
}
|
||||
deadline := time.Now().Add(3 * time.Second)
|
||||
for time.Now().Before(deadline) {
|
||||
w := httptest.NewRecorder()
|
||||
req := httptest.NewRequest(http.MethodGet, "/internal/v1/full-sync-replays/"+receipt.ReplayRunID, nil)
|
||||
handler.ServeHTTP(w, req)
|
||||
if w.Code == 200 {
|
||||
var status runtime.ReplayStatus
|
||||
_ = json.Unmarshal(w.Body.Bytes(), &status)
|
||||
if status.Status == "completed" && status.Enqueued == 1 {
|
||||
return
|
||||
}
|
||||
}
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
}
|
||||
t.Fatal("replay HTTP never completed")
|
||||
}
|
||||
Reference in New Issue
Block a user