77 lines
2.8 KiB
Go
77 lines
2.8 KiB
Go
package api
|
|
|
|
import (
|
|
"droboticflow/internal/domain"
|
|
"encoding/json"
|
|
"net/http"
|
|
"reflect"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestWorkBufferRetainsFailedSourceAndRefreshesRecovery(t *testing.T) {
|
|
f := randomClaimFixture(t, 0)
|
|
batch, _ := f.store.GetHumanBatch(f.ctx, f.item.BatchID)
|
|
batch.ProcessingProfile = domain.ProcessingProfileRawHuman
|
|
if err := f.store.UpsertHumanBatch(f.ctx, *batch); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
task, _ := f.store.GetAnnotationTask(f.ctx, f.task.ID)
|
|
task.SourceIsFullVideo, task.TemplateVersion, task.ArtifactID = true, 6, "source-left"
|
|
if err := f.store.UpsertAnnotationTask(f.ctx, *task); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
before, _ := f.store.GetHumanItem(f.ctx, f.item.ID)
|
|
now := time.Now().UTC()
|
|
job, err := f.store.ClaimAnnotationIndex(f.ctx, "buffer-validator", now.Format(time.RFC3339Nano), now.Add(time.Minute).Format(time.RFC3339Nano))
|
|
if err != nil || job == nil {
|
|
t.Fatal("missing job", err)
|
|
}
|
|
job.Status, job.Error = "failed", "IMU row 418451 invalid type gyr"
|
|
if ok, err := f.store.FinishAnnotationIndex(f.ctx, *job); !ok || err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
check := func(want string) {
|
|
t.Helper()
|
|
for _, view := range []string{"", "&view=summary"} {
|
|
response := f.request(http.MethodGet, "/api/plugins/annotation-qa/work-buffer?projectId="+task.ProjectID+view, f.annotator, nil)
|
|
var body struct {
|
|
Occupied int
|
|
Items []domain.HumanItemRecord
|
|
Summaries []annotationBufferSummary
|
|
}
|
|
if response.Code != 200 || json.Unmarshal(response.Body.Bytes(), &body) != nil {
|
|
t.Fatalf("buffer: %d %s", response.Code, response.Body.String())
|
|
}
|
|
if body.Occupied != 1 {
|
|
t.Fatalf("owned task disappeared: %+v", body)
|
|
}
|
|
if view == "" {
|
|
if len(body.Items) != 1 || body.Items[0].SourceValidationStatus != want || body.Items[0].AssignedUserID != before.AssignedUserID {
|
|
t.Fatalf("full buffer: %+v", body)
|
|
}
|
|
} else if len(body.Summaries) != 1 || body.Summaries[0].SourceValidationStatus != want || body.Summaries[0].Version != before.Version {
|
|
t.Fatalf("summary: %+v", body)
|
|
}
|
|
}
|
|
}
|
|
check("failed")
|
|
if err := f.store.RetryAnnotationSourceValidation(f.ctx, *task, false, ""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
check("pending")
|
|
job, err = f.store.ClaimAnnotationIndex(f.ctx, "buffer-repair", now.Format(time.RFC3339Nano), now.Add(time.Minute).Format(time.RFC3339Nano))
|
|
if err != nil || job == nil {
|
|
t.Fatal("missing repair", err)
|
|
}
|
|
job.Status, job.Error = "completed", ""
|
|
if ok, err := f.store.FinishAnnotationIndex(f.ctx, *job); !ok || err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
check("")
|
|
after, _ := f.store.GetHumanItem(f.ctx, f.item.ID)
|
|
if after.Version != before.Version || after.AssignedUserID != before.AssignedUserID || !reflect.DeepEqual(after.Subject, before.Subject) {
|
|
t.Fatal("polling changed ownership or version")
|
|
}
|
|
}
|