Skip to content

Commit

Permalink
fix the test
Browse files Browse the repository at this point in the history
Signed-off-by: liyaojie <[email protected]>
  • Loading branch information
lyj199907 committed Aug 22, 2023
1 parent 41fd5c5 commit 46be8aa
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 118 deletions.
53 changes: 9 additions & 44 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
matrix:
redis-version: [ "2.8", "3.0", "4.0", "5.0", "6.0", "7.0" ]
fail-fast: false
container: ubuntu:latest
steps:
- name: Git checkout
uses: actions/checkout@v2
Expand All @@ -29,29 +30,20 @@ jobs:
mkdir bin
cp src/redis-server bin/redis-server
echo "$GITHUB_WORKSPACE/redis/bin" >> $GITHUB_PATH
ls $GITHUB_WORKSPACE
cat $GITHUB_PATH
cat /etc/ld.so.conf
- name: clone and make TairString Module
if: contains( '5.0, 6.0, 7.0', matrix.redis-version)
run: |
echo "moduleSuppported=true" >> "$GITHUB_ENV"
echo "${{ env.moduleSuppported }}"
cd $GITHUB_WORKSPACE
apt-get install -y cmake
git clone https://github.com/tair-opensource/TairString.git
cd TairString
mkdir build
cd build
cmake ../ && make -j
sudo cp $GITHUB_WORKSPACE/TairString/lib/tairstring_module.so /lib
cp $GITHUB_WORKSPACE/TairString/lib/tairstring_module.so /lib
ls $GITHUB_WORKSPACE
echo "aaaaaaa"
cat $GITHUB_PATH
echo "bbbbbbbbbb"
less /etc/ld.so.conf
- name: clone and make TairHash Module
if: contains( '5.0, 6.0, 7.0', matrix.redis-version)
Expand All @@ -62,14 +54,9 @@ jobs:
mkdir build
cd build
cmake ../ && make -j
sudo cp $GITHUB_WORKSPACE/TairHash/lib/tairhash_module.so /lib
cp $GITHUB_WORKSPACE/TairHash/lib/tairhash_module.so /lib

ls $GITHUB_WORKSPACE
echo "aaaaaaa"
cat $GITHUB_PATH
echo "bbbbbbbbbb"
less /etc/ld.so.conf

- name: clone and make TairZset Module
if: contains( '5.0, 6.0, 7.0', matrix.redis-version)
Expand All @@ -80,14 +67,7 @@ jobs:
mkdir build
cd build
cmake ../ && make -j
sudo cp $GITHUB_WORKSPACE/TairZset/lib/tairzset_module.so /lib

ls $GITHUB_WORKSPACE
echo "aaaaaaa"
cat $GITHUB_PATH
echo "bbbbbbbbbb"
less /etc/ld.so.conf
cp $GITHUB_WORKSPACE/TairZset/lib/tairzset_module.so /lib
- name: Setup Python
Expand All @@ -99,22 +79,7 @@ jobs:
run: |
sh build.sh
- name: test with module supported
if: contains( '5.0, 6.0, 7.0', matrix.redis-version)
run: |
echo "${{ env.moduleSupported }}"
echo "moduleSupported=true" >> "$GITHUB_ENV"
echo "${{ env.moduleSupported }}"
pip3 install -r tests/requirements.txt
sh test.sh
- name: test withnot moduele supported
if: contains( '2.8, 3.0, 4.0', matrix.redis-version)
- name: test
run: |
echo "${{ env.moduleSupported }}"
echo "moduleSupported=false" >> "$GITHUB_ENV"
echo "${{ env.moduleSupported }}"
pip3 install -r tests/requirements.txt
sh test.sh
python -m pip install -r tests/requirements.txt
sh test.sh
6 changes: 5 additions & 1 deletion tests/cases/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import helpers as h

import time


def test(src, dst):
cross_slots_cmd = not (src.is_cluster() or dst.is_cluster())
Expand All @@ -20,8 +22,10 @@ def test(src, dst):
# add data again
inserter.add_data(src, cross_slots_cmd=cross_slots_cmd)

# time.sleep(20)

# wait sync done
p.ASSERT_TRUE_TIMEOUT(lambda: shake.is_consistent())
p.ASSERT_TRUE_TIMEOUT(lambda: shake.is_consistent(), timeout=20)
p.log(shake.get_status())

# check data
Expand Down
19 changes: 15 additions & 4 deletions tests/helpers/data_inserter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from helpers.commands import SelectChecker, StringChecker, TairStringChecker, TairHashChecker, TairZsetChecker
from helpers.redis import Redis
from helpers.constant import PATH_REDIS_SERVER, REDIS_SERVER_VERSION


