Skip to content

Commit 512da9a

Browse files
Avoid RDB usage on unit tests (#145)
* Avoid RDB usage on unit tests * fixed GH_TOKEN bad argument passing on new test * Don't fail-fast on matrix of tests
1 parent 9fce8d8 commit 512da9a

File tree

9 files changed

+131
-105
lines changed

9 files changed

+131
-105
lines changed

.github/workflows/tox.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
jobs:
99
pytest:
1010
strategy:
11+
fail-fast: false
1112
matrix:
1213
python-version: [ '3.8', '3.9', '3.10' ]
1314
env:
@@ -38,7 +39,7 @@ jobs:
3839
3940
- name: Run tox
4041
run: |
41-
TST_RUNNER_USE_RDB=0 tox
42+
tox
4243
4344
- name: Upload coverage to Codecov
4445
uses: codecov/codecov-action@v2

redis_benchmarks_specification/__builder__/builder.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,13 @@ def builder_process_stream(
329329
bin_artifact = open(
330330
"{}src/{}".format(redis_temporary_dir, artifact), "rb"
331331
).read()
332+
bin_artifact_len = len(bytes(bin_artifact))
333+
assert bin_artifact_len > 0
332334
conn.set(bin_key, bytes(bin_artifact), ex=REDIS_BINS_EXPIRE_SECS)
333335
build_stream_fields[artifact] = bin_key
334-
build_stream_fields["{}_len_bytes".format(artifact)] = len(
335-
bytes(bin_artifact)
336-
)
336+
build_stream_fields[
337+
"{}_len_bytes".format(artifact)
338+
] = bin_artifact_len
337339
result = True
338340
if result is True:
339341
stream_id = conn.xadd(

redis_benchmarks_specification/__common__/builder_schema.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ def commit_schema_to_stream(
4141
binary_key,
4242
binary_value,
4343
) = get_commit_dict_from_sha(
44-
fields["git_hash"], gh_org, gh_repo, fields, use_git_timestamp, gh_token
44+
fields["git_hash"],
45+
gh_org,
46+
gh_repo,
47+
fields,
48+
use_git_timestamp,
49+
gh_token,
4550
)
4651
reply_fields["use_git_timestamp"] = fields["use_git_timestamp"]
4752
if "git_timestamp_ms" in fields:
@@ -66,6 +71,7 @@ def get_archive_zip_from_hash(gh_org, gh_repo, git_hash, fields):
6671
gh_org, gh_repo, git_hash
6772
)
6873
try:
74+
logging.info("Fetching data from {}".format(github_url))
6975
response = urlopen(github_url, timeout=5)
7076
content = response.read()
7177
fields["zip_archive_key"] = bin_key
@@ -78,6 +84,7 @@ def get_archive_zip_from_hash(gh_org, gh_repo, git_hash, fields):
7884
)
7985
logging.error(error_msg)
8086
result = False
87+
8188
return result, bin_key, binary_value, error_msg
8289

8390

@@ -107,7 +114,10 @@ def get_commit_dict_from_sha(
107114
commit_dict["git_branch"] = gh_branch
108115

109116
result, binary_key, binary_value, error_msg = get_archive_zip_from_hash(
110-
gh_org, gh_repo, git_hash, commit_dict
117+
gh_org,
118+
gh_repo,
119+
git_hash,
120+
commit_dict,
111121
)
112122
return result, error_msg, commit_dict, commit, binary_key, binary_value
113123

tox.ini

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ basepython = python3
99

1010
[testenv:integration-tests]
1111
deps = -r{toxinidir}/dev_requirements.txt
12-
passenv = TST_BUILDER_X TST_RUNNER_X TST_RUNNER_USE_RDB GH_TOKEN TST_REDIS_DIR
12+
passenv = TST_BUILDER_X TST_RUNNER_X GH_TOKEN TST_REDIS_DIR
1313

1414
commands =
1515
black --check redis_benchmarks_specification
@@ -26,9 +26,6 @@ docker =
2626
image = redis/redis-stack-server:7.0.2-RC4
2727
ports =
2828
16379:6379/tcp
29-
volumes =
30-
bind:rw:{toxinidir}/utils/tests/test_data/:/data
31-
3229

3330
[docker:db_server]
3431
image = redis/redis-stack-server:7.0.2-RC4

utils/tests/test_builder.py

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,27 @@ def test_build_spec_image_prefetch():
3939

4040
def test_commit_schema_to_stream_then_build():
4141
try:
42-
run_builder = True
43-
TST_BUILDER_X = os.getenv("TST_BUILDER_X", "1")
44-
if TST_BUILDER_X == "0":
45-
run_builder = False
46-
if run_builder:
42+
if should_run_builder():
4743
conn = redis.StrictRedis(port=16379)
4844
conn.ping()
4945
conn.flushall()
5046
builder_consumer_group_create(conn, "0")
51-
assert conn.xlen(STREAM_KEYNAME_GH_EVENTS_COMMIT) == 0
52-
53-
result, reply_fields, error_msg = commit_schema_to_stream(
54-
{
55-
"git_hash": "0cf2df84d4b27af4bffd2bf3543838f09e10f874",
56-
"git_branch": "unstable",
57-
},
58-
conn,
59-
"redis",
60-
"redis",
61-
)
62-
assert result == True
63-
assert error_msg == None
64-
assert STREAM_KEYNAME_GH_EVENTS_COMMIT.encode() in conn.keys()
65-
assert conn.xlen(STREAM_KEYNAME_GH_EVENTS_COMMIT) == 1
66-
assert "id" in reply_fields
47+
events_in_pipe = conn.xlen(STREAM_KEYNAME_GH_EVENTS_COMMIT)
48+
if events_in_pipe == 0:
49+
result, reply_fields, error_msg = commit_schema_to_stream(
50+
{
51+
"git_hash": "0cf2df84d4b27af4bffd2bf3543838f09e10f874",
52+
"git_branch": "unstable",
53+
},
54+
conn,
55+
"redis",
56+
"redis",
57+
)
58+
assert result == True
59+
assert error_msg == None
60+
assert STREAM_KEYNAME_GH_EVENTS_COMMIT.encode() in conn.keys()
61+
assert conn.xlen(STREAM_KEYNAME_GH_EVENTS_COMMIT) == 1
62+
assert "id" in reply_fields
6763
builders_folder = "./redis_benchmarks_specification/setups/builders"
6864
different_build_specs = ["gcc:8.5.0-amd64-debian-buster-default.yml"]
6965
previous_id = ">"
@@ -78,33 +74,38 @@ def test_commit_schema_to_stream_then_build():
7874
pass
7975

8076

77+
def should_run_builder():
78+
run_builder = True
79+
TST_BUILDER_X = os.getenv("TST_BUILDER_X", "1")
80+
if TST_BUILDER_X == "0":
81+
run_builder = False
82+
return run_builder
83+
84+
8185
def test_commit_schema_to_stream_then_build_historical_redis():
8286
try:
83-
run_builder = True
84-
TST_BUILDER_X = os.getenv("TST_BUILDER_X", "1")
85-
if TST_BUILDER_X == "0":
86-
run_builder = False
87-
if run_builder:
87+
if should_run_builder():
8888
conn = redis.StrictRedis(port=16379)
8989
conn.ping()
9090
conn.flushall()
9191
builder_consumer_group_create(conn, "0")
92-
assert conn.xlen(STREAM_KEYNAME_GH_EVENTS_COMMIT) == 0
92+
events_in_pipe = conn.xlen(STREAM_KEYNAME_GH_EVENTS_COMMIT)
93+
if events_in_pipe == 0:
9394

94-
result, reply_fields, error_msg = commit_schema_to_stream(
95-
{
96-
"git_hash": "021af7629590c638ae0d4867d4b397f6e0c38ec8",
97-
"git_version": "5.0.13",
98-
},
99-
conn,
100-
"redis",
101-
"redis",
102-
)
103-
assert result == True
104-
assert error_msg == None
105-
assert STREAM_KEYNAME_GH_EVENTS_COMMIT.encode() in conn.keys()
106-
assert conn.xlen(STREAM_KEYNAME_GH_EVENTS_COMMIT) == 1
107-
assert "id" in reply_fields
95+
result, reply_fields, error_msg = commit_schema_to_stream(
96+
{
97+
"git_hash": "021af7629590c638ae0d4867d4b397f6e0c38ec8",
98+
"git_version": "5.0.13",
99+
},
100+
conn,
101+
"redis",
102+
"redis",
103+
)
104+
assert result == True
105+
assert error_msg == None
106+
assert STREAM_KEYNAME_GH_EVENTS_COMMIT.encode() in conn.keys()
107+
assert conn.xlen(STREAM_KEYNAME_GH_EVENTS_COMMIT) == 1
108+
assert "id" in reply_fields
108109
builders_folder = "./redis_benchmarks_specification/setups/builders"
109110
different_build_specs = ["gcc:8.5.0-amd64-debian-buster-default.yml"]
110111
previous_id = ">"
@@ -113,6 +114,7 @@ def test_commit_schema_to_stream_then_build_historical_redis():
113114
)
114115
assert new_builds_count == 1
115116
assert conn.exists(STREAM_KEYNAME_NEW_BUILD_EVENTS)
117+
conn.save()
116118

117119
except redis.exceptions.ConnectionError:
118120
pass

utils/tests/test_builder_schema.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# BSD 3-Clause License
2+
#
3+
# Copyright (c) 2021., Redis Labs Modules
4+
# All rights reserved.
5+
#
6+
7+
import redis
8+
9+
from redis_benchmarks_specification.__common__.builder_schema import (
10+
commit_schema_to_stream,
11+
)
12+
13+
from redis_benchmarks_specification.__builder__.builder import (
14+
builder_consumer_group_create,
15+
)
16+
from redis_benchmarks_specification.__common__.env import (
17+
STREAM_KEYNAME_GH_EVENTS_COMMIT,
18+
)
19+
from utils.tests.test_builder import should_run_builder
20+
21+
22+
def test_commit_schema_to_stream():
23+
try:
24+
if should_run_builder():
25+
conn = redis.StrictRedis(port=16379)
26+
conn.ping()
27+
conn.flushall()
28+
builder_consumer_group_create(conn, "0")
29+
events_in_pipe = conn.xlen(STREAM_KEYNAME_GH_EVENTS_COMMIT)
30+
if events_in_pipe == 0:
31+
32+
result, reply_fields, error_msg = commit_schema_to_stream(
33+
{
34+
"git_hash": "021af7629590c638ae0d4867d4b397f6e0c38ec8",
35+
"git_version": "5.0.13",
36+
},
37+
conn,
38+
"redis",
39+
"redis",
40+
)
41+
assert result == True
42+
assert error_msg == None
43+
assert STREAM_KEYNAME_GH_EVENTS_COMMIT.encode() in conn.keys()
44+
assert conn.xlen(STREAM_KEYNAME_GH_EVENTS_COMMIT) == 1
45+
assert "id" in reply_fields
46+
47+
except redis.exceptions.ConnectionError:
48+
pass

utils/tests/test_data/dump.rdb

-161 Bytes
Binary file not shown.

utils/tests/test_self_contained_coordinator.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
)
3232
from redis_benchmarks_specification.__setups__.topologies import get_topologies
3333
from utils.tests.test_data.api_builder_common import flow_1_and_2_api_builder_checks
34-
from utils.tests.test_self_contained_coordinator_memtier import rdb_load_in_tests
3534

