test(worker): add retry and persistence checks and adapt attachment tests for async processing

This commit is contained in:
kk10
2026-11-16 12:41:11 +03:00
parent 4a6176fe81
commit eafc437933
9 changed files with 345 additions and 70 deletions
+31 -3
View File
@@ -1,4 +1,4 @@
//go:build contract || reconcile || failure
//go:build contract || reconcile || failure || worker
package studenttests_test
@@ -8,6 +8,7 @@ import (
"net/http"
"net/url"
"testing"
"time"
"github.com/google/uuid"
@@ -49,12 +50,12 @@ func uploadPNG(t *testing.T, actor testUser, chatID uuid.UUID) dto.AttachmentRes
t.Helper()
resp := uploadAttachment(t, actor, chatID, "sample.png", "image/png", makePNG(t, 32, 32))
requireStatus(t, resp, http.StatusCreated)
requireStatus(t, resp, http.StatusAccepted)
var att dto.AttachmentResponse
mustDecode(t, resp, &att)
return att
return waitAttachment(t, actor, att.ID, "ready", time.Minute)
}
func postMessage(
@@ -104,3 +105,30 @@ func requireErrorCode(t *testing.T, resp *http.Response, code dto.ErrorCode) {
t.Errorf("expected error code %q, got %q", code, apiErr.Error.Code)
}
}
func waitAttachment(
t *testing.T,
actor testUser,
id uuid.UUID,
status string,
timeout time.Duration,
) dto.AttachmentResponse {
t.Helper()
deadline := time.Now().Add(timeout)
for time.Now().Before(deadline) {
resp := doRequest(t, http.MethodGet, "/api/v1/attachments/"+id.String(), actor.Token, nil)
requireStatus(t, resp, http.StatusOK)
var att dto.AttachmentResponse
mustDecode(t, resp, &att)
if string(att.Status) == status {
return att
}
if att.Status == "failed" {
t.Fatalf("attachment failed: %v", att.ErrorCode)
}
time.Sleep(200 * time.Millisecond)
}
t.Fatalf("attachment did not reach %s within %s", status, timeout)
return dto.AttachmentResponse{}
}