Skip to content

Commit

Permalink
RSCBC-73: Rework test framework for couchbase crate
Browse files Browse the repository at this point in the history
  • Loading branch information
chvck committed Jan 16, 2025
1 parent d7ee61b commit 4e2fc7a
Show file tree
Hide file tree
Showing 14 changed files with 1,119 additions and 1,212 deletions.
2 changes: 1 addition & 1 deletion sdk/couchbase/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ env_logger = "0.11"
envconfig = "0.11.0"
rand = "0.9.0-beta.0"
serde_json = { version = "1.0", features = ["raw_value"] }
serde_yaml = "0.9"
serde_yaml = "0.9.33"
tokio = "1.40"

[features]
Expand Down
131 changes: 58 additions & 73 deletions sdk/couchbase/benches/collection_crud.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::common::test_config::{setup_tests, test_bucket, test_collection, test_scope};
use crate::common::{create_cluster_from_test_config, new_key};
use crate::common::new_key;
use crate::common::test_config::create_test_cluster;
use couchbase::transcoding;
use criterion::{criterion_group, criterion_main, Criterion};
use log::LevelFilter;
use std::time::Duration;

#[path = "../tests/common/mod.rs"]
Expand All @@ -12,13 +11,12 @@ fn upsert(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();

let collection = rt.block_on(async {
setup_tests(LevelFilter::Off).await;
let cluster = create_cluster_from_test_config().await;
let cluster = create_test_cluster().await;

cluster
.bucket(test_bucket().await)
.scope(test_scope().await)
.collection(test_collection().await)
.bucket(&cluster.default_bucket)
.scope(&cluster.default_scope)
.collection(&cluster.default_collection)
});

let key = new_key();
Expand All @@ -34,13 +32,12 @@ fn insert(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();

let collection = rt.block_on(async {
setup_tests(LevelFilter::Off).await;
let cluster = create_cluster_from_test_config().await;
let cluster = create_test_cluster().await;

cluster
.bucket(test_bucket().await)
.scope(test_scope().await)
.collection(test_collection().await)
.bucket(&cluster.default_bucket)
.scope(&cluster.default_scope)
.collection(&cluster.default_collection)
});

let key = new_key();
Expand All @@ -56,13 +53,12 @@ fn replace(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();

let collection = rt.block_on(async {
setup_tests(LevelFilter::Off).await;
let cluster = create_cluster_from_test_config().await;
let cluster = create_test_cluster().await;

cluster
.bucket(test_bucket().await)
.scope(test_scope().await)
.collection(test_collection().await)
.bucket(&cluster.default_bucket)
.scope(&cluster.default_scope)
.collection(&cluster.default_collection)
});

let key = new_key();
Expand All @@ -82,13 +78,12 @@ fn remove(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();

let collection = rt.block_on(async {
setup_tests(LevelFilter::Off).await;
let cluster = create_cluster_from_test_config().await;
let cluster = create_test_cluster().await;

cluster
.bucket(test_bucket().await)
.scope(test_scope().await)
.collection(test_collection().await)
.bucket(&cluster.default_bucket)
.scope(&cluster.default_scope)
.collection(&cluster.default_collection)
});

let key = new_key();
Expand All @@ -105,13 +100,12 @@ fn exists(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();

let collection = rt.block_on(async {
setup_tests(LevelFilter::Off).await;
let cluster = create_cluster_from_test_config().await;
let cluster = create_test_cluster().await;

cluster
.bucket(test_bucket().await)
.scope(test_scope().await)
.collection(test_collection().await)
.bucket(&cluster.default_bucket)
.scope(&cluster.default_scope)
.collection(&cluster.default_collection)
});

let key = new_key();
Expand All @@ -128,13 +122,12 @@ fn get(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();

let collection = rt.block_on(async {
setup_tests(LevelFilter::Off).await;
let cluster = create_cluster_from_test_config().await;
let cluster = create_test_cluster().await;

cluster
.bucket(test_bucket().await)
.scope(test_scope().await)
.collection(test_collection().await)
.bucket(&cluster.default_bucket)
.scope(&cluster.default_scope)
.collection(&cluster.default_collection)
});

let key = new_key();
Expand All @@ -151,13 +144,12 @@ fn get_and_touch(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();

let collection = rt.block_on(async {
setup_tests(LevelFilter::Off).await;
let cluster = create_cluster_from_test_config().await;
let cluster = create_test_cluster().await;

cluster
.bucket(test_bucket().await)
.scope(test_scope().await)
.collection(test_collection().await)
.bucket(&cluster.default_bucket)
.scope(&cluster.default_scope)
.collection(&cluster.default_collection)
});

let key = new_key();
Expand All @@ -177,13 +169,12 @@ fn get_and_lock(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();

let collection = rt.block_on(async {
setup_tests(LevelFilter::Off).await;
let cluster = create_cluster_from_test_config().await;
let cluster = create_test_cluster().await;

cluster
.bucket(test_bucket().await)
.scope(test_scope().await)
.collection(test_collection().await)
.bucket(&cluster.default_bucket)
.scope(&cluster.default_scope)
.collection(&cluster.default_collection)
});

let key = new_key();
Expand All @@ -203,13 +194,12 @@ fn unlock(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();

let collection = rt.block_on(async {
setup_tests(LevelFilter::Off).await;
let cluster = create_cluster_from_test_config().await;
let cluster = create_test_cluster().await;

cluster
.bucket(test_bucket().await)
.scope(test_scope().await)
.collection(test_collection().await)
.bucket(&cluster.default_bucket)
.scope(&cluster.default_scope)
.collection(&cluster.default_collection)
});

let key = new_key();
Expand All @@ -232,13 +222,12 @@ fn touch(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();

let collection = rt.block_on(async {
setup_tests(LevelFilter::Off).await;
let cluster = create_cluster_from_test_config().await;
let cluster = create_test_cluster().await;

cluster
.bucket(test_bucket().await)
.scope(test_scope().await)
.collection(test_collection().await)
.bucket(&cluster.default_bucket)
.scope(&cluster.default_scope)
.collection(&cluster.default_collection)
});

let key = new_key();
Expand All @@ -258,13 +247,12 @@ fn append(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();

let collection = rt.block_on(async {
setup_tests(LevelFilter::Off).await;
let cluster = create_cluster_from_test_config().await;
let cluster = create_test_cluster().await;

cluster
.bucket(test_bucket().await)
.scope(test_scope().await)
.collection(test_collection().await)
.bucket(&cluster.default_bucket)
.scope(&cluster.default_scope)
.collection(&cluster.default_collection)
});

let key = new_key();
Expand All @@ -291,13 +279,12 @@ fn prepend(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();

let collection = rt.block_on(async {
setup_tests(LevelFilter::Off).await;
let cluster = create_cluster_from_test_config().await;
let cluster = create_test_cluster().await;

cluster
.bucket(test_bucket().await)
.scope(test_scope().await)
.collection(test_collection().await)
.bucket(&cluster.default_bucket)
.scope(&cluster.default_scope)
.collection(&cluster.default_collection)
});

let key = new_key();
Expand All @@ -324,13 +311,12 @@ fn increment(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();

let collection = rt.block_on(async {
setup_tests(LevelFilter::Off).await;
let cluster = create_cluster_from_test_config().await;
let cluster = create_test_cluster().await;

cluster
.bucket(test_bucket().await)
.scope(test_scope().await)
.collection(test_collection().await)
.bucket(&cluster.default_bucket)
.scope(&cluster.default_scope)
.collection(&cluster.default_collection)
});

let key = new_key();
Expand All @@ -347,13 +333,12 @@ fn decrement(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();

let collection = rt.block_on(async {
setup_tests(LevelFilter::Off).await;
let cluster = create_cluster_from_test_config().await;
let cluster = create_test_cluster().await;

cluster
.bucket(test_bucket().await)
.scope(test_scope().await)
.collection(test_collection().await)
.bucket(&cluster.default_bucket)
.scope(&cluster.default_scope)
.collection(&cluster.default_collection)
});

let key = new_key();
Expand Down
9 changes: 2 additions & 7 deletions sdk/couchbase/benches/query.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
use crate::common::create_cluster_from_test_config;
use crate::common::test_config::setup_tests;
use crate::common::test_config::create_test_cluster;
use criterion::{criterion_group, criterion_main, Criterion};
use log::LevelFilter;

#[path = "../tests/common/mod.rs"]
mod common;

fn query(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();

let cluster = rt.block_on(async {
setup_tests(LevelFilter::Off).await;
create_cluster_from_test_config().await
});
let cluster = rt.block_on(async { create_test_cluster().await });

c.bench_function("query", |b| {
b.to_async(&rt).iter(|| async {
Expand Down
Loading

0 comments on commit 4e2fc7a

Please sign in to comment.