@@ -235,3 +235,47 @@ def test_expire_aggregate(env):
235235 # This test ensures that the flag indicating expiration is cleared and the search result struct is ready to be re-used.
236236 res = conn .execute_command ('FT.AGGREGATE' , 'idx' , '*' , 'LOAD' , 1 , '@t' )
237237 env .assertEqual (res , [1 , None , ['t' , 'arr' ]])
238+
239+
240+ # Verify that background indexing does not cause lazy expiration of expired documents.
241+ @skip (cluster = True )
242+ def test_background_index_no_lazy_expiration (env ):
243+ env .cmd ('DEBUG' , 'SET-ACTIVE-EXPIRE' , '0' )
244+ env .expect ('HSET' , 'doc:1' , 't' , 'bar' ).equal (1 )
245+ env .expect ('HSET' , 'doc:2' , 't' , 'arr' ).equal (1 )
246+ env .expect ('EXPIRE' , 'doc:1' , '1' ).equal (1 )
247+ time .sleep (1.5 )
248+
249+ # Expect background indexing to take place after doc:1 has expired.
250+ env .expect ('FT.CREATE' , 'idx' , 'SCHEMA' , 't' , 'TEXT' ).equal ('OK' )
251+ waitForIndex (env , 'idx' )
252+
253+ # Validate that doc:1 has expired but not evicted.
254+ env .expect ('FT.SEARCH' , 'idx' , '*' ).equal ([1 , 'doc:2' , ['t' , 'arr' ]])
255+ env .expect ('DBSIZE' ).equal (2 )
256+
257+ # Accessing doc:1 directly should cause lazy expire and its removal from the DB.
258+ env .expect ('HGET' , 'doc:1' , 't' ).equal (None )
259+ env .expect ('DBSIZE' ).equal (1 )
260+
261+
262+ # Same test as the above but for JSON documents.
263+ @skip (cluster = True )
264+ def test_background_index_no_lazy_expiration_json (env ):
265+ env .cmd ('DEBUG' , 'SET-ACTIVE-EXPIRE' , '0' )
266+ env .expect ('JSON.SET' , 'doc:1' , "$" , r'{"t":"bar"}' ).ok ()
267+ env .expect ('JSON.SET' , 'doc:2' , "$" , r'{"t":"arr"}' ).ok ()
268+ env .expect ('EXPIRE' , 'doc:1' , '1' ).equal (1 )
269+ time .sleep (1.5 )
270+
271+ # Expect background indexing to take place after doc:1 has expired.
272+ env .expect ('FT.CREATE' , 'idx' , 'ON' , 'JSON' , 'SCHEMA' , 't' , 'TEXT' ).equal ('OK' )
273+ waitForIndex (env , 'idx' )
274+
275+ # Validate that doc:1 has expired but not evicted.
276+ env .expect ('FT.SEARCH' , 'idx' , '*' ).equal ([1 , 'doc:2' , ['$' , '{"t":"arr"}' ]])
277+ env .expect ('DBSIZE' ).equal (2 )
278+
279+ # Accessing doc:1 directly should cause lazy expire and its removal from the DB.
280+ env .expect ('JSON.GET' , 'doc:1' , "$" ).equal (None )
281+ env .expect ('DBSIZE' ).equal (1 )
0 commit comments