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

Commit 15baf81

Browse files
Base BDD test scaffolding (#38)
## What is the goal of this PR? We create the `behaviour` test package and introduce the BDD context structure. We also implement basic connection and database management BDD tests. ## What are the changes implemented in this PR? We add the typedb-behaviour dependency, and imlpement the database, session, and transaction steps, along with the TypeQL steps necessary to write schema and data. Drive-by: fix clippy warnings.
1 parent 5840bd4 commit 15baf81

File tree

31 files changed

+974
-47
lines changed

31 files changed

+974
-47
lines changed

.factory/automation.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ build:
5555
bazel run @vaticle_dependencies//distribution/artifact:create-netrc
5656
bazel build //...
5757
tools/start-core-server.sh
58-
bazel test //tests:queries --test_arg=-- --test_arg=core --test_arg=--test-threads=1 --test_output=streamed && export TEST_SUCCESS=0 || export TEST_SUCCESS=1
58+
bazel test //tests --test_arg=-- --test_arg=integration::queries::core --test_arg=--test-threads=1 --test_output=streamed && export TEST_SUCCESS=0 || export TEST_SUCCESS=1
5959
tools/stop-core-server.sh
6060
exit $TEST_SUCCESS
6161
test-integration-cluster:
@@ -67,18 +67,29 @@ build:
6767
bazel run @vaticle_dependencies//distribution/artifact:create-netrc
6868
bazel build //...
6969
source tools/start-cluster-servers.sh # use source to receive export vars
70-
bazel test //tests:queries --test_env=ROOT_CA=$ROOT_CA --test_arg=-- --test_arg=cluster --test_arg=--test-threads=1 --test_output=streamed && export TEST_SUCCESS=0 || export TEST_SUCCESS=1
70+
bazel test //tests --test_env=ROOT_CA=$ROOT_CA --test_arg=-- --test_arg=integration::queries::cluster --test_arg=--test-threads=1 --test_output=streamed && export TEST_SUCCESS=0 || export TEST_SUCCESS=1
7171
tools/stop-cluster-servers.sh
7272
exit $TEST_SUCCESS
7373
test-integration-runtimes:
74+
image: vaticle-ubuntu-22.04
75+
command: |
76+
export ARTIFACT_USERNAME=$REPO_VATICLE_USERNAME
77+
export ARTIFACT_PASSWORD=$REPO_VATICLE_PASSWORD
78+
bazel run @vaticle_dependencies//distribution/artifact:create-netrc
79+
bazel build //...
80+
source tools/start-cluster-servers.sh # use source to receive export vars
81+
bazel test //tests --test_env=ROOT_CA=$ROOT_CA --test_arg=-- --test_arg=integration::runtimes --test_arg=--test-threads=1 --test_output=streamed && export TEST_SUCCESS=0 || export TEST_SUCCESS=1
82+
tools/stop-cluster-servers.sh
83+
exit $TEST_SUCCESS
84+
test-behaviour-connection:
7485
image: vaticle-ubuntu-22.04
7586
command: |
7687
export ARTIFACT_USERNAME=$REPO_VATICLE_USERNAME
7788
export ARTIFACT_PASSWORD=$REPO_VATICLE_PASSWORD
7889
bazel run @vaticle_dependencies//distribution/artifact:create-netrc
7990
bazel build //...
8091
tools/start-core-server.sh
81-
bazel test //tests:runtimes --test_arg=-- --test_arg=--test-threads=1 --test_output=streamed && export TEST_SUCCESS=0 || export TEST_SUCCESS=1
92+
bazel test //tests --test_arg=-- --test_arg=behaviour::connection --test_arg=--test-threads=1 --test_output=streamed && export TEST_SUCCESS=0 || export TEST_SUCCESS=1
8293
tools/stop-core-server.sh
8394
exit $TEST_SUCCESS
8495
deploy-crate-snapshot:

WORKSPACE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ github_deps()
8181
# Load @vaticle dependencies #
8282
################################
8383

84-
load("//dependencies/vaticle:repositories.bzl", "vaticle_typedb_common", "vaticle_typedb_protocol", "vaticle_typeql")
84+
load("//dependencies/vaticle:repositories.bzl", "vaticle_typedb_common", "vaticle_typedb_protocol", "vaticle_typedb_behaviour", "vaticle_typeql")
8585
vaticle_typedb_common()
8686
vaticle_typedb_protocol()
87+
vaticle_typedb_behaviour()
8788
vaticle_typeql()
8889

8990
# Load artifacts

dependencies/vaticle/repositories.bzl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def vaticle_dependencies():
2525
git_repository(
2626
name = "vaticle_dependencies",
2727
remote = "https://github.com/vaticle/dependencies",
28-
commit = "76636b1672b04e9880439395b8913231724ae459", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies
28+
commit = "25ac954c8757d5ba64914e44678e74e659179005", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies
2929
)
3030

3131
def vaticle_typedb_common():
@@ -42,6 +42,13 @@ def vaticle_typedb_protocol():
4242
commit = "b1c19e02054c1a1d354b42875e6ccd67602a546f", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies
4343
)
4444

