mirror of
https://github.com/phishingclub/phishingclub.git
synced 2026-12-06 01:53:42 +01:00
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package service
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/phishingclub/phishingclub/database"
|
|
)
|
|
|
|
// TestDeletePassSkipsHeldRows checks a pass whose oldest marks all wait after
|
|
// a failure still reaches a newer mark
|
|
func TestDeletePassSkipsHeldRows(t *testing.T) {
|
|
f := newDeleteFixture(t)
|
|
var held []uuid.UUID
|
|
for i := 0; i < deletePassScanLimit+2; i++ {
|
|
id := f.group(nil)
|
|
held = append(held, id)
|
|
if err := f.groups.RecipientGroupRepository.MarkDeleting(f.ctx, &id, time.Now().Add(-time.Hour)); err != nil {
|
|
t.Fatalf("mark: %v", err)
|
|
}
|
|
f.groups.deletes.mu.Lock()
|
|
if f.groups.deletes.retryAt == nil {
|
|
f.groups.deletes.retryAt = map[uuid.UUID]time.Time{}
|
|
}
|
|
f.groups.deletes.retryAt[id] = time.Now().Add(time.Hour)
|
|
f.groups.deletes.mu.Unlock()
|
|
}
|
|
newer := f.group(nil)
|
|
if err := f.groups.RecipientGroupRepository.MarkDeleting(f.ctx, &newer, time.Now()); err != nil {
|
|
t.Fatalf("mark: %v", err)
|
|
}
|
|
if err := f.groups.FinishDeletesInBackground(f.ctx, authorizedSession(t)); err != nil {
|
|
t.Fatalf("finish: %v", err)
|
|
}
|
|
f.waitDeletes()
|
|
if f.exists(&database.RecipientGroup{}, newer) {
|
|
t.Fatal("a newer mark must be reached past the held ones")
|
|
}
|
|
if !f.exists(&database.RecipientGroup{}, held[0]) {
|
|
t.Fatal("a held mark waits")
|
|
}
|
|
}
|