Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cargo first #711

Draft
wants to merge 4 commits into
base: 3.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
switch behaviour tests to blocking (sync) driver mode
  • Loading branch information
dmitrii-ubskii committed Nov 13, 2024
commit 6c80d38f5b669a04193b0c1555042f8f208db814
19 changes: 0 additions & 19 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@

[dev-dependencies]

[dev-dependencies.smol]
features = []
version = "1.3.0"
default-features = false

[dev-dependencies.regex]
features = ["default", "perf", "perf-backtrack", "perf-cache", "perf-dfa", "perf-inline", "perf-literal", "perf-onepass", "std", "unicode", "unicode-age", "unicode-bool", "unicode-case", "unicode-gencat", "unicode-perl", "unicode-script", "unicode-segment"]
version = "1.10.6"
default-features = false

[dev-dependencies.async-std]
features = ["alloc", "async-attributes", "async-channel", "async-global-executor", "async-io", "async-lock", "attributes", "crossbeam-utils", "default", "futures-channel", "futures-core", "futures-io", "futures-lite", "gloo-timers", "kv-log-macro", "log", "memchr", "once_cell", "pin-project-lite", "pin-utils", "slab", "std", "wasm-bindgen-futures"]
version = "1.13.0"
default-features = false

[dev-dependencies.steps]
path = "../rust/tests/behaviour/steps"
features = []
Expand Down Expand Up @@ -128,10 +113,6 @@
version = "0.8.4"
default-features = false

[[test]]
path = "tests/integration/core/example.rs"
name = "test_example"

