test(worker): add retry and persistence checks and adapt attachment tests for async processing
This commit is contained in:
@@ -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{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user