Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit 82f6ee3

Browse files
author
Alex Walker
authored
Add BDD to CI and create pip deployment test (#157)
## What is the goal of this PR? Our test suite was not being run in CI and could only be triggered manually by ourselves. In order to get them to work in CI, we needed them to fetch, unzip and run Grakn in the background. So we implemented that and added the tests to CI. We also didn't have an automated mechanism for verifying that our `pip` deployment produced a working Client Python artifact that could be used to make Graql queries, so we created `test-deployment-pip`. ## What are the changes implemented in this PR? - Unzip and run Grakn when running BDD tests - Add test-behaviour to automation.yml - Create test-deployment-pip
1 parent e23a617 commit 82f6ee3

File tree

31 files changed

+172
-670
lines changed

31 files changed

+172
-670
lines changed

.bazelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
build --incompatible_strict_action_env
2121
run --incompatible_strict_action_env
22-
test --incompatible_strict_action_env
22+
test --incompatible_strict_action_env --test_env=PATH
2323

2424
# what is defined in this section will be applied when bazel is invoked like this: bazel ... --config=rbe ...
2525
build:rbe --project_id=grakn-dev

.grabl/automation.yml

Lines changed: 35 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -42,52 +42,27 @@ build:
4242
sudo unlink /usr/bin/python3
4343
sudo ln -s $(which python3) /usr/bin/python3
4444
sudo ln -s /usr/share/pyshared/lsb_release.py /opt/pyenv/versions/3.6.10/lib/python3.6/site-packages/lsb_release.py
45-
ARTIFACT_USERNAME=$REPO_GRAKN_USERNAME \
46-
ARTIFACT_PASSWORD=$REPO_GRAKN_PASSWORD \
47-
bazel run @graknlabs_dependencies//distribution/artifact:create-netrc
4845
bazel build //...
4946
bazel run @graknlabs_dependencies//tool/checkstyle:test-coverage
5047
bazel test $(bazel query 'kind(checkstyle_test, //...)') --test_output=errors
51-
# test-concept:
52-
# image: graknlabs-ubuntu-20.04
53-
# type: foreground
54-
# command: |
55-
# pyenv global 3.6.10
56-
# sudo unlink /usr/bin/python3
57-
# sudo ln -s $(which python3) /usr/bin/python3
58-
# sudo ln -s /usr/share/pyshared/lsb_release.py /opt/pyenv/versions/3.6.10/lib/python3.6/site-packages/lsb_release.py
59-
# ARTIFACT_USERNAME=$REPO_GRAKN_USERNAME \
60-
# ARTIFACT_PASSWORD=$REPO_GRAKN_PASSWORD \
61-
# bazel run @graknlabs_dependencies//distribution/artifact:create-netrc
62-
# bazel test //:test_concept --test_output=errors
63-
# test-connection:
64-
# image: graknlabs-ubuntu-20.04
65-
# type: foreground
66-
# command: |
67-
# pyenv global 3.6.10
68-
# sudo unlink /usr/bin/python3
69-
# sudo ln -s $(which python3) /usr/bin/python3
70-
# sudo ln -s /usr/share/pyshared/lsb_release.py /opt/pyenv/versions/3.6.10/lib/python3.6/site-packages/lsb_release.py
71-
# ARTIFACT_USERNAME=$REPO_GRAKN_USERNAME \
72-
# ARTIFACT_PASSWORD=$REPO_GRAKN_PASSWORD \
73-
# bazel run @graknlabs_dependencies//distribution/artifact:create-netrc
74-
# bazel test //:test_connection --test_output=errors
75-
# test-query:
76-
# image: graknlabs-ubuntu-20.04
77-
# type: foreground
78-
# command: |
79-
# pyenv global 3.6.10
80-
# sudo unlink /usr/bin/python3
81-
# sudo ln -s $(which python3) /usr/bin/python3
82-
# sudo ln -s /usr/share/pyshared/lsb_release.py /opt/pyenv/versions/3.6.10/lib/python3.6/site-packages/lsb_release.py
83-
# ARTIFACT_USERNAME=$REPO_GRAKN_USERNAME \
84-
# ARTIFACT_PASSWORD=$REPO_GRAKN_PASSWORD \
85-
# bazel run @graknlabs_dependencies//distribution/artifact:create-netrc
86-
# bazel test //:test_query --test_output=errors
48+
test-behaviour:
49+
image: graknlabs-ubuntu-20.04
50+
type: foreground
51+
command: |
52+
pyenv global 3.6.10
53+
pip install -r requirements_dev.txt
54+
sudo unlink /usr/bin/python3
55+
sudo ln -s $(which python3) /usr/bin/python3
56+
sudo ln -s /usr/share/pyshared/lsb_release.py /opt/pyenv/versions/3.6.10/lib/python3.6/site-packages/lsb_release.py
57+
bazel test //tests/behaviour/connection/... --test_output=errors --jobs=1
58+
bazel test //tests/behaviour/concept/... --test_output=errors --jobs=1
59+
bazel test //tests/behaviour/graql/language/match/... --test_output=errors --jobs=1
60+
bazel test //tests/behaviour/graql/language/get/... --test_output=errors --jobs=1
61+
bazel test //tests/behaviour/graql/language/define/... --test_output=errors --jobs=1
62+
# TODO: remove --jobs=1 from Concept and Graql tests once Grakn runner is parallelisable
8763
deploy-pip-snapshot:
8864
image: graknlabs-ubuntu-20.04
89-
# TODO: should depend on tests
90-
dependencies: [build]
65+
dependencies: [build, test-behaviour]
9166
filter:
9267
owner: graknlabs
9368
branch: master
@@ -97,37 +72,28 @@ build:
9772
sudo unlink /usr/bin/python3
9873
sudo ln -s $(which python3) /usr/bin/python3
9974
sudo ln -s /usr/share/pyshared/lsb_release.py /opt/pyenv/versions/3.6.10/lib/python3.6/site-packages/lsb_release.py
100-
ARTIFACT_USERNAME=$REPO_GRAKN_USERNAME \
101-
ARTIFACT_PASSWORD=$REPO_GRAKN_PASSWORD \
102-
bazel run @graknlabs_dependencies//distribution/artifact:create-netrc
10375
export DEPLOY_PIP_USERNAME=$REPO_GRAKN_USERNAME
10476
export DEPLOY_PIP_PASSWORD=$REPO_GRAKN_PASSWORD
10577
bazel run --define version=$(git rev-parse HEAD) //:deploy-pip -- snapshot
106-
# TODO: fix test-deployment
107-
# test-deployment:
108-
# image: graknlabs-ubuntu-20.04
109-
# dependencies: [deploy-pip-snapshot]
110-
# filter:
111-
# owner: graknlabs
112-
# branch: master
113-
# type: foreground
114-
# command: |
115-
# pyenv global 3.6.10
116-
# sudo unlink /usr/bin/python3
117-
# sudo ln -s $(which python3) /usr/bin/python3
118-
# sudo ln -s /usr/share/pyshared/lsb_release.py /opt/pyenv/versions/3.6.10/lib/python3.6/site-packages/lsb_release.py
119-
# ARTIFACT_USERNAME=$REPO_GRAKN_USERNAME \
120-
# ARTIFACT_PASSWORD=$REPO_GRAKN_PASSWORD \
121-
# bazel run @graknlabs_dependencies//distribution/artifact:create-netrc
122-
# bazel run //:grakn-extractor -- dist/grakn-core-server-linux
123-
# nohup ./dist/grakn-core-server-linux/grakn server start
124-
# sleep 60
125-
# echo -n "0.0.0-$GRABL_COMMIT" > VERSION
126-
# sed -i -e "s/CLIENT_PYTHON_VERSION_MARKER/$(cat VERSION)/g" test/deployment/requirements.txt
127-
# cat test/deployment/requirements.txt
128-
# pip install --upgrade pip
129-
# pip install -r test/deployment/requirements.txt
130-
# cd test/deployment/ && python -m unittest test
78+
test-deployment-pip:
79+
image: graknlabs-ubuntu-20.04
80+
dependencies: [deploy-pip-snapshot]
81+
filter:
82+
owner: graknlabs
83+
branch: master
84+
type: foreground
85+
command: |
86+
pyenv global 3.6.10
87+
sudo unlink /usr/bin/python3
88+
sudo ln -s $(which python3) /usr/bin/python3
89+
sudo ln -s /usr/share/pyshared/lsb_release.py /opt/pyenv/versions/3.6.10/lib/python3.6/site-packages/lsb_release.py
90+
bazel run //tests:grakn-extractor -- grakn-core-all-linux
91+
./grakn-core-all-linux/grakn server &
92+
pip install --extra-index-url https://repo.grakn.ai/repository/pypi-snapshot/simple grakn-client==0.0.0-$GRABL_COMMIT
93+
cd tests/deployment/ && python -m unittest test && export TEST_SUCCESS=0 || export TEST_SUCCESS=1
94+
kill $(jps | awk '/GraknServer/ {print $1}')
95+
exit $TEST_SUCCESS
96+
13197
13298
release:
13399
filter:

BUILD

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ load("@graknlabs_client_python_pip//:requirements.bzl",
2525
load("@graknlabs_bazel_distribution//pip:rules.bzl", "assemble_pip", "deploy_pip")
2626
load("@graknlabs_bazel_distribution_pip//:requirements.bzl", graknlabs_bazel_distribution_requirement = "requirement")
2727
load("@graknlabs_bazel_distribution//github:rules.bzl", "deploy_github")
28-
load("@graknlabs_bazel_distribution//artifact:rules.bzl", "artifact_extractor")
2928

3029
load("@graknlabs_dependencies//tool/release:rules.bzl", "release_validate_python_deps")
3130
load("@graknlabs_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test")
@@ -104,11 +103,6 @@ deploy_github(
104103
draft = False
105104
)
106105

107-
artifact_extractor(
108-
name = "grakn-extractor",
109-
artifact = "@graknlabs_grakn_core_artifact_linux//file",
110-
)
111-
112106
release_validate_python_deps(
113107
name = "release-validate-python-deps",
114108
requirements = "//:requirements.txt",

WORKSPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ graknlabs_grakn_core_artifacts()
106106

107107
pip3_import(
108108
name = "graknlabs_client_python_pip",
109-
requirements = "//:requirements.txt",
109+
requirements = "//:requirements_dev.txt",
110110
)
111111
load("@graknlabs_client_python_pip//:requirements.bzl",
112112
graknlabs_client_python_pip_install = "pip_install")

dependencies/graknlabs/artifacts.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ def graknlabs_grakn_core_artifacts():
2727
artifact_name = "grakn-core-server-{platform}-{version}.{ext}",
2828
tag_source = deployment["artifact.release"],
2929
commit_source = deployment["artifact.snapshot"],
30-
commit = "118eee244a4949c629de0277804155ebd4b316be",
30+
commit = "184f37fcd48cc55ef15a7425bc863b18071afc35",
3131
)

dependencies/graknlabs/repositories.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ def graknlabs_behaviour():
3737
git_repository(
3838
name = "graknlabs_behaviour",
3939
remote = "https://github.com/graknlabs/behaviour",
40-
commit = "2279d3a284d53fdd989885c06f3c50f00f930a63" # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_behaviour
40+
commit = "e20a930d7fec16d2feee008a937f4b565842279e" # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_behaviour
4141
)

grakn/concept/proto/concept_proto_builder.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@
2626
from grakn.concept.type.value_type import ValueType
2727

2828

29+
def iid(iid_: str):
30+
return bytes.fromhex(iid_.lstrip("0x"))
31+
32+
2933
def thing(thing_):
3034
proto_thing = concept_proto.Thing()
31-
proto_thing.iid = bytes.fromhex(thing_.get_iid())
35+
proto_thing.iid = iid(thing_.get_iid())
3236
proto_thing.encoding = thing_encoding(thing_)
3337
return proto_thing
3438

@@ -95,10 +99,6 @@ def value_type(value_type_: ValueType):
9599
raise GraknClientException("Unrecognised value type: " + str(value_type_))
96100

97101

98-
def iid(iid_: str):
99-
return bytes.fromhex(iid_.lstrip("0x"))
100-
101-
102102
def thing_encoding(thing_):
103103
if thing_.is_entity():
104104
return concept_proto.Thing.Encoding.Value("ENTITY")

tests/BUILD

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#
1919

2020
# Note: Do NOT rename this folder to 'test' as it conflicts with a built-in Python package!
21+
load("@graknlabs_bazel_distribution//artifact:rules.bzl", "artifact_extractor")
2122
load("@graknlabs_common//test/server:rules.bzl", "native_grakn_artifact")
2223
load("@graknlabs_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test")
2324
load("@rules_python//python:defs.bzl", "py_library", "py_test")
@@ -30,58 +31,6 @@ native_grakn_artifact(
3031
visibility = ["//tests:__subpackages__"],
3132
)
3233

33-
py_test(
34-
name = "test_concept",
35-
srcs = [
36-
"integration/base.py",
37-
"integration/test_concept.py"
38-
],
39-
deps = [
40-
"//:client_python",
41-
],
42-
data = [":native-grakn-artifact"],
43-
args = ["$(location :native-grakn-artifact)"],
44-
python_version = "PY3"
45-
)
46-
47-
py_test(
48-
name = "test_connection",
49-
srcs = [
50-
"integration/base.py",
51-
"integration/test_connection.py"
52-
],
53-
deps = [
54-
"//:client_python",
55-
],
56-
data = [":native-grakn-artifact"],
57-
args = ["$(location :native-grakn-artifact)"],
58-
python_version = "PY3"
59-
)
60-
61-
py_test(
62-
name = "test_query",
63-
srcs = [
64-
"integration/base.py",
65-
"integration/test_query.py"
66-
],
67-
deps = [
68-
"//:client_python",
69-
],
70-
size = "large",
71-
data = [":native-grakn-artifact"],
72-
args = ["$(location :native-grakn-artifact)"],
73-
python_version = "PY3"
74-
)
75-
76-
test_suite(
77-
name = "test_integration",
78-
tests = [
79-
":test_concept",
80-
":test_connection",
81-
":test_query",
82-
]
83-
)
84-
8534
checkstyle_test(
8635
name = "checkstyle",
8736
include = glob([
@@ -90,4 +39,10 @@ checkstyle_test(
9039
"integration/*",
9140
]),
9241
license_type = "apache",
42+
size = "small",
43+
)
44+
45+
artifact_extractor(
46+
name = "grakn-extractor",
47+
artifact = ":native-grakn-artifact",
9348
)

tests/behaviour/concept/thing/attribute/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ py_behave_test(
4747
"//tests/behaviour:util",
4848
"//tests/behaviour/config:parameters",
4949
],
50+
native_grakn_artifact = "//tests:native-grakn-artifact",
5051
size = "medium",
5152
)
5253

tests/behaviour/concept/thing/entity/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ py_behave_test(
4848
"//tests/behaviour:util",
4949
"//tests/behaviour/config:parameters",
5050
],
51+
native_grakn_artifact = "//tests:native-grakn-artifact",
5152
size = "medium",
5253
)
5354

0 commit comments

Comments
 (0)