| 68 | } |
| 69 | |
| 70 | func TestQuarantine_ReclaimMixedDeadlines(t *testing.T) { |
| 71 | q := newQuarantine(time.Hour) // entries default to a future deadline |
| 72 | |
| 73 | dueID := uuid.New() |
| 74 | notDueID := uuid.New() |
| 75 | |
| 76 | dueCalled := false |
| 77 | notDueCalled := false |
| 78 | |
| 79 | // Add a "due" entry by overriding the deadline directly. |
| 80 | q.entries = append(q.entries, quarantineEntry{ |
| 81 | blockID: dueID, |
| 82 | tenant: "tenant", |
| 83 | blockType: "wal", |
| 84 | deadline: time.Now().Add(-time.Second), |
| 85 | reclaim: func() error { dueCalled = true; return nil }, |
| 86 | }) |
| 87 | q.add(notDueID, "tenant", "wal", func() error { notDueCalled = true; return nil }) |
| 88 | |
| 89 | results := q.reclaim() |
| 90 | require.Len(t, results, 1) |
| 91 | assert.Equal(t, dueID, results[0].BlockID) |
| 92 | assert.True(t, dueCalled) |
| 93 | assert.False(t, notDueCalled, "future-deadline entry must remain") |
| 94 | |
| 95 | require.Len(t, q.entries, 1) |
| 96 | assert.Equal(t, notDueID, q.entries[0].blockID) |
| 97 | } |
| 98 | |
| 99 | // TestQuarantine_ConcurrentAddAndReclaim verifies that reclaim does not hold |
| 100 | // the mutex while invoking fn — otherwise concurrent adds would deadlock. |