45+
def vaticle_typedb_behaviour():
46+
git_repository(
47+
name = "vaticle_typedb_behaviour",
48+
remote = "https://github.com/vaticle/typedb-behaviour",
49+
commit = "21ae86ac44e84c7dbb4351a9006b97a555f0a215", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour
50+
)
51+
4552
def vaticle_typeql():
4653
git_repository(
4754
name = "vaticle_typeql",

src/common/options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct Options {
3737

3838
impl Options {
3939
pub fn new() -> Self {
40-
Default::default()
40+
Self::default()
4141
}
4242

4343
pub fn infer(self, infer: bool) -> Self {

src/connection/connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl ServerConnection {
181181

182182
pub(crate) fn force_close(&self) -> Result {
183183
let session_ids: Vec<SessionID> = self.open_sessions.lock().unwrap().keys().cloned().collect();
184-
for session_id in session_ids.into_iter() {
184+
for session_id in session_ids {
185185
self.close_session(session_id).ok();
186186
}
187187
self.request_transmitter.force_close()

src/connection/network/transmitter/response_sink.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<T> ResponseSink<T> {
5858
}
5959
}
6060

61-
pub(super) async fn error(self, error: ConnectionError) {
61+
pub(super) fn error(self, error: ConnectionError) {
6262
match self {
6363
Self::AsyncOneShot(sink) => sink.send(Err(error.into())).ok(),
6464
Self::BlockingOneShot(sink) => sink.send(Err(error.into())).ok(),

src/connection/network/transmitter/transaction.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
use std::{
2323
collections::HashMap,
24-
ops::DerefMut,
2524
sync::{Arc, RwLock},
2625
time::Duration,
2726
};
@@ -85,8 +84,12 @@ impl TransactionTransmitter {
8584
Self { request_sink: buffer_sink, is_open, shutdown_sink }
8685
}
8786

87+
pub(in crate::connection) fn is_open(&self) -> bool {
88+
self.is_open.load()
89+
}
90+
8891
pub(in crate::connection) async fn single(&self, req: TransactionRequest) -> Result<TransactionResponse> {
89-
if !self.is_open.load() {
92+
if !self.is_open() {
9093
return Err(ConnectionError::SessionIsClosed().into());
9194
}
9295
let (res_sink, recv) = oneshot_async();
@@ -98,7 +101,7 @@ impl TransactionTransmitter {
98101
&self,
99102
req: TransactionRequest,
100103
) -> Result<impl Stream<Item = Result<TransactionResponse>>> {
101-
if !self.is_open.load() {
104+
if !self.is_open() {
102105
return Err(ConnectionError::SessionIsClosed().into());
103106
}
104107
let (res_part_sink, recv) = unbounded_async();
@@ -246,7 +249,7 @@ impl ResponseCollector {
246249
match self.request_sink.send((TransactionRequest::Stream { request_id }, None)) {
247250
Err(SendError((TransactionRequest::Stream { request_id }, None))) => {
248251
let callback = self.callbacks.write().unwrap().remove(&request_id).unwrap();
249-
callback.error(ConnectionError::TransactionIsClosed()).await;
252+
callback.error(ConnectionError::TransactionIsClosed());
250253
}
251254
_ => (),
252255
}
@@ -263,9 +266,9 @@ impl ResponseCollector {
263266

264267
async fn close(self, error: ConnectionError) {
265268
self.is_open.store(false);
266-
let mut listeners = std::mem::take(self.callbacks.write().unwrap().deref_mut());
269+
let mut listeners = std::mem::take(&mut *self.callbacks.write().unwrap());
267270
for (_, listener) in listeners.drain() {
268-
listener.error(error.clone()).await;
271+
listener.error(error.clone());
269272
}
270273
}
271274
}

src/connection/runtime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl BackgroundRuntime {
4444
thread::Builder::new().name("gRPC worker".to_string()).spawn(move || {
4545
async_runtime.block_on(async move {
4646
shutdown_source.recv().await;
47-
})
47+
});
4848
})?;
4949
Ok(Self { async_runtime_handle, is_open, shutdown_sink })
5050
}

src/connection/transaction_stream.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ impl TransactionStream {
4747
Self { type_, options, transaction_transmitter }
4848
}
4949

50+
pub(crate) fn is_open(&self) -> bool {
51+
self.transaction_transmitter.is_open()
52+
}
53+
5054
pub(crate) fn type_(&self) -> TransactionType {
5155
self.type_
5256
}

src/database/database.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl Database {
105105
{
106106
let mut is_first_run = true;
107107
let replicas = self.replicas.read().unwrap().clone();
108-
for replica in replicas.iter() {
108+
for replica in replicas {
109109
match task(replica.database.clone(), self.connection.connection(&replica.address)?.clone(), is_first_run)
110110
.await
111111
{

0 commit comments

Comments
 (0)