Skip to content

Commit 1de881c

Browse files
authored
MOD-5943: Fix mget test failures with redis unstable (RedisJSON#1110)
* mget tests: put all keys on the same shard * Fix test.py:testMgetCommand
1 parent d4ba815 commit 1de881c

File tree

3 files changed

+31
-30
lines changed

3 files changed

+31
-30
lines changed

tests/pytest/test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,36 +380,36 @@ def testMgetCommand(env):
380380

381381
# Set up a few keys
382382
for d in range(0, 5):
383-
key = 'doc:{}'.format(d)
383+
key = '{{doc}}:{}'.format(d)
384384
r.cmd('DEL', key)
385385
r.expect('JSON.SET', key, '.', json.dumps(docs['basic'])).ok()
386386

387387
# Test an MGET that succeeds on all keys
388-
raw = r.execute_command('JSON.MGET', *['doc:{}'.format(d) for d in range(0, 5)] + ['.'])
388+
raw = r.execute_command('JSON.MGET', *['{{doc}}:{}'.format(d) for d in range(0, 5)] + ['.'])
389389
r.assertEqual(len(raw), 5)
390390
for d in range(0, 5):
391-
key = 'doc:{}'.format(d)
391+
key = '{{doc}}:{}'.format(d)
392392
r.assertEqual(json.loads(raw[d]), docs['basic'], d)
393393

394394
# Test an MGET that fails for one key
395395
r.cmd('DEL', 'test')
396-
r.assertOk(r.execute_command('JSON.SET', 'test', '.', '{"bool":false}'))
397-
raw = r.execute_command('JSON.MGET', 'test', 'doc:0', 'foo', '.bool')
396+
r.assertOk(r.execute_command('JSON.SET', '{doc}:test', '.', '{"bool":false}'))
397+
raw = r.execute_command('JSON.MGET', '{doc}:test', '{doc}:0', '{doc}:foo', '.bool')
398398
r.assertEqual(len(raw), 3)
399399
r.assertFalse(json.loads(raw[0]))
400400
r.assertTrue(json.loads(raw[1]))
401401
r.assertEqual(raw[2], None)
402402

403403
# Test that MGET on missing path
404-
raw = r.execute_command('JSON.MGET', 'doc:0', 'doc:1', '42isnotapath')
404+
raw = r.execute_command('JSON.MGET', '{doc}:0', '{doc}:1', '42isnotapath')
405405
r.assertEqual(len(raw), 2)
406406
r.assertEqual(raw[0], None)
407407
r.assertEqual(raw[1], None)
408408

409409
# Test that MGET fails on path errors
410410
r.cmd('DEL', 'test')
411411
r.assertOk(r.execute_command('JSON.SET', 'test', '.', '{"bull":4.2}'))
412-
raw = r.execute_command('JSON.MGET', 'doc:0', 'test', 'doc:1', '.bool')
412+
raw = r.execute_command('JSON.MGET', '{doc}:0', 'test', '{doc}:1', '.bool')
413413
r.assertEqual(len(raw), 3)
414414
r.assertTrue(json.loads(raw[0]))
415415
r.assertEqual(raw[1], None)

tests/pytest/test_multi.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -233,55 +233,56 @@ def testMGetCommand(env):
233233
"""Test REJSON.MGET command"""
234234
r = env
235235
# Test mget with multi paths
236-
r.assertOk(r.execute_command('JSON.SET', 'doc1', '$', '{"a":1, "b": 2, "nested1": {"a": 3}, "c": null, "nested2": {"a": null}}'))
237-
r.assertOk(r.execute_command('JSON.SET', 'doc2', '$', '{"a":4, "b": 5, "nested3": {"a": 6}, "c": null, "nested4": {"a": [null]}}'))
236+
r.assertOk(r.execute_command('JSON.SET', '{doc}:1', '$', '{"a":1, "b": 2, "nested1": {"a": 3}, "c": null, "nested2": {"a": null}}'))
237+
r.assertOk(r.execute_command('JSON.SET', '{doc}:2', '$', '{"a":4, "b": 5, "nested3": {"a": 6}, "c": null, "nested4": {"a": [null]}}'))
238238
# Compare also to single JSON.GET
239-
res1 = r.execute_command('JSON.GET', 'doc1', '$..a')
240-
res2 = r.execute_command('JSON.GET', 'doc2', '$..a')
239+
res1 = r.execute_command('JSON.GET', '{doc}:1', '$..a')
240+
res2 = r.execute_command('JSON.GET', '{doc}:2', '$..a')
241241
r.assertEqual(res1, '[1,3,null]')
242242
r.assertEqual(res2, '[4,6,[null]]')
243243

244-
r.assertTrue(r.execute_command('SET', 'wrong_key_type', 'not a json key'))
244+
r.assertTrue(r.execute_command('SET', '{doc}:wrong_key_type', 'not a json key'))
245245

246246
# Test mget with single path
247-
res = r.execute_command('JSON.MGET', 'doc1', '$..a')
247+
res = r.execute_command('JSON.MGET', '{doc}:1', '$..a')
248248
r.assertEqual([res1], res)
249+
249250
# Test mget with multi path
250-
res = r.execute_command('JSON.MGET', 'doc1', 'wrong_key_type', 'doc2', '$..a')
251+
res = r.execute_command('JSON.MGET', '{doc}:1', '{doc}:wrong_key_type', '{doc}:2', '$..a')
251252
r.assertEqual(res, [res1, None, res2])
252253

253254
# Test missing/wrong key / missing path
254-
res = r.execute_command('JSON.MGET', 'doc1', 'missing_doc', '$..a')
255+
res = r.execute_command('JSON.MGET', '{doc}:1', '{doc}:missing', '$..a')
255256
r.assertEqual(res, [res1, None])
256-
res = r.execute_command('JSON.MGET', 'doc1', 'doc2', 'wrong_key_type', 'missing_doc', '$.nested1.a')
257+
res = r.execute_command('JSON.MGET', '{doc}:1', '{doc}:2', '{doc}:wrong_key_type', '{doc}:missing', '$.nested1.a')
257258
r.assertEqual(res, [json.dumps([json.loads(res1)[1]]), '[]', None, None])
258-
res = r.execute_command('JSON.MGET', 'missing_doc1', 'missing_doc2', '$..a')
259+
res = r.execute_command('JSON.MGET', '{doc}:missing1', '{doc}:missing2', '$..a')
259260
r.assertEqual(res, [None, None])
260261

261262
# Test missing path
262-
res = r.execute_command('JSON.MGET', 'doc1', 'wrong_key_type', 'missing_doc2', '$..niente')
263+
res = r.execute_command('JSON.MGET', '{doc}:1', '{doc}:wrong_key_type', '{doc}:missing2', '$..niente')
263264
r.assertEqual(res, ['[]', None, None])
264265

265266
# Test legacy (for each path only the first value is returned as a json string)
266267
# Test mget with single path
267-
res = r.execute_command('JSON.MGET', 'doc1', '..a')
268+
res = r.execute_command('JSON.MGET', '{doc}:1', '..a')
268269
r.assertEqual(res, [json.dumps(json.loads(res1)[0])])
269270
# Test mget with multi path
270-
res = r.execute_command('JSON.MGET', 'doc1', 'doc2', '..a')
271+
res = r.execute_command('JSON.MGET', '{doc}:1', '{doc}:2', '..a')
271272
r.assertEqual(res, [json.dumps(json.loads(res1)[0]), json.dumps(json.loads(res2)[0])])
272273

273274
# Test wrong key
274-
res = r.execute_command('JSON.MGET', 'doc1', 'wrong_key_type', 'doc2', '..a')
275+
res = r.execute_command('JSON.MGET', '{doc}:1', '{doc}:wrong_key_type', '{doc}:2', '..a')
275276
r.assertEqual(res, [json.dumps(json.loads(res1)[0]), None, json.dumps(json.loads(res2)[0])])
276277

277278
# Test missing key/path
278-
res = r.execute_command('JSON.MGET', 'doc1', 'doc2', 'wrong_key_type', 'missing_doc', '.nested1.a')
279+
res = r.execute_command('JSON.MGET', '{doc}:1', '{doc}:2', '{doc}:wrong_key_type', '{doc}:missing', '.nested1.a')
279280
r.assertEqual(res, [json.dumps(json.loads(res1)[1]), None, None, None])
280-
res = r.execute_command('JSON.MGET', 'missing_doc1', 'missing_doc2', '..a')
281+
res = r.execute_command('JSON.MGET', '{doc}:missing1', '{doc}:missing2', '..a')
281282
r.assertEqual(res, [None, None])
282283

283284
# Test missing path
284-
res = r.execute_command('JSON.MGET', 'doc1', 'wrong_key_type', 'missing_doc2', '.niente')
285+
res = r.execute_command('JSON.MGET', '{doc}:1', '{doc}:wrong_key_type', '{doc}:missing2', '.niente')
285286
r.assertEqual(res, [None, None, None])
286287

287288

tests/pytest/test_resp3.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,14 @@ def test_resp_json_mget(self):
304304
r = self.env
305305
r.skipOnVersionSmaller('7.0')
306306

307-
r.assertTrue(r.execute_command('JSON.SET', 'test_resp3_1', '$', '{"a":1, "b":{"f":"g"}, "c":3}'))
308-
r.assertTrue(r.execute_command('JSON.SET', 'test_resp3_2', '$', '{"a":5, "b":[true, 3, null], "d":7}'))
307+
r.assertTrue(r.execute_command('JSON.SET', '{test}resp3_1', '$', '{"a":1, "b":{"f":"g"}, "c":3}'))
308+
r.assertTrue(r.execute_command('JSON.SET', '{test}resp3_2', '$', '{"a":5, "b":[true, 3, null], "d":7}'))
309309

310310
# Test JSON.MGET RESP3 with default FORMAT STRING
311-
r.assertEqual(list(map(lambda x:json.loads(x) if x else None, r.execute_command('JSON.MGET', 'test_resp3_1', 'test_resp3_2', '$.not'))), [[], []])
312-
r.assertEqual(list(map(lambda x:json.loads(x) if x else None, r.execute_command('JSON.MGET', 'test_resp3_1', 'test_resp3_2', 'test_not_JSON', '$.b'))), [[{'f': 'g'}], [[True, 3, None]], None])
313-
r.assertEqual(list(map(lambda x:json.loads(x), r.execute_command('JSON.MGET', 'test_resp3_1', 'test_resp3_2', '$'))), [[{'a': 1, 'b': {'f': 'g'}, 'c': 3}], [{'b': [True, 3, None], 'd': 7, 'a': 5}]])
314-
r.assertEqual(list(map(lambda x:json.loads(x), r.execute_command('JSON.MGET', 'test_resp3_1', 'test_resp3_2', '$..*'))), [[1, {'f': 'g'}, 3, 'g'], [5, [True, 3, None], 7, True, 3, None]])
311+
r.assertEqual(list(map(lambda x:json.loads(x) if x else None, r.execute_command('JSON.MGET', '{test}resp3_1', '{test}resp3_2', '$.not'))), [[], []])
312+
r.assertEqual(list(map(lambda x:json.loads(x) if x else None, r.execute_command('JSON.MGET', '{test}resp3_1', '{test}resp3_2', '{test}not_JSON', '$.b'))), [[{'f': 'g'}], [[True, 3, None]], None])
313+
r.assertEqual(list(map(lambda x:json.loads(x), r.execute_command('JSON.MGET', '{test}resp3_1', '{test}resp3_2', '$'))), [[{'a': 1, 'b': {'f': 'g'}, 'c': 3}], [{'b': [True, 3, None], 'd': 7, 'a': 5}]])
314+
r.assertEqual(list(map(lambda x:json.loads(x), r.execute_command('JSON.MGET', '{test}resp3_1', '{test}resp3_2', '$..*'))), [[1, {'f': 'g'}, 3, 'g'], [5, [True, 3, None], 7, True, 3, None]])
315315

316316
# Test different commands with RESP3 when default path is used
317317
def test_resp_default_path(self):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy