kvstore: use batch delete to cleanup old events (#112737)
* use batchdelete for cleaning up old events * comment
This commit is contained in:
@@ -610,3 +610,53 @@ func TestEventStore_CleanupOldEvents_EmptyStore(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 0, deletedCount, "Should not have deleted any events from empty store")
|
||||
}
|
||||
|
||||
func TestEventStore_BatchDelete(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
store := setupTestEventStore(t)
|
||||
|
||||
// Create multiple events (more than batch size to test batching)
|
||||
eventKeys := make([]string, 75)
|
||||
for i := 0; i < 75; i++ {
|
||||
event := Event{
|
||||
Namespace: "default",
|
||||
Group: "apps",
|
||||
Resource: "deployments",
|
||||
Name: "test-deployment",
|
||||
ResourceVersion: int64(1000 + i),
|
||||
Action: DataActionCreated,
|
||||
Folder: "test-folder",
|
||||
PreviousRV: int64(999 + i),
|
||||
}
|
||||
err := store.Save(ctx, event)
|
||||
require.NoError(t, err)
|
||||
|
||||
eventKeys[i] = EventKey{
|
||||
Namespace: event.Namespace,
|
||||
Group: event.Group,
|
||||
Resource: event.Resource,
|
||||
Name: event.Name,
|
||||
ResourceVersion: event.ResourceVersion,
|
||||
Action: event.Action,
|
||||
Folder: event.Folder,
|
||||
}.String()
|
||||
}
|
||||
|
||||
// Batch delete all events
|
||||
err := store.batchDelete(ctx, eventKeys)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Verify all events were deleted
|
||||
for i := 0; i < 75; i++ {
|
||||
_, err := store.Get(ctx, EventKey{
|
||||
Namespace: "default",
|
||||
Group: "apps",
|
||||
Resource: "deployments",
|
||||
Name: "test-deployment",
|
||||
ResourceVersion: int64(1000 + i),
|
||||
Action: DataActionCreated,
|
||||
Folder: "test-folder",
|
||||
})
|
||||
require.Error(t, err, "Event should have been deleted")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user