class DataInserter:
Expand All @@ -13,9 +14,19 @@ def __init__(self, ):
]

def add_data(self, r: Redis, cross_slots_cmd: bool):
for checker in self.checkers:
checker.add_data(r, cross_slots_cmd)
if REDIS_SERVER_VERSION > 4.0:
for checker in self.checkers:
checker.add_data(r, cross_slots_cmd)
else:
self.checkers[0].add_data(r, cross_slots_cmd)
self.checkers[1].add_data(r, cross_slots_cmd)


def check_data(self, r: Redis, cross_slots_cmd: bool):
for checker in self.checkers:
checker.check_data(r, cross_slots_cmd)
if REDIS_SERVER_VERSION > 4.0:
for checker in self.checkers:
checker.check_data(r, cross_slots_cmd)
else:
self.checkers[0].add_data(r, cross_slots_cmd)
self.checkers[1].add_data(r, cross_slots_cmd)

72 changes: 3 additions & 69 deletions tests/helpers/redis.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import time
import os

import pybbt
import redis
Expand All @@ -19,66 +18,20 @@ def __init__(self, args=None):
self.dir = f"{self.case_ctx.dir}/redis_{self.port}"
args.extend(["--port", str(self.port)])


# v1
# print(os.environ.get("moduleSupported"))
# print(os.getenv("moduleSupported"))
# env_file = os.getenv('GITHUB_ENV')
# with open(env_file, "a") as myfile:
# print(myfile.read())
# if os.getenv("modulesupported"):
# args.extend(["--loadmodule", "tairstring_module.so"])
# args.extend(["--loadmodule", "tairhash_module.so"])
# args.extend(["--loadmodule", "tairzset_module.so"])
# self.server = pybbt.Launcher(args=[PATH_REDIS_SERVER] + args, work_dir=self.dir)
# else:
# self.server = pybbt.Launcher(args=[PATH_REDIS_SERVER] + args, work_dir=self.dir)


# v2
# print(os.environ.get("GITHUB_ENV"))
# github_env_path = os.environ.get("GITHUB_ENV")
# github_env_vars = read_github_env(github_env_path)
# my_variable_value = github_env_vars.get('moduleSupported')
# print(my_variable_value)


# v3
# print(os.getenv('GITHUB_ENV'))
# env_file = os.getenv('GITHUB_ENV')
# with open(env_file, 'r') as myfile:
# print(myfile.read())


# v4 完善
print(os.getenv('GITHUB_ENV'))
env_file = os.getenv('GITHUB_ENV')
envs = read_github_env(env_file)
moduleSupported = envs['moduleSupported']
print(moduleSupported)


if (moduleSupported == 'true'):
if REDIS_SERVER_VERSION > 4.0:
args.extend(["--loadmodule", "tairstring_module.so"])
args.extend(["--loadmodule", "tairhash_module.so"])
args.extend(["--loadmodule", "tairzset_module.so"])
self.server = pybbt.Launcher(args=[PATH_REDIS_SERVER] + args, work_dir=self.dir)
else:
self.server = pybbt.Launcher(args=[PATH_REDIS_SERVER] + args, work_dir=self.dir)



args.extend(["--loadmodule", "tairstring_module.so"])
args.extend(["--loadmodule", "tairhash_module.so"])
args.extend(["--loadmodule", "tairzset_module.so"])
self.server = pybbt.Launcher(args=[PATH_REDIS_SERVER] + args, work_dir=self.dir)

self._wait_start()
self.client = redis.Redis(host=self.host, port=self.port)
self.case_ctx.add_exit_hook(lambda: self.server.stop())
pybbt.log_yellow(f"redis server started at {self.host}:{self.port}, redis-cli -p {self.port}")

def _wait_start(self, timeout=10):
def _wait_start(self, timeout=5):
timer = Timer()
while True:
try:
Expand Down Expand Up @@ -113,23 +66,4 @@ def is_cluster(self):
return self.client.info()["cluster_enabled"]

def dbsize(self):
return self.client.dbsize()





def read_github_env(env_path):
# env_vars = {}
# with open(env_path, 'r') as env_file:
# for line in env_file:
# key, value = line.strip().split('=')
# env_vars[key] = value
# return env_vars
with open(env_path, 'r') as file:
lines = file.readlines()
key_value_pairs = {}
for line in lines:
key, value = line.strip().split('=')
key_value_pairs[key.strip()] = value.strip()
return key_value_pairs
return self.client.dbsize()

0 comments on commit 46be8aa

Please sign in to comment.