[[test]]
path = "tests/behaviour/connection/database.rs"
name = "test_database"
Expand Down
2 changes: 1 addition & 1 deletion rust/tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ rustfmt_test(
"//rust/tests/behaviour/connection:test_transaction",
"//rust/tests/behaviour/driver:test_driver",

"//rust/tests/integration/core:test_example",
# "//rust/tests/integration/core:test_example",
# "//rust/tests/integration/cloud:test_example",
],
size = "small",
Expand Down
2 changes: 1 addition & 1 deletion rust/tests/behaviour/steps/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ rust_library(
srcs = glob(["**/*.rs"]),
crate_root = "lib.rs",
deps = [
"//rust:typedb_driver",
"//rust:typedb_driver_sync",
"@crates//:async-std",
"@crates//:chrono",
"@crates//:cucumber",
Expand Down
3 changes: 2 additions & 1 deletion rust/tests/behaviour/steps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ features = {}

[dependencies.typedb-driver]
path = "../../../../rust"
features = []
features = ["sync"]
default-features = false

[dependencies.futures]
features = ["alloc", "async-await", "default", "executor", "futures-executor", "std", "thread-pool"]
Expand Down
34 changes: 13 additions & 21 deletions rust/tests/behaviour/steps/connection/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,16 @@

use std::collections::HashSet;

use cucumber::{gherkin::Step, given, then, when};
use futures::{
future::{join_all, try_join_all},
stream, StreamExt, TryFutureExt,
};
use cucumber::gherkin::Step;
use futures::future::join_all;
use macro_rules_attribute::apply;
use tokio::time::sleep;
use typedb_driver::{Database, DatabaseManager, Result as TypeDBResult, TypeDBDriver};
use typedb_driver::{Database, TypeDBDriver};

use crate::{assert_with_timeout, generic_step, params, util::iter_table, Context};

async fn create_database(driver: &TypeDBDriver, name: String, may_error: params::MayError) {
may_error.check(driver.databases().create(name).await);
may_error.check(driver.databases().create(name));
}

#[apply(generic_step)]
Expand Down Expand Up @@ -67,32 +64,30 @@ async fn connection_create_databases_in_parallel(context: &mut Context, step: &S
#[apply(generic_step)]
#[step(expr = "connection delete database: {word}{may_error}")]
pub async fn connection_delete_database(context: &mut Context, name: String, may_error: params::MayError) {
may_error.check(context.driver.as_ref().unwrap().databases().get(name).and_then(Database::delete).await);
may_error.check(context.driver.as_ref().unwrap().databases().get(name).and_then(Database::delete));
}

#[apply(generic_step)]
#[step(expr = "connection delete database(s):")]
async fn connection_delete_databases(context: &mut Context, step: &Step) {
for name in iter_table(step) {
context.driver.as_ref().unwrap().databases().get(name).and_then(Database::delete).await.unwrap();
context.driver.as_ref().unwrap().databases().get(name).and_then(Database::delete).unwrap();
}
}

#[apply(generic_step)]
#[step(expr = "connection delete databases in parallel:")]
async fn connection_delete_databases_in_parallel(context: &mut Context, step: &Step) {
try_join_all(
iter_table(step).map(|name| context.driver.as_ref().unwrap().databases().get(name).and_then(Database::delete)),
)
.await
.unwrap();
for name in iter_table(step) {
context.driver.as_ref().unwrap().databases().get(name).and_then(Database::delete).unwrap();
}
}

#[apply(generic_step)]
#[step(expr = "connection has database: {word}")]
async fn connection_has_database(context: &mut Context, name: String) {
assert_with_timeout!(
context.driver.as_ref().unwrap().databases().contains(name.clone()).await.unwrap(),
context.driver.as_ref().unwrap().databases().contains(name.clone()).unwrap(),
"Connection doesn't contain database {name}.",
);
}
Expand All @@ -101,17 +96,14 @@ async fn connection_has_database(context: &mut Context, name: String) {
#[step(expr = "connection has database(s):")]
async fn connection_has_databases(context: &mut Context, step: &Step) {
let names: HashSet<String> = iter_table(step).map(|name| name.to_owned()).collect();
assert_with_timeout!(
context.all_databases().await == names,
"Connection doesn't contain at least one of the databases.",
);
assert_with_timeout!(context.all_databases() == names, "Connection doesn't contain at least one of the databases.",);
}

#[apply(generic_step)]
#[step(expr = "connection does not have database: {word}")]
async fn connection_does_not_have_database(context: &mut Context, name: String) {
assert_with_timeout!(
!context.driver.as_ref().unwrap().databases().contains(name.clone()).await.unwrap(),
!context.driver.as_ref().unwrap().databases().contains(name.clone()).unwrap(),
"Connection contains database {name}.",
);
}
Expand All @@ -120,7 +112,7 @@ async fn connection_does_not_have_database(context: &mut Context, name: String)
#[step(expr = "connection does not have database(s):")]
async fn connection_does_not_have_databases(context: &mut Context, step: &Step) {
assert_with_timeout!(
stream::iter(iter_table(step)).all(|name| async { !context.all_databases().await.contains(name) }).await,
iter_table(step).all(|name| !context.all_databases().contains(name)),
"Connection contains at least one of the databases.",
)
}
12 changes: 5 additions & 7 deletions rust/tests/behaviour/steps/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@
* under the License.
*/

use cucumber::{given, then, when};
use macro_rules_attribute::apply;
use tokio::time::sleep;
use typedb_driver::{Credential, TypeDBDriver};

use crate::{assert_with_timeout, generic_step, params, params::check_boolean, Context};
use crate::{generic_step, params, params::check_boolean, Context};

mod database;
mod transaction;
Expand Down Expand Up @@ -70,7 +67,8 @@ async fn connection_opens_with_a_wrong_host(context: &mut Context, may_error: pa
.await
}
true => {
let updated_address = change_host(Context::DEFAULT_CLOUD_ADDRESSES.get(0).unwrap(), "surely-not-localhost");
let updated_address =
change_host(Context::DEFAULT_CLOUD_ADDRESSES.first().unwrap(), "surely-not-localhost");
context
.create_cloud_driver(&[&updated_address], Some(Context::ADMIN_USERNAME), Some(Context::ADMIN_PASSWORD))
.await
Expand All @@ -92,7 +90,7 @@ async fn connection_opens_with_a_wrong_port(context: &mut Context, may_error: pa
.await
}
true => {
let updated_address = change_port(Context::DEFAULT_CLOUD_ADDRESSES.get(0).unwrap(), "0");
let updated_address = change_port(Context::DEFAULT_CLOUD_ADDRESSES.first().unwrap(), "0");
context
.create_cloud_driver(&[&updated_address], Some(Context::ADMIN_USERNAME), Some(Context::ADMIN_PASSWORD))
.await
Expand All @@ -109,7 +107,7 @@ async fn connection_has_been_opened(context: &mut Context, is_open: params::Bool
#[apply(generic_step)]
#[step(expr = r"connection has {int} database(s)")]
async fn connection_has_count_databases(context: &mut Context, count: usize) {
assert_eq!(context.driver.as_ref().unwrap().databases().all().await.unwrap().len(), count);
assert_eq!(context.driver.as_ref().unwrap().databases().all().unwrap().len(), count);
}

#[apply(generic_step)]
Expand Down
12 changes: 6 additions & 6 deletions rust/tests/behaviour/steps/connection/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
* under the License.
*/

use std::{collections::VecDeque, time::Duration};
use std::collections::VecDeque;

use cucumber::{gherkin::Step, given, then, when};
use cucumber::gherkin::Step;
use futures::{future::join_all, FutureExt};
use macro_rules_attribute::apply;
use typedb_driver::{Result as TypeDBResult, Transaction, TransactionType, TypeDBDriver};
use typedb_driver::{resolve, Result as TypeDBResult, Transaction, TransactionType, TypeDBDriver};

use crate::{generic_step, params, params::check_boolean, util::iter_table, Context};

Expand All @@ -31,7 +31,7 @@ async fn open_transaction_for_database(
database_name: impl AsRef<str>,
transaction_type: TransactionType,
) -> TypeDBResult<Transaction> {
driver.as_ref().unwrap().transaction(database_name, transaction_type).await
driver.as_ref().unwrap().transaction(database_name, transaction_type)
}

#[apply(generic_step)]
Expand Down Expand Up @@ -100,7 +100,7 @@ pub async fn transactions_have_type(context: &mut Context, step: &Step) {
#[apply(generic_step)]
#[step(expr = "transaction commits{may_error}")]
pub async fn transaction_commits(context: &mut Context, may_error: params::MayError) {
may_error.check(context.take_transaction().commit().await);
may_error.check(resolve!(context.take_transaction().commit()));
}

#[apply(generic_step)]
Expand All @@ -112,5 +112,5 @@ pub async fn transaction_closes(context: &mut Context) {
#[apply(generic_step)]
#[step(expr = "transaction rollbacks{may_error}")]
pub async fn transaction_rollbacks(context: &mut Context, may_error: params::MayError) {
may_error.check(context.transaction().rollback().await);
may_error.check(resolve!(context.transaction().rollback()));
}
53 changes: 21 additions & 32 deletions rust/tests/behaviour/steps/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
#![deny(elided_lifetimes_in_paths)]

use std::{
collections::{HashMap, HashSet, VecDeque},
env::VarError,
collections::{HashSet, VecDeque},
error::Error,
fmt,
fmt::Formatter,
Expand All @@ -32,16 +31,14 @@ use std::{

use cucumber::{gherkin::Feature, StatsWriter, World};
use futures::{
future::{try_join_all, Either},
future::Either,
stream::{self, StreamExt},
};
use itertools::Itertools;
use tokio::time::{sleep, Duration};
use typedb_driver::{
answer::{ConceptDocument, ConceptRow, QueryAnswer, QueryType, JSON},
concept::Value,
BoxStream, Credential, Database, DatabaseManager, Options, Result as TypeDBResult, Transaction, TypeDBDriver,
UserManager,
answer::{ConceptDocument, ConceptRow, QueryAnswer, QueryType},
BoxStream, Credential, Options, Result as TypeDBResult, Transaction, TypeDBDriver,
};

use crate::params::QueryAnswerType;
Expand Down Expand Up @@ -185,13 +182,12 @@ impl Context {
Ok(())
}

pub async fn all_databases(&self) -> HashSet<String> {
pub fn all_databases(&self) -> HashSet<String> {
self.driver
.as_ref()
.unwrap()
.databases()
.all()
.await
.unwrap()
.into_iter()
.map(|db| db.name().to_owned())
Expand All @@ -203,9 +199,9 @@ impl Context {
self.create_default_driver(Some(Self::ADMIN_USERNAME), Some(Self::ADMIN_PASSWORD)).await.unwrap();
}

try_join_all(self.driver.as_ref().unwrap().databases().all().await.unwrap().into_iter().map(|db| db.delete()))
.await
.unwrap();
for db in self.driver.as_ref().unwrap().databases().all().unwrap() {
db.delete().unwrap()
}
}

pub async fn cleanup_transactions(&mut self) {
Expand All @@ -215,24 +211,17 @@ impl Context {
}

pub async fn cleanup_users(&mut self) {
if self.driver.is_none() || !self.driver.as_ref().unwrap().is_open() {
let driver = self.driver.as_ref().unwrap();
if self.driver.is_none() || !driver.is_open() {
return;
}

try_join_all(
self.driver
.as_ref()
.unwrap()
.users()
.all()
.await
.unwrap()
.into_iter()
.filter(|user| user.username != Context::ADMIN_USERNAME)
.map(|user| self.driver.as_ref().unwrap().users().delete(user.username)),
)
.await
.ok();
for user in driver.users().all().unwrap() {
if user.username == Context::ADMIN_USERNAME {
continue;
}
driver.users().delete(user.username).ok();
}
}

pub async fn cleanup_answers(&mut self) {
Expand All @@ -249,11 +238,11 @@ impl Context {
}

pub fn transaction_opt(&self) -> Option<&Transaction> {
self.transactions.get(0)
self.transactions.front()
}

pub fn transaction(&self) -> &Transaction {
self.transactions.get(0).unwrap()
self.transactions.front().unwrap()
}

pub fn take_transaction(&mut self) -> Transaction {
Expand Down Expand Up @@ -308,7 +297,7 @@ impl Context {

pub async fn unwrap_answer_into_rows(&mut self) {
self.collected_rows =
Some(self.answer.take().unwrap().into_rows().map(|result| result.unwrap()).collect::<Vec<_>>().await);
Some(self.answer.take().unwrap().into_rows().map(|result| result.unwrap()).collect::<Vec<_>>());
}

pub async fn unwrap_concurrent_answers_into_rows_streams(&mut self) {
Expand All @@ -318,7 +307,7 @@ impl Context {

pub async fn unwrap_answer_into_documents(&mut self) {
self.collected_documents =
Some(self.answer.take().unwrap().into_documents().map(|result| result.unwrap()).collect::<Vec<_>>().await);
Some(self.answer.take().unwrap().into_documents().map(|result| result.unwrap()).collect::<Vec<_>>());
}

pub async fn get_answer(&self) -> Option<&QueryAnswer> {
Expand Down Expand Up @@ -381,7 +370,7 @@ impl Context {
_password: Option<&str>,
) -> TypeDBResult {
assert!(!self.is_cloud);
let driver = TypeDBDriver::new_core(address).await?;
let driver = TypeDBDriver::new_core(address)?;
self.driver = Some(driver);
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions rust/tests/behaviour/steps/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

use std::{borrow::Borrow, convert::Infallible, fmt, ops::Not, str::FromStr};
use std::{borrow::Borrow, convert::Infallible, fmt, str::FromStr};

use chrono::{FixedOffset, NaiveDate, NaiveDateTime, NaiveTime};
use cucumber::Parameter;
Expand Down Expand Up @@ -295,7 +295,7 @@ macro_rules! check_boolean {
pub(crate) use check_boolean;
use typedb_driver::concept::{
value::{Decimal, TimeZone},
Concept, ConceptCategory,
Concept,
};

impl FromStr for Boolean {
Expand Down
Loading