feat(worker): add optimized WebP variant
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"golang.org/x/image/webp"
|
||||
|
||||
"mtusi2026-messenger/internal/dto"
|
||||
)
|
||||
@@ -160,17 +161,23 @@ func TestWorkerPersistenceAndDuplicate(t *testing.T) {
|
||||
if err != nil || cfg.Width != 128 || cfg.Height != 128 {
|
||||
t.Fatal("invalid JPEG crop")
|
||||
}
|
||||
// Re-publish the same intent, modeling duplicate delivery after a lost publisher confirmation.
|
||||
optimized := workerContent(t, user, att.ID, "optimized")
|
||||
cfg, err = webp.DecodeConfig(bytes.NewReader(optimized))
|
||||
if err != nil || cfg.Width != 320 || cfg.Height != 200 {
|
||||
t.Fatal("invalid optimized WebP")
|
||||
}
|
||||
|
||||
workerSQL(t, "UPDATE outbox SET published_at=NULL WHERE "+where)
|
||||
workerWait(t, "duplicate publication", 15*time.Second, func() bool {
|
||||
return workerSQL(t, "SELECT published_at IS NOT NULL FROM outbox WHERE "+where) == "t"
|
||||
})
|
||||
workerWait(t, "duplicate acknowledgement", 15*time.Second, func() bool { return workerQueue(t) == "0:0" })
|
||||
duplicate := waitAttachment(t, user, att.ID, "ready", 30*time.Second)
|
||||
if !reflect.DeepEqual(ready, duplicate) || workerSQL(t, "SELECT count(*) FROM attachment_variants WHERE "+where) != "2" {
|
||||
if !reflect.DeepEqual(ready, duplicate) || workerSQL(t, "SELECT count(*) FROM attachment_variants WHERE "+where) != "3" {
|
||||
t.Fatal("duplicate job changed metadata or duplicated variants")
|
||||
}
|
||||
if !bytes.Equal(workerContent(t, user, att.ID, "crop"), crop) ||
|
||||
if !bytes.Equal(workerContent(t, user, att.ID, "optimized"), optimized) ||
|
||||
!bytes.Equal(workerContent(t, user, att.ID, "crop"), crop) ||
|
||||
!bytes.Equal(workerContent(t, user, att.ID, "thumbnail"), thumb) ||
|
||||
!bytes.Equal(workerContent(t, user, att.ID, "original"), source) {
|
||||
t.Fatal("duplicate changed content")
|
||||
|
||||
Reference in New Issue
Block a user