3635

3736
def test_extract_client_cpu_limit():
@@ -99,22 +98,15 @@ def test_self_contained_coordinator_blocking_read():
9998
if run_coordinator:
10099
conn = redis.StrictRedis(port=16379)
101100
conn.ping()
102-
build_variant_name = "gcc:8.5.0-amd64-debian-buster-default"
103101
expected_datapoint_ts = None
104-
use_rdb = rdb_load_in_tests(conn)
105-
if use_rdb is False:
106-
conn.flushall()
107-
build_variant_name, reply_fields = flow_1_and_2_api_builder_checks(conn)
108-
if b"git_timestamp_ms" in reply_fields:
109-
expected_datapoint_ts = int(
110-
reply_fields[b"git_timestamp_ms"].decode()
111-
)
112-
if b"git_timestamp_ms" in reply_fields:
113-
expected_datapoint_ts = int(
114-
reply_fields[b"git_timestamp_ms"].decode()
115-
)
116-
if "git_timestamp_ms" in reply_fields:
117-
expected_datapoint_ts = int(reply_fields["git_timestamp_ms"])
102+
conn.flushall()
103+
build_variant_name, reply_fields = flow_1_and_2_api_builder_checks(conn)
104+
if b"git_timestamp_ms" in reply_fields:
105+
expected_datapoint_ts = int(reply_fields[b"git_timestamp_ms"].decode())
106+
if b"git_timestamp_ms" in reply_fields:
107+
expected_datapoint_ts = int(reply_fields[b"git_timestamp_ms"].decode())
108+
if "git_timestamp_ms" in reply_fields:
109+
expected_datapoint_ts = int(reply_fields["git_timestamp_ms"])
118110

