@@ -63,6 +63,11 @@ func testCommonIndexBehavior(t *testing.T, indexFactory func(t *testing.T) Index
6363 index := indexFactory (t )
6464 testConcurrentOperations (t , ctx , index )
6565 })
66+
67+ t .Run ("Clear" , func (t * testing.T ) {
68+ index := indexFactory (t )
69+ testClear (t , ctx , index )
70+ })
6671}
6772
6873// testBasicAddAndLookup tests basic Add and Lookup functionality.
@@ -213,6 +218,30 @@ func testEvictBasic(t *testing.T, ctx context.Context, index Index) {
213218 assert .ElementsMatch (t , expected , podsPerKey [requestKey ])
214219}
215220
221+ func testClear (t * testing.T , ctx context.Context , index Index ) {
222+ t .Helper ()
223+ engineKey := BlockHash (17434655 )
224+ requestKey := BlockHash (59244875 )
225+ entries := []PodEntry {
226+ {PodIdentifier : "pod1" , DeviceTier : "gpu" },
227+ {PodIdentifier : "pod2" , DeviceTier : "gpu" },
228+ {PodIdentifier : "pod3" , DeviceTier : "cpu" },
229+ }
230+
231+ // Add entries
232+ err := index .Add (ctx , []BlockHash {engineKey }, []BlockHash {requestKey }, entries )
233+ require .NoError (t , err )
234+
235+ // Clear the index
236+ err = index .Clear (ctx )
237+ require .NoError (t , err )
238+
239+ // Verify that the index is empty
240+ podsPerKey , err := index .Lookup (ctx , []BlockHash {requestKey }, sets.Set [string ]{})
241+ require .NoError (t , err )
242+ assert .Len (t , podsPerKey , 0 )
243+ }
244+
216245// testConcurrentOperations tests thread safety with concurrent operations.
217246func testConcurrentOperations (t * testing.T , ctx context.Context , index Index ) {
218247 t .Helper ()
@@ -245,6 +274,10 @@ func testConcurrentOperations(t *testing.T, ctx context.Context, index Index) {
245274 if err := index .Evict (ctx , engineKey , entries ); err != nil {
246275 errChan <- err
247276 }
277+ case 3 : // Clear
278+ if err := index .Clear (ctx ); err != nil {
279+ errChan <- err
280+ }
248281 }
249282 }
250283 }(goroutineID )
0 commit comments