Skip to content

Commit

Permalink
skip expiredocs test for redis version below 7.2 (#4275)
Browse files Browse the repository at this point in the history
we skip this test for Redis versions below 7.2 due to a bug in PEXPIRE.
In older versions, a bug involving multiple time samplings during PEXPIRE execution can cause keys to prematurely expire, triggering a "del" notification and eliminating them from the index, thus missing from search results.
This impacts the test as the key should be included in the search results but return NULL upon access (i.e lazy expiration).
The bug was resolved in Redis 7.2, ensuring the test's stability.

(cherry picked from commit 3afdc42)

Co-authored-by: meiravgri <meirav.grimberg@redis.com>
  • Loading branch information
github-actions[bot] and meiravgri committed Dec 28, 2023
1 parent 6cfb5a1 commit 84e200f
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions tests/pytests/test_expire.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ def add_explain_to_results(results):
for offset, i in enumerate(range(2, len(results), 2)):
results.insert(i+offset, res_score_and_explanation)
return results

def buildExpireDocsResults(isSortable, isJson):
results = {}
# When calling FT.SEARCH with SORTBY on json index, the sortby field is loaded into the result together with the json document
results[both_docs_no_sortby] = [2, 'doc1', ['t', 'bar'], 'doc2', ['t', 'foo']] if not isJson else [2, 'doc1', ['$', '{"t":"bar"}'], 'doc2', ['$', '{"t":"foo"}']]
results[both_docs_sortby] = [2, 'doc1', ['t', 'bar'], 'doc2', ['t', 'foo']] if not isJson else [2, 'doc1', ['t', 'bar','$', '{"t":"bar"}'], 'doc2', ['t', 'foo', '$', '{"t":"foo"}']]

results[doc1_is_empty] = [2, 'doc1', [], 'doc2', ['t', 'foo']] if not isJson else [2, 'doc1', [], 'doc2', ['$', '{"t":"foo"}']]
results[doc1_is_empty_sortby] = [2, 'doc2', ['t', 'foo'], 'doc1', []] if not isJson else [2, 'doc2', ['t', 'foo', '$', '{"t":"foo"}'], 'doc1', []]

Expand All @@ -87,15 +87,17 @@ def buildExpireDocsResults(isSortable, isJson):
# empty_with_scores_and_explain_last if not isSortable else partial_with_scores_and_explain,
# empty_with_scores_and_explain_last if not isSortable else partial_with_scores_and_explain_last]

@skip(cluster=True)
# Refer to expireDocs for details on why this test is skipped for Redis versions below 7.2
@skip(cluster=True, redis_less_than="7.2")
def testExpireDocs(env):

for isJson in [False, True]:
expected_results = buildExpireDocsResults(False, isJson)
expireDocs(env, False, # Without SORTABLE - since the fields are not SORTABLE, we need to load the results from Redis Keyspace
expected_results, isJson)

@skip(cluster=True)
# Refer to expireDocs for details on why this test is skipped for Redis versions below 7.2
@skip(cluster=True, redis_less_than="7.2")
def testExpireDocsSortable(env):
'''
Same as test `testExpireDocs` only with SORTABLE
Expand All @@ -111,6 +113,13 @@ def testExpireDocsSortable(env):


#TODO: DvirDu: I think this test should be broken down to smaller tests, due to the complexity of the test and the number of cases it covers it is hard to debug
# Skip this test for Redis versions below 7.2 due to a bug in PEXPIRE.
# In older versions, a bug involving multiple time samplings during PEXPIRE execution
# can cause keys to prematurely expire, triggering a "del" notification and eliminating them from the index,
# thus missing from search results.
# This impacts the test as the key should be included in the search results but return NULL upon access
# (i.e lazy expiration).
# The bug was resolved in Redis 7.2, ensuring the test's stability.
def expireDocs(env, isSortable, expected_results, isJson):
'''
This test creates an index and two documents
Expand Down Expand Up @@ -174,7 +183,7 @@ def expireDocs(env, isSortable, expected_results, isJson):
if isJson:
conn.execute_command('JSON.SET', 'doc1', '$', '{"t":"bar"}')
conn.execute_command('JSON.SET', 'doc2', '$', '{"t":"foo"}')
else:
else:
conn.execute_command('HSET', 'doc1', 't', 'bar')
conn.execute_command('HSET', 'doc2', 't', 'foo')

Expand Down

0 comments on commit 84e200f

Please sign in to comment.