119111
assert conn.exists(STREAM_KEYNAME_NEW_BUILD_EVENTS)
120112
assert conn.xlen(STREAM_KEYNAME_NEW_BUILD_EVENTS) > 0

utils/tests/test_self_contained_coordinator_memtier.py

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,13 @@ def test_self_contained_coordinator_blocking_read():
3737
if run_coordinator:
3838
conn = redis.StrictRedis(port=16379)
3939
conn.ping()
40-
build_variant_name = "gcc:8.5.0-amd64-debian-buster-default"
4140
expected_datapoint_ts = None
42-
use_rdb = rdb_load_in_tests(conn)
43-
if use_rdb is False:
44-
conn.flushall()
45-
build_variant_name, reply_fields = flow_1_and_2_api_builder_checks(conn)
46-
if b"git_timestamp_ms" in reply_fields:
47-
expected_datapoint_ts = int(
48-
reply_fields[b"git_timestamp_ms"].decode()
49-
)
50-
if "git_timestamp_ms" in reply_fields:
51-
expected_datapoint_ts = int(reply_fields["git_timestamp_ms"])
41+
conn.flushall()
42+
build_variant_name, reply_fields = flow_1_and_2_api_builder_checks(conn)
43+
if b"git_timestamp_ms" in reply_fields:
44+
expected_datapoint_ts = int(reply_fields[b"git_timestamp_ms"].decode())
45+
if "git_timestamp_ms" in reply_fields:
46+
expected_datapoint_ts = int(reply_fields["git_timestamp_ms"])
5247

5348
assert conn.exists(STREAM_KEYNAME_NEW_BUILD_EVENTS)
5449
assert conn.xlen(STREAM_KEYNAME_NEW_BUILD_EVENTS) > 0
@@ -195,23 +190,6 @@ def test_self_contained_coordinator_blocking_read():
195190
pass
196191

197192

198-
def rdb_load_in_tests(conn):
199-
use_rdb = True
200-
TST_RUNNER_USE_RDB = os.getenv("TST_RUNNER_USE_RDB", "1")
201-
if TST_RUNNER_USE_RDB == "0":
202-
use_rdb = False
203-
if use_rdb:
204-
try:
205-
conn.execute_command("DEBUG", "RELOAD", "NOSAVE")
206-
except redis.exceptions.ResponseError as e:
207-
if "DEBUG command not allowed" in e.__str__():
208-
use_rdb = False
209-
pass
210-
else:
211-
raise e
212-
return use_rdb
213-
214-
215193
def test_self_contained_coordinator_skip_build_variant():
216194
try:
217195
run_coordinator = True
@@ -223,16 +201,12 @@ def test_self_contained_coordinator_skip_build_variant():
223201
conn.ping()
224202
build_variant_name = "gcc:8.5.0-amd64-debian-buster-default"
225203
expected_datapoint_ts = None
226-
use_rdb = rdb_load_in_tests(conn)
227-
if use_rdb is False:
228-
conn.flushall()
229-
build_variant_name, reply_fields = flow_1_and_2_api_builder_checks(conn)
230-
if b"git_timestamp_ms" in reply_fields:
231-
expected_datapoint_ts = int(
232-
reply_fields[b"git_timestamp_ms"].decode()
233-
)
234-
if "git_timestamp_ms" in reply_fields:
235-
expected_datapoint_ts = int(reply_fields["git_timestamp_ms"])
204+
conn.flushall()
205+
build_variant_name, reply_fields = flow_1_and_2_api_builder_checks(conn)
206+
if b"git_timestamp_ms" in reply_fields:
207+
expected_datapoint_ts = int(reply_fields[b"git_timestamp_ms"].decode())
208+
if "git_timestamp_ms" in reply_fields:
209+
expected_datapoint_ts = int(reply_fields["git_timestamp_ms"])
236210

237211
assert conn.exists(STREAM_KEYNAME_NEW_BUILD_EVENTS)
238212
assert conn.xlen(STREAM_KEYNAME_NEW_BUILD_EVENTS) > 0

0 commit comments

Comments
 (0)