forked from mtusi2026/mtusi2026lab5
Реализовать уровень 3: очередь RabbitMQ и обработку изображений
Добавить устойчивый приём с ответом 202, durable jobs, dispatcher с publisher confirms и отдельный worker с ручным ACK. Формировать thumbnail, ограничить retry и защитить результат от повторной доставки. Добавить проверки очереди и адаптировать клиент к асинхронным состояниям.
This commit is contained in:
@@ -129,9 +129,13 @@ func TestDirectUploadFlow(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
router := attachmentRouter(f, objects)
|
||||
content := attachmentCall(t, f, router, "GET", "/api/v1/attachments/"+a.ID+"/content", user, "", nil, 200)
|
||||
if !bytes.Equal(content.Body.Bytes(), sample.data) {
|
||||
t.Fatal("original bytes changed")
|
||||
attachmentCall(t, f, router, "GET", "/api/v1/attachments/"+a.ID+"/content", user, "", nil, 409)
|
||||
if a.Status != "queued" {
|
||||
t.Fatal("direct complete must queue processing")
|
||||
}
|
||||
var jobs int
|
||||
if err = f.db.QueryRow(context.Background(), "SELECT count(*) FROM attachment_jobs WHERE attachment_id=$1", a.ID).Scan(&jobs); err != nil || jobs != 1 {
|
||||
t.Fatal("durable job missing", err)
|
||||
}
|
||||
message := []byte(`{"text":"","attachment_ids":["` + a.ID + `"]}`)
|
||||
attachmentCall(t, f, router, "POST", "/api/v1/chats/"+chat+"/messages", user, "application/json", message, 201)
|
||||
@@ -198,7 +202,7 @@ func TestDirectUploadValidationHTTP(t *testing.T) {
|
||||
if status := postDirect(t, result.Upload, uploadPNG(t), nil); status != 204 {
|
||||
t.Fatal("HTTP-created form failed")
|
||||
}
|
||||
attachmentCall(t, f, router, "POST", path+"/"+result.ID+"/complete", user, "", nil, 201)
|
||||
attachmentCall(t, f, router, "POST", path+"/"+result.ID+"/complete", user, "", nil, 202)
|
||||
}
|
||||
|
||||
func TestDirectUploadValidationContents(t *testing.T) {
|
||||
|
||||
@@ -107,6 +107,13 @@ func newTestFixture(t *testing.T) *testFixture {
|
||||
if _, err = db.Exec(ctx, string(ddl)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ddl, err = os.ReadFile("../repositories/migrations/000007_jobs.up.sql")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = db.Exec(ctx, string(ddl)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = redisClient.Close() })
|
||||
if err := redisClient.Ping(ctx).Err(); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user