Skip to content

Commit 2188b43

Browse files
author
DvirDukhan
committed
adapt changes to new redis-py errors
1 parent ffd5931 commit 2188b43

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

tests/flow/includes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def run_test_multiproc(env, routing_hint, n_procs, fn, args=tuple()):
202202
procs = []
203203

204204
def tmpfn():
205-
con = env.getConnectionByKey(routing_hint, None)
205+
con = env.getConnectionByKey(routing_hint, 'SET')
206206
fn(con, *args)
207207
return 1
208208

@@ -222,26 +222,26 @@ def load_file_content(file_name):
222222
return f.read()
223223

224224

225-
def check_error_message(env, con, error_msg, *command, error_msg_is_substr=False):
225+
def check_error_message(env, con, error_msg, *command, error_msg_is_substr=False, error_type=redis.exceptions.ResponseError):
226226
try:
227227
con.execute_command(*command)
228228
env.assertFalse(True, message=get_caller_pos())
229229
except Exception as exception:
230-
env.assertEqual(type(exception), redis.exceptions.ResponseError, message=get_caller_pos())
230+
env.assertEqual(type(exception), error_type, message=get_caller_pos())
231231
if error_msg_is_substr:
232232
# We only verify that the given error_msg is a substring of the entire error message.
233233
env.assertTrue(str(exception).find(error_msg) >= 0, message=get_caller_pos())
234234
else:
235235
env.assertEqual(error_msg, str(exception), message=get_caller_pos())
236236

237237

238-
def check_error(env, con, *command):
238+
def check_error(env, con, *command, error_type=redis.exceptions.ResponseError):
239239
try:
240240
con.execute_command(*command)
241241
env.assertFalse(True, message=get_caller_pos())
242242
except Exception as e:
243243
exception = e
244-
env.assertEqual(type(exception), redis.exceptions.ResponseError, message=get_caller_pos())
244+
env.assertTrue(issubclass(type(exception), error_type), message=get_caller_pos())
245245

246246

247247
# Returns a dict with all the fields of a certain section from INFO MODULES command

tests/flow/tests_commands.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ def test_modelexecute_errors(env):
147147

148148
# The following 2 commands should raise an error on cluster mode (keys are not on the same shard)
149149
if env.isCluster():
150-
check_error_message(env, con, "CROSSSLOT Keys in request don't hash to the same slot",
151-
'AI.MODELEXECUTE', 'm{1}', 'INPUTS', 2, 'a{1}', 'b', 'OUTPUTS', 1, 'c{1}')
152-
check_error_message(env, con, "CROSSSLOT Keys in request don't hash to the same slot",
153-
'AI.MODELEXECUTE', 'm{1}', 'INPUTS', 2, 'a{1}', 'b{1}', 'OUTPUTS', 1, 'c')
150+
check_error_message(env, con, "Keys in request don't hash to the same slot",
151+
'AI.MODELEXECUTE', 'm{1}', 'INPUTS', 2, 'a{1}', 'b', 'OUTPUTS', 1, 'c{1}', error_type=redis.exceptions.ClusterCrossSlotError)
152+
check_error_message(env, con, "Keys in request don't hash to the same slot",
153+
'AI.MODELEXECUTE', 'm{1}', 'INPUTS', 2, 'a{1}', 'b{1}', 'OUTPUTS', 1, 'c', error_type=redis.exceptions.ClusterCrossSlotError)
154154

155155

156156
def test_keys_syntax(env):
@@ -319,10 +319,10 @@ def test_pytorch_scriptexecute_errors(env):
319319

320320
if env.isCluster():
321321
# cross shard
322-
check_error_message(env, con, "CROSSSLOT Keys in request don't hash to the same slot", 'AI.SCRIPTEXECUTE', 'ket{1}', 'bar', 'KEYS', 1 , '{2}', 'INPUTS', 2, 'a{1}', 'b{1}', 'OUTPUTS', 1, 'c{1}')
322+
check_error_message(env, con, "Keys in request don't hash to the same slot", 'AI.SCRIPTEXECUTE', 'ket{1}', 'bar', 'KEYS', 1 , '{2}', 'INPUTS', 2, 'a{1}', 'b{1}', 'OUTPUTS', 1, 'c{1}', error_type=redis.exceptions.ClusterCrossSlotError)
323323

324324
# key doesn't exist
325-
check_error_message(env, con, "CROSSSLOT Keys in request don't hash to the same slot", 'AI.SCRIPTEXECUTE', 'ket{1}', 'bar', 'KEYS', 1 , '{1}', 'INPUTS', 2, 'a{1}', 'b{2}', 'OUTPUTS', 1, 'c{1}')
325+
check_error_message(env, con, "Keys in request don't hash to the same slot", 'AI.SCRIPTEXECUTE', 'ket{1}', 'bar', 'KEYS', 1 , '{1}', 'INPUTS', 2, 'a{1}', 'b{2}', 'OUTPUTS', 1, 'c{1}', error_type=redis.exceptions.ClusterCrossSlotError)
326326

327327

328328
def test_pytorch_scriptexecute_variadic_errors(env):

tests/flow/tests_dag_errors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def test_dag_crossslot_violation_errors(env):
213213
'PERSIST', '1', 'resultTensor:{2}', '|>',
214214
'AI.TENSORSET', 'resultTensor:{2}', 'FLOAT', 1, 30,
215215
)
216-
check_error_message(env, con, "CROSSSLOT Keys in request don't hash to the same slot", *command)
216+
check_error_message(env, con, "Keys in request don't hash to the same slot", *command, error_type=redis.exceptions.ClusterCrossSlotError)
217217

218218
# ERR CROSSSLOT violation (model key has a different hash tag than the LOAD and PERSIST tensors)
219219
command = (
@@ -224,7 +224,7 @@ def test_dag_crossslot_violation_errors(env):
224224
'INPUTS', 1, 'transactionTensor:{1}',
225225
'OUTPUTS', 1, 'resultTensor:{1}',
226226
)
227-
check_error_message(env, con, "CROSSSLOT Keys in request don't hash to the same slot", *command)
227+
check_error_message(env, con, "Keys in request don't hash to the same slot", *command, error_type=redis.exceptions.ClusterCrossSlotError)
228228

229229
command = (
230230
'AI.DAGEXECUTE', 'LOAD', '1', 'referenceTensor:{1}',
@@ -235,7 +235,7 @@ def test_dag_crossslot_violation_errors(env):
235235
'INPUTS', 1, 'transactionTensor:{1}',
236236
'OUTPUTS', 1, 'resultTensor:{1}',
237237
)
238-
check_error_message(env, con, "CROSSSLOT Keys in request don't hash to the same slot", *command)
238+
check_error_message(env, con, "Keys in request don't hash to the same slot", *command, error_type=redis.exceptions.ClusterCrossSlotError)
239239

240240

241241
def test_dag_tensorget_tensorset_errors(env):

0 commit comments

Comments
 (0)