lab4: исправления по ревью
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package attachment_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -88,3 +89,38 @@ func TestSweepSkipsWhenAnotherReplicaHoldsTheLock(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Zero(t, stats)
|
||||
}
|
||||
|
||||
func TestSweepKeepsObjectWhenMarkReadyFails(t *testing.T) {
|
||||
repo := mocks.NewMockRepository(t)
|
||||
locker := mocks.NewMockLockStore(t)
|
||||
store := newFakeStore()
|
||||
|
||||
stale := time.Now().UTC().Add(-time.Hour)
|
||||
row := domain.Attachment{
|
||||
ID: uuid.New(), ObjectKey: "attachments/chat/" + uuid.NewString(),
|
||||
SizeBytes: 3, SHA256: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
Status: domain.AttachmentPending, CreatedAt: stale,
|
||||
}
|
||||
|
||||
store.objects[row.ObjectKey] = storedObject{
|
||||
data: []byte("abc"),
|
||||
lastModified: stale,
|
||||
metadata: map[string]string{"sha256": row.SHA256},
|
||||
}
|
||||
|
||||
repo.EXPECT().ListStalePending(mock.Anything, mock.Anything, int32(100)).
|
||||
Return([]domain.Attachment{row}, nil).Once()
|
||||
repo.EXPECT().MarkReady(mock.Anything, row.ID, row.ObjectKey).
|
||||
Return(domain.Attachment{}, context.DeadlineExceeded).Once()
|
||||
repo.EXPECT().ListKeys(mock.Anything, int32(1000), int32(0)).
|
||||
Return([]domain.AttachmentKey{{ID: row.ID, ObjectKey: row.ObjectKey, Status: domain.AttachmentPending}}, nil).Once()
|
||||
locker.EXPECT().AcquireSweepLock(mock.Anything).Return(func() {}, true, nil).Once()
|
||||
|
||||
sweeper := attachment.NewSweeper(repo, store, locker, time.Minute, time.Hour, slog.Default())
|
||||
|
||||
stats, err := sweeper.SweepOnce(t.Context())
|
||||
require.NoError(t, err)
|
||||
require.Zero(t, stats.Recovered)
|
||||
require.Zero(t, stats.RowsDeleted)
|
||||
require.Contains(t, store.objects, row.ObjectKey)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user