Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ jobs:
- setup-automation
- run:
name: Run QA Automation
command: MODULE_VERSION=$CIRCLE_TAG VERBOSE=1 TEST=release ./tests/qa/run
command: ./tests/qa/qatests -v -t release -m "$CIRCLE_TAG"

nightly-automation:
docker:
Expand All @@ -305,7 +305,7 @@ jobs:
- setup-automation
- run:
name: Run QA Automation
command: MODULE_VERSION=$CIRCLE_BRANCH VERBOSE=1 TEST=nightly QUICK=1 ./tests/qa/run
command: ./tests/qa/qatests -v -t nightly -m "$CIRCLE_BRANCH" --snapshot --quick

performance-automation:
docker:
Expand Down
10 changes: 5 additions & 5 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ pub fn command_json_str_len<M: Manager>(
) -> RedisResult {
let mut args = args.into_iter().skip(1);
let key = args.next_arg()?;
let path = Path::new(args.next_str()?);
let path = Path::new(args.next_str().unwrap_or(JSON_ROOT_PATH_LEGACY));

let key = manager.open_key_read(ctx, &key)?;

Expand Down Expand Up @@ -1449,7 +1449,7 @@ pub fn command_json_arr_len<M: Manager>(
) -> RedisResult {
let mut args = args.into_iter().skip(1);
let key = args.next_arg()?;
let path = Path::new(args.next_str()?);
let path = Path::new(args.next_str().unwrap_or(JSON_ROOT_PATH_LEGACY));
let is_legacy = path.is_legacy();
let key = manager.open_key_read(ctx, &key)?;
let root = match key.get_value()? {
Expand Down Expand Up @@ -1666,7 +1666,7 @@ pub fn command_json_obj_keys<M: Manager>(
) -> RedisResult {
let mut args = args.into_iter().skip(1);
let key = args.next_arg()?;
let path = Path::new(args.next_str()?);
let path = Path::new(args.next_str().unwrap_or(JSON_ROOT_PATH_LEGACY));

let mut key = manager.open_key_read(ctx, &key)?;
if !path.is_legacy() {
Expand Down Expand Up @@ -1720,7 +1720,7 @@ pub fn command_json_obj_len<M: Manager>(
) -> RedisResult {
let mut args = args.into_iter().skip(1);
let key = args.next_arg()?;
let path = Path::new(args.next_str()?);
let path = Path::new(args.next_str().unwrap_or(JSON_ROOT_PATH_LEGACY));

let key = manager.open_key_read(ctx, &key)?;
if !path.is_legacy() {
Expand Down Expand Up @@ -1858,7 +1858,7 @@ pub fn command_json_resp<M: Manager>(

let key = args.next_arg()?;
let path = match args.next() {
None => Path::new(JSON_ROOT_PATH),
None => Path::new(JSON_ROOT_PATH_LEGACY),
Some(s) => Path::new(s.try_as_str()?),
};

Expand Down
50 changes: 47 additions & 3 deletions tests/pytest/test_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ def testForgetCommand(env):

def testSetAndGetCommands(env):
"""Test REJSON.SET command"""
"""Test REJSON.GET command"""

r = env
# Test set and get on large nested key
r.assertIsNone(r.execute_command('JSON.SET', 'doc1', '$', nested_large_key, 'XX'))
Expand Down Expand Up @@ -154,6 +156,12 @@ def testSetAndGetCommands(env):
r.expect('JSON.GET', 'doc2', '.a', '.nested.b', '.back_in_nov', '.ttyl').raiseError()
r.expect('JSON.GET', 'doc2', '.back_in_nov').raiseError()

# Test missing path (defaults to root)
r.assertOk(r.execute_command('JSON.SET', 'doc1', '$', '"inizio"'))
res = r.execute_command('JSON.GET', 'doc1')
r.assertEqual(res, '"inizio"')



def testMGetCommand(env):
"""Test REJSON.MGET command"""
Expand Down Expand Up @@ -310,8 +318,10 @@ def testStrAppendCommand(env):
res = r.execute_command('JSON.GET', 'doc1', '$')
r.assertEqual(res, '[{"a":"foo","nested1":{"a":"hellobar"},"nested2":{"a":31}}]')

# Test missing path
r.expect('JSON.STRAPPEND', 'doc1', '"piu"').raiseError()
# Test missing path (defaults to root)
r.assertOk(r.execute_command('JSON.SET', 'doc1', '$', '"abcd"'))
res = r.execute_command('JSON.STRAPPEND', 'doc1', '"piu"')
r.assertEqual(res, 7)


def testStrLenCommand(env):
Expand Down Expand Up @@ -342,6 +352,11 @@ def testStrLenCommand(env):
res1 = r.execute_command('JSON.STRLEN', 'doc1', '..a')
r.assertEqual(res1, 6)

# Test missing path
r.assertOk(r.execute_command('JSON.SET', 'doc1', '$', '"kantele"'))
res = r.execute_command('JSON.STRLEN', 'doc1')
r.assertEqual(res, 7)


def testArrAppendCommand(env):
"""
Expand Down Expand Up @@ -455,6 +470,11 @@ def testArrLenCommand(env):
# Test missing key
r.assertEqual(r.execute_command('JSON.ARRLEN', 'non_existing_doc', '..a'), None)

# Test missing path (defaults to root)
r.assertOk(r.execute_command('JSON.SET', 'doc1', '$', '[0, 1, 2, 3, 4]'))
res = r.execute_command('JSON.ARRLEN', 'doc1')
r.assertEqual(res, 5)

def testArrPopCommand(env):
"""
Test REJSON.ARRPOP command
Expand Down Expand Up @@ -489,14 +509,25 @@ def testArrPopCommand(env):
res = r.execute_command('JSON.GET', 'doc1', '$')
r.assertEqual(json.loads(res), [{"a": [], "nested1": {"a": ["hello", "world"]}, "nested2": {"a": 31}}])
# Test single
res = r.execute_command('JSON.ARRPOP', 'doc1', '.nested1.a', -2, '"baz"')
res = r.execute_command('JSON.ARRPOP', 'doc1', '.nested1.a', -2)
r.assertEqual(res, '"hello"')
res = r.execute_command('JSON.GET', 'doc1', '$')
r.assertEqual(json.loads(res), [{"a": [], "nested1": {"a": ["world"]}, "nested2": {"a": 31}}])

# Test missing key
r.expect('JSON.ARRPOP', 'non_existing_doc', '..a').raiseError()

# Test default path/index
r.assertOk(r.execute_command('JSON.SET', 'doc1', '$', '[0, 1, 2]'))
res = r.execute_command('JSON.ARRPOP', 'doc1')
r.assertEqual(res, '2')
res = r.execute_command('JSON.ARRPOP', 'doc1', '$')
r.assertEqual(res, ['1'])
res = r.execute_command('JSON.ARRPOP', 'doc1', '.')
r.assertEqual(res, '0')



def testArrTrimCommand(env):
"""
Test REJSON.ARRTRIM command
Expand Down Expand Up @@ -565,6 +596,10 @@ def testObjKeysCommand(env):
# Test missing key
r.expect('JSON.OBJKEYS', 'doc1', '$.nowhere').raiseError()

# Test default path
res = r.execute_command('JSON.OBJKEYS', 'doc1')
r.assertEqual(res, ["nested1", "a", "nested2"])


def testObjLenCommand(env):
"""Test JSON.OBJLEN command"""
Expand Down Expand Up @@ -600,6 +635,10 @@ def testObjLenCommand(env):
# Test missing path
r.expect('JSON.OBJLEN', 'doc1', '.nowhere').raiseError()

# Test default path
res = r.execute_command('JSON.OBJLEN', 'doc1')
r.assertEqual(res, 3)


def load_types_data(nested_key_name):
types_data = {
Expand Down Expand Up @@ -781,6 +820,11 @@ def testRespCommand(env):
res = r.execute_command('JSON.RESP', 'doc1', '.L1.a')
r.assertEqual([res], resSingle)

# Test default path
r.assertOk(r.execute_command('JSON.SET', 'doc1', '$', '[[1],[2]]'))
res = r.execute_command('JSON.RESP', 'doc1')
r.assertEqual(res, ['[', ['[', 1], ['[', 2]])

def testArrIndexCommand(env):
"""Test JSON.ARRINDEX command"""
r = env
Expand Down
7 changes: 4 additions & 3 deletions tests/qa/RS_VERSIONS
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
6.0.20-69
6.0.6-39
6.2.4-54
6.0.8-32
6.0.12-58
100.0.0-2199
6.0.20-101
6.2.8-36
100.0.0-2602
185 changes: 185 additions & 0 deletions tests/qa/qatests
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
#!/bin/sh
''''[ ! -z $VIRTUAL_ENV ] && exec python -u -- "$0" ${1+"$@"}; command -v python3 > /dev/null && exec python3 -u -- "$0" ${1+"$@"}; exec python2 -u -- "$0" ${1+"$@"} # '''

import sys
import os
import click
import re
import json
import requests

HERE = os.path.dirname(__file__)
ROOT = os.path.abspath(os.path.join(HERE, ".."))
READIES = "/w/rafi_1/readies"
sys.path.insert(0, READIES)
import paella

VERBOSE = 0
NOP = False
OPERETO3_URL = "opereto.qa.redislabs.com"

RS_PLATFORMS = {
'xenial': {
'platform': 'Linux-ubuntu16.04',
'env': 'xenial-amd64-aws' },
'bionic': {
'platform': 'Linux-ubuntu18.04',
'env': 'bionic-amd64-aws' },
'cenos7': {
'platform': 'Linux-rhel7',
'env': 'rhel7.7-amd64-aws' },
'cenos8': {
'platform': 'Linux-rhel8',
'env': 'rhel8.3-amd64-aws' }
}


class Command1(click.Command):
def header(self):
return r'''
█████ █████
░░███ ░░███
████████ ██████ ███████ ██████ █████ ███████ █████
███░░███ ░░░░░███ ░░░███░ ███░░███ ███░░ ░░░███░ ███░░
░███ ░███ ███████ ░███ ░███████ ░░█████ ░███ ░░█████
░███ ░███ ███░░███ ░███ ███░███░░░ ░░░░███ ░███ ███ ░░░░███
░░███████ ░░████████ ░░█████ ░░██████ ██████ ░░█████ ██████
░░░░░███ ░░░░░░░░ ░░░░░ ░░░░░░ ░░░░░░ ░░░░░ ░░░░░░
░███
█████
░░░░░

'''

def footer(self):
return '''

Other configuration:
RS_VERSIONS file includes Redis Enterprive versions for release tests.

'''

def get_help(self, ctx):
h = super().get_help(ctx)
return self.header() + h + self.footer()


class Test:
def __init__(self, token, test_fname, modver, snapshot, rsver, osnick, light):
global NOP, VERBOSE

self.token = token
self.test_fname = test_fname
self.modver = re.sub(r'^v(.*)', r'\1', modver)
self.snapshot = snapshot
self.rsver = rsver
self.osnick = osnick
self.light = light

os.environ['RS_MODULE_DIR'] = 'rejson'
self.rsmod = 'ReJSON'
ENV['RS_MODULE_FILE_PREFIX'] = 'rejson'
if snapshot:
ENV['RS_MODULE_FILE_PREFIX'] = "snapshots/" + ENV['RS_MODULE_FILE_PREFIX']

ENV['RS_MODULE'] = self.rsmod
ENV['MODULE_VERSION'] = modver
ENV['RS_VERSION'] = rsver

self.xtx_vars = ['RS_MODULE', 'RS_MODULE_DIR', 'RS_MODULE_FILE_PREFIX',
'RS_VERSION', 'RS_ENV', 'RS_MODULE_OS',
'MODULE_VERSION']

def run(self):
for osnick in RS_PLATFORMS.keys():
if self.osnick is None or osnick == self.osnick:
rs_platform = RS_PLATFORMS[osnick]['platform']
rs_env = RS_PLATFORMS[osnick]['env']
self.run_for_os(rs_platform, rs_env)

def run_for_os(self, rs_mod_os, rs_env):
ENV['RS_ENV'] = rs_env
ENV['RS_MODULE_OS'] = rs_mod_os

desc = f"{self.rsmod}/{self.modver}/{rs_mod_os} for RS {self.rsver}"
click.echo(f"Testing {desc}")

global NOP, VERBOSE
var_args = ' '.join(map(lambda v: f"-e {v}", self.xtx_vars))

try:
if VERBOSE > 1:
print(f'{READIES}/bin/xtx {var_args} {self.test_fname}')

rest = sh(f'{READIES}/bin/xtx --strict {var_args} {self.test_fname}')
except Exception as x:
fatal(x)

try:
rest_json = json.loads(rest)
if VERBOSE > 0:
print(json.dumps(rest_json, indent=2))
except Exception as x:
print(rest)
fatal(x)

if NOP:
return 0

BB()
res = requests.post(f"https://{OPERETO3_URL}/processes", verify=False,
headers={'Authorization': f'Bearer {self.token}',
'Content-Type': 'application/json'},
data=rest)
if not res.ok:
click.echo(f"Failed to run tests on {desc}: {res.reason} [{res.status_code}]")
return 1
j = json.loads(res.content)
if j['status'] != 'success':
err = j['text']
click.echo(f"Failed to run tests on {desc}: {err}")
return 1

self.id = j['data'][0]
click.echo(f"Tests running on {desc}")
click.echo(f"Results: https://{OPERETO3_URL}/ui#dashboard/flow/{self.id}")
return 0


@click.command(help='Invoke QA Automation tests', cls=Command1)
@click.option('--token', default=None, help='QA automation (Opereto) token (also: QA_AUTOMATION_TOKEN env var)')
@click.option('--test', '-t', default='release', help='Name of .json parameters file')
@click.option('--modver', '-m', default='master', help='Module version to test. Default: master')
@click.option('--snapshot', '-s', is_flag=True, default=False, help='Test a snapshoy module version')
@click.option('--rsver', default=None, help='Test for a RS version`')
@click.option('--osnick', default=None, help='Test for OSNICK`')
@click.option('--quick', is_flag=True, default=False, help='Only test one RS version')
@click.option('--nop', is_flag=True, default=False, help='Dry run')
@click.option('--verbose', '-v', is_flag=True, default=False, help='Be verbose')
@click.option('--verbosity', type=int, default=0, help='Verbosity level')
def main(token, test, modver, snapshot, rsver, osnick, light, quick, nop, verbose, verbosity, *args, **kwargs):
BB()
global NOP, VERBOSE
VERBOSE = 1 if verbose else verbosity
NOP = nop

if token is None:
token = os.getenv('QA_AUTOMATION_TOKEN')
if token is None and not nop:
raise click.ClickException('QA automation token is missing.')
test_fname = os.path.join(HERE, f'{test}.json')
if not os.path.exists(test_fname):
raise click.ClickException(f"Invalid test name: {test}")

if rsver is not None:
Test(token, test_fname, modver, snapshot, rsver, osnick, light).run()
else:
rs_versions = paella.flines(os.path.join(HERE, 'RS_VERSIONS'))
if quick:
rs_versions = [rs_versions[0]]
for rsver in rs_versions:
Test(token, test_fname, modver, snapshot, rsver, osnick, light).run()


if __name__ == '__main__':
main()