Skip to content

Commit

Permalink
Behavioural tests (typedb#127)
Browse files Browse the repository at this point in the history
## What is the goal of this PR?

We introduced behavioural tests in alignment with the behavioural tests present in our other clients and core server. This also comes with a more comprehensive set of automated tests, split up in a more sensible way, including but not limited to local integration testing, behavioural tests, and automatic linting checks at the build level.

## What are the changes implemented in this PR?

Behavioural test step definitions added for the Concept and Connection packages.
General testing infrastructure has been added to allow for running a grakn server artifact for testing purposes.
Test folder has been sorted more cleanly to reflect what is needed for what tests.
Linting pass has been added to the build workflow.
Testing has been broken up across multiple workflows- test-behaviour and test-integration
  • Loading branch information
Alistair Crook committed Jan 8, 2021
1 parent 9ecca79 commit f5a82f1
Show file tree
Hide file tree
Showing 37 changed files with 1,210 additions and 55 deletions.
20 changes: 14 additions & 6 deletions .grabl/automation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,21 @@ build:
bazel build //...
bazel run @graknlabs_dependencies//tool/checkstyle:test-coverage
bazel test $(bazel query 'kind(checkstyle_test, //...)')
test:
npm install
npm run lint
test-integration:
image: graknlabs-ubuntu-20.04
command: |
./test/start-server.sh
./test/test.sh && export TEST_SUCCESS=0 || export TEST_SUCCESS=1
./test/stop-server.sh
./test/common/start-server.sh
./test/integration/test.sh && export TEST_SUCCESS=0 || export TEST_SUCCESS=1
./test/common/stop-server.sh
exit $TEST_SUCCESS
test-behaviour:
image: graknlabs-ubuntu-20.04
command: |
npm install typescript
bazel test //test/behaviour/... --jobs=1
# TODO: Remove --jobs=1 from above line once parallelism is functional.
deploy-npm-snapshot:
filter:
owner: graknlabs
Expand All @@ -61,15 +69,15 @@ build:
export DEPLOY_NPM_PASSWORD=$REPO_GRAKN_PASSWORD
export DEPLOY_NPM_EMAIL=$REPO_GRAKN_EMAIL
bazel run --define version=$(git rev-parse HEAD) //:deploy-npm -- snapshot
dependencies: [build, test]
dependencies: [build, test-integration, test-behaviour]

test-deployment-npm:
filter:
owner: graknlabs
branch: master
image: graknlabs-ubuntu-20.04
command: |
./test/start-server.sh
./test/common/start-server.sh
cd test/deployment/
echo -n "0.0.0-$GRABL_COMMIT" > ../../VERSION
npm install https://repo.grakn.ai/repository/npm-snapshot-group/grakn-client/-/grakn-client-$(cat ../../VERSION).tgz
Expand Down
40 changes: 40 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,46 @@ load("//:deployment.bzl", github_deployment = "deployment")

load("@npm//@bazel/typescript:index.bzl", "ts_library")

genrule(
name = "client-nodejs-compiled",
outs = ["client-nodejs.tar.gz"],
cmd = "npx tsc; tar -cf $(@D)/client-nodejs.tar.gz dist;",
tools = [
"//:client-nodejs-ts",
"//:package.json",
"//:package-lock.json",
],
visibility = ["//visibility:public"],
)

filegroup(
name = "client-nodejs-ts",
srcs = glob([
"*.ts",
"common/**/*.ts",
"concept/**/*.ts",
"query/**/*.ts",
"rpc/**/*.ts",
"tsconfig.json",
"node_modules/**"
]),
)

filegroup(
name = "behavioural-steps",
srcs = [
"//test/behaviour/config:Parameters.ts",
"//test/behaviour/connection:ConnectionSteps.ts",
"//test/behaviour/connection/database:DatabaseSteps.ts",
"//test/behaviour/connection/session:SessionSteps.ts",
"//test/behaviour/connection/transaction:TransactionSteps.ts",
"//test/behaviour/graql/language/define:DefineSteps.ts",
"//test/behaviour/util:Util.ts",
"//:tsconfig-test.json"
] + glob(["node_modules/**"]),
visibility = ["//test/behaviour:__pkg__"],
)

ts_library(
name = "_client_nodejs",
srcs = glob([
Expand Down
22 changes: 22 additions & 0 deletions GraknOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ export class GraknOptions {
private _infer: boolean;
private _explain: boolean;
private _batchSize: number;
private _sessionIdleTimeoutMillis: number;
private _schemaLockAcquireTimeoutMillis: number;

constructor() {
this._infer = null;
this._explain = null;
this._batchSize = null;
this._sessionIdleTimeoutMillis = null;
this._schemaLockAcquireTimeoutMillis = null;
}

infer(): boolean {
Expand Down Expand Up @@ -62,4 +66,22 @@ export class GraknOptions {
this._batchSize = batchSize;
return this;
}

sessionIdleTimeoutMillis(): number {
return this._sessionIdleTimeoutMillis;
}

setSessionIdleTimeoutMillis(sessionIdleTimeoutMillis: number): GraknOptions {
this._sessionIdleTimeoutMillis = sessionIdleTimeoutMillis;
return this;
}

schemaLockAcquireTimeoutMillis(): number {
return this._schemaLockAcquireTimeoutMillis;
}

setSchemaLockAcquireTimeoutMillis(schemaLockAcquireTimeoutMillis: number): GraknOptions {
this._schemaLockAcquireTimeoutMillis = schemaLockAcquireTimeoutMillis;
return this;
}
}
4 changes: 3 additions & 1 deletion common/ProtoBuilder.ts → GraknProtoBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { GraknOptions } from "../dependencies_internal";
import { GraknOptions } from "./dependencies_internal";
import options_pb from "grakn-protocol/protobuf/options_pb";
import Options = options_pb.Options;

Expand All @@ -28,6 +28,8 @@ export namespace ProtoBuilder {
if (options.infer() != null) optionsProto.setInfer(options.infer() as boolean);
if (options.explain() != null) optionsProto.setExplain(options.explain() as boolean);
if (options.batchSize() != null) optionsProto.setBatchSize(options.batchSize() as number);
if (options.sessionIdleTimeoutMillis() != null) optionsProto.setSessionIdleTimeoutMillis(options.sessionIdleTimeoutMillis() as number);
if (options.schemaLockAcquireTimeoutMillis() != null) optionsProto.setSchemaLockAcquireTimeoutMillis(options.schemaLockAcquireTimeoutMillis() as number);
}
return optionsProto;
}
Expand Down
16 changes: 0 additions & 16 deletions concept/type/impl/TypeImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,6 @@ export abstract class TypeImpl extends ConceptImpl implements Type {
this._root = root;
}

isThingType(): boolean {
return false;
}

isEntityType(): boolean {
return false;
}

isAttributeType(): boolean {
return false;
}

isRelationType(): boolean {
return false;
}

getLabel(): string {
return this._label;
}
Expand Down
2 changes: 1 addition & 1 deletion dependencies/graknlabs/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ def graknlabs_behaviour():
git_repository(
name = "graknlabs_behaviour",
remote = "https://github.com/graknlabs/behaviour",
commit = "7039a69aa776ca29511403d39111af36bc451282", # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_behaviour
commit = "8fd31875980767172c100ae65720b129ae928b53", # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_behaviour
)
2 changes: 1 addition & 1 deletion dependencies_internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export * from "./common/errors/ErrorMessage";
export * from "./common/errors/GraknClientError";
export * from "./common/BlockingQueue";
export * from "./common/Bytes";
export * from "./common/ProtoBuilder";
export * from "./common/utils";

/* concept.answer */
Expand Down Expand Up @@ -92,6 +91,7 @@ export * from "./rpc/Stream";
/* ROOT */
export * from "./Grakn";
export * from "./GraknOptions";
export * from "./GraknProtoBuilder";

/* concept.proto */
export * from "./concept/proto/ConceptProtoBuilder";
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
"build": "npm run clean && npm run lint && tsc",
"pretest": "npm run build",
"test": "npm run test-concept && npm run test-connection && npm run test-query",
"test-concept": "node test/endtoend/test-concept.js",
"test-connection": "node test/endtoend/test-connection.js",
"test-query": "node test/endtoend/test-query.js",
"lint": "eslint . --ext .ts"
"test-concept": "node test/integration/test-concept.js",
"test-connection": "node test/integration/test-connection.js",
"test-query": "node test/integration/test-query.js",
"lint": "eslint . --ext .ts",
"compile-tests": "tsc --build tsconfig-test.json"
},
"dependencies": {
"@grpc/grpc-js": "1.2.1",
Expand Down
2 changes: 1 addition & 1 deletion rpc/RPCTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class RPCTransaction implements Grakn.Transaction {
}
if (!this._transactionWasClosed) {
this._transactionWasClosed = true;
this._collectors.clearWithError(new ErrorResponse("Transaction closed."))
this._collectors.clearWithError(new ErrorResponse(new GraknClientError(ErrorMessage.Client.TRANSACTION_CLOSED.message())))
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ checkstyle_test(
include = glob([
"*",
"deployment/*",
"behaviour/*",
"endtoend/*",
"integration/*",
"common/*"
]),
exclude = glob([
"**/package.json",
Expand Down
43 changes: 43 additions & 0 deletions test/behaviour/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

exports_files([
"cucumber_test.sh",
"tsconfig-test.json",
])

genrule(
name = "behavioural-steps-compiled",
outs = ["behavioural-steps.tar.gz"],
cmd = "tar -xf $(location //:client-nodejs-compiled); npx tsc --build tsconfig-test.json; tar -cf $(@D)/behavioural-steps.tar.gz dist-test;",
tools = [
"//:behavioural-steps",
"//:client-nodejs-compiled",
"//:package.json",
"//:package-lock.json",
],
visibility = ["//visibility:public"],
)

load("@graknlabs_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test")
checkstyle_test(
name = "checkstyle",
include = glob(["*"]),
license_type = "apache",
)
28 changes: 28 additions & 0 deletions test/behaviour/concept/thing/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

exports_files(["ThingSteps.ts"])

load("@graknlabs_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test")

checkstyle_test(
name = "checkstyle",
include = glob(["*"]),
license_type = "apache",
)
28 changes: 28 additions & 0 deletions test/behaviour/concept/type/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

exports_files(["TypeSteps.ts"])

load("@graknlabs_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test")

checkstyle_test(
name = "checkstyle",
include = glob(["*"]),
license_type = "apache",
)
29 changes: 29 additions & 0 deletions test/behaviour/config/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

load("@graknlabs_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test")
load("//test/behaviour:rules.bzl", "node_cucumber_test")

exports_files(["Parameters.ts"])

checkstyle_test(
name = "checkstyle",
include = glob(["*"]),
license_type = "apache",
)
Loading

0 comments on commit f5a82f1

Please sign in to comment.