From 46be8aac76f11d374e728d81d9f2f6f9ac5d3b76 Mon Sep 17 00:00:00 2001 From: liyaojie Date: Mon, 21 Aug 2023 18:14:30 +0800 Subject: [PATCH] fix the test Signed-off-by: liyaojie --- .github/workflows/ci.yml | 53 +++++-------------------- tests/cases/sync.py | 6 ++- tests/helpers/data_inserter.py | 19 +++++++-- tests/helpers/redis.py | 72 ++-------------------------------- 4 files changed, 32 insertions(+), 118 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c1b3be3c..8c98d5db 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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) @@ -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) @@ -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 @@ -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 \ No newline at end of file diff --git a/tests/cases/sync.py b/tests/cases/sync.py index dfd4f41f..fc27fde0 100644 --- a/tests/cases/sync.py +++ b/tests/cases/sync.py @@ -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()) @@ -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 diff --git a/tests/helpers/data_inserter.py b/tests/helpers/data_inserter.py index 590d0099..10104ba6 100644 --- a/tests/helpers/data_inserter.py +++ b/tests/helpers/data_inserter.py @@ -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: @@ -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) + diff --git a/tests/helpers/redis.py b/tests/helpers/redis.py index 2f404d6b..b90cf7b9 100644 --- a/tests/helpers/redis.py +++ b/tests/helpers/redis.py @@ -1,5 +1,4 @@ import time -import os import pybbt import redis @@ -19,46 +18,7 @@ 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"]) @@ -66,19 +26,12 @@ def __init__(self, args=None): 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: @@ -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 \ No newline at end of file + return self.client.dbsize() \ No newline at end of file