Skip to content

Commit c6f86a7

Browse files
Increased API and builder spec implementation testing (#15)
* [add] Increased API and builder spec implementation testing * [fix] Fixed wrong version assert
1 parent c669604 commit c6f86a7

File tree

8 files changed

+64
-26
lines changed

8 files changed

+64
-26
lines changed

.github/workflows/publish-pypi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Publish Pypi
22
on:
33
release:
4-
types: [ published, edited ]
4+
types: [ published ]
55

66
jobs:
77
pytest:

redis_benchmarks_specification/__api__/api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def verify_password(username, password):
4949
result = True
5050
except redis.exceptions.ResponseError:
5151
result = False
52+
except redis.exceptions.AuthenticationError:
53+
result = False
5254
return result
5355

5456

@@ -79,7 +81,7 @@ def commit_schema_to_stream(json_str: str, conn: redis.StrictRedis):
7981
result = False
8082

8183
if result is True:
82-
id = conn.xadd(STREAM_KEYNAME_GH_EVENTS_COMMIT, fields)
84+
id = conn.xadd(STREAM_KEYNAME_GH_EVENTS_COMMIT.encode(), fields)
8385
reply_fields["id"] = id
8486

8587
return result, reply_fields, error_msg

redis_benchmarks_specification/__builder__/builder.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def main():
112112

113113
previous_id = args.consumer_start_id
114114
while True:
115-
previous_id = builder_process_stream(
115+
previous_id, new_builds_count = builder_process_stream(
116116
builders_folder, conn, different_build_specs, previous_id
117117
)
118118

@@ -138,14 +138,16 @@ def builder_consumer_group_create(conn):
138138

139139

140140
def builder_process_stream(builders_folder, conn, different_build_specs, previous_id):
141+
new_builds_count = 0
141142
logging.info("Entering blocking read waiting for work.")
143+
consumer_name = "{}-proc#{}".format(STREAM_GH_EVENTS_COMMIT_BUILDERS_CG, "1")
142144
newTestInfo = conn.xreadgroup(
143145
STREAM_GH_EVENTS_COMMIT_BUILDERS_CG,
144-
"{}-proc#{}".format(STREAM_GH_EVENTS_COMMIT_BUILDERS_CG, "1"),
146+
consumer_name,
145147
{STREAM_KEYNAME_GH_EVENTS_COMMIT: previous_id},
146148
count=1,
147-
block=0,
148149
)
150+
149151
if len(newTestInfo[0]) < 2 or len(newTestInfo[0][1]) < 1:
150152
previous_id = ">"
151153
else:
@@ -162,6 +164,9 @@ def builder_process_stream(builders_folder, conn, different_build_specs, previou
162164
git_hash = testDetails[b"git_hash"]
163165
logging.info("Received commit hash specifier {}.".format(git_hash))
164166
buffer = testDetails[b"zip_archive"]
167+
git_branch = None
168+
if b"git_branch" in testDetails:
169+
git_branch = testDetails[b"git_branch"]
165170

166171
for build_spec in different_build_specs:
167172
build_config, id = get_build_config(builders_folder + "/" + build_spec)
@@ -239,6 +244,8 @@ def builder_process_stream(builders_folder, conn, different_build_specs, previou
239244
"build_command": build_command,
240245
"build_artifacts": ",".join(build_artifacts),
241246
}
247+
if git_branch is not None:
248+
build_stream_fields["git_branch"] = git_branch
242249
for artifact in build_artifacts:
243250
bin_artifact = open(
244251
"{}src/{}".format(redis_temporary_dir, artifact), "rb"
@@ -258,9 +265,15 @@ def builder_process_stream(builders_folder, conn, different_build_specs, previou
258265
)
259266
)
260267
shutil.rmtree(temporary_dir, ignore_errors=True)
268+
new_builds_count = new_builds_count + 1
269+
conn.xack(
270+
STREAM_GH_EVENTS_COMMIT_BUILDERS_CG,
271+
STREAM_KEYNAME_GH_EVENTS_COMMIT,
272+
streamId,
273+
)
261274
else:
262275
logging.error("Missing commit information within received message.")
263-
return previous_id
276+
return previous_id, new_builds_count
264277

265278

266279
def build_spec_image_prefetch(builders_folder, different_build_specs):

redis_benchmarks_specification/__self_contained_coordinator__/self_contained_coordinator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,12 @@ def extract_build_info_from_streamdata(testDetails):
443443
git_hash = testDetails[b"git_hash"]
444444
if b"git_branch" in testDetails:
445445
git_branch = testDetails[b"git_branch"]
446+
if type(git_branch) == bytes:
447+
git_branch = git_branch.decode()
446448
if b"git_version" in testDetails:
447449
git_version = testDetails[b"git_version"]
450+
if type(git_version) == bytes:
451+
git_version = git_version.decode()
448452
if type(git_hash) == bytes:
449453
git_hash = git_hash.decode()
450454
logging.info("Received commit hash specifier {}.".format(git_hash))

tox.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[testenv:integration-tests]
2+
passenv = *
3+
24
deps =
35
pytest
46
pytest-cov
@@ -21,3 +23,5 @@ docker =
2123
image = redislabs/redistimeseries:1.4.7
2224
ports =
2325
6379:6379/tcp
26+
volumes =
27+
bind:rw:{toxinidir}/utils/tests/test_data/:/data

utils/tests/test_builder.py

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,49 @@
33
# Copyright (c) 2021., Redis Labs
44
# All rights reserved.
55
#
6+
import os
7+
68
from redis_benchmarks_specification.__api__.api import commit_schema_to_stream
79
import redis
810

11+
from redis_benchmarks_specification.__builder__.builder import (
12+
builder_consumer_group_create,
13+
builder_process_stream,
14+
)
915
from redis_benchmarks_specification.__common__.env import (
1016
STREAM_KEYNAME_GH_EVENTS_COMMIT,
17+
STREAM_KEYNAME_NEW_BUILD_EVENTS,
18+
STREAM_GH_EVENTS_COMMIT_BUILDERS_CG,
1119
)
1220

1321

14-
def test_commit_schema_to_stream():
15-
result, reply_fields, error_msg = commit_schema_to_stream(
16-
'{"git_hashss":"0cf2df84d4b27af4bffd2bf3543838f09e10f874"}', None
17-
)
18-
assert result == False
19-
assert error_msg is not None
22+
def test_commit_schema_to_stream_then_build():
2023
try:
21-
conn = redis.StrictRedis()
22-
conn.ping()
23-
conn.flushall()
24-
result, reply_fields, error_msg = commit_schema_to_stream(
25-
'{"git_hash":"0cf2df84d4b27af4bffd2bf3543838f09e10f874"}', conn
26-
)
27-
assert result == True
28-
assert error_msg == None
29-
reply = conn.xread({STREAM_KEYNAME_GH_EVENTS_COMMIT: 0}, 1)
30-
assert (
31-
reply[0][1][0][1][b"git_hash"]
32-
== b"0cf2df84d4b27af4bffd2bf3543838f09e10f874"
33-
)
24+
skip_builder = False
25+
if skip_builder is not True:
26+
conn = redis.StrictRedis()
27+
conn.ping()
28+
conn.flushall()
29+
builder_consumer_group_create(conn)
30+
assert conn.xlen(STREAM_KEYNAME_GH_EVENTS_COMMIT) == 0
31+
32+
result, reply_fields, error_msg = commit_schema_to_stream(
33+
'{"git_hash":"0cf2df84d4b27af4bffd2bf3543838f09e10f874"}', conn
34+
)
35+
assert result == True
36+
assert error_msg == None
37+
assert STREAM_KEYNAME_GH_EVENTS_COMMIT.encode() in conn.keys()
38+
assert conn.xlen(STREAM_KEYNAME_GH_EVENTS_COMMIT) == 1
39+
assert "id" in reply_fields
40+
builders_folder = "./redis_benchmarks_specification/setups/builders"
41+
different_build_specs = ["gcc:8.5.0-amd64-debian-buster-default.yml"]
42+
previous_id = ">"
43+
previous_id, new_builds_count = builder_process_stream(
44+
builders_folder, conn, different_build_specs, previous_id
45+
)
46+
assert new_builds_count == 1
47+
assert conn.exists(STREAM_KEYNAME_NEW_BUILD_EVENTS)
48+
conn.save()
3449

3550
except redis.exceptions.ConnectionError:
3651
pass

utils/tests/test_data/dump.rdb

8.64 MB
Binary file not shown.

utils/tests/test_redis_benchmarks_specification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33

44
def test_version():
5-
assert __version__ == "0.1.0"
5+
assert __version__ == "0.1.2"

0 commit comments

Comments
 (0)