diff --git a/CHANGELOG.md b/CHANGELOG.md index dd75016..3871605 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- `TraverseConfig::in_bounds` takes a slice instead of a `&Vec` now. +- Bumped upstream dependencies. +- Fixed broken python tests. FFI requires tokio now. - Work around some broken python & FFI tests ### Removed diff --git a/Cargo.toml b/Cargo.toml index 25f3890..53cfc38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,21 +40,15 @@ thiserror = "1.0.50" tokio = { version = "1.34.0", features = ["macros", "rt", "sync"] } tokio-stream = "0.1.14" tracing = "0.1.40" -uniffi = { version = "0.26.1", features = ["cli"], optional = true } +uniffi = { version = "0.26.1", features = ["cli", "tokio"], optional = true } [dependencies.replicator] -#path = "../replicator/replicator" git = "https://github.com/cowlicks/replicator.git" -# TODO onyl used in the tests, but duplicating this for dev-dependencies is annoying -features = ["utils"] [dependencies.hypercore] -#version = "0.13.0" -#path = "../core" -git = "https://github.com/cowlicks/hypercore.git" -branch = "replication" +version = "0.14.0" default-features = false -features = ["sparse", "tokio"] +features = ["sparse", "tokio", "replication"] [build-dependencies] prost-build = "0.12.1" @@ -68,3 +62,7 @@ random-access-memory = "3.0.0" once_cell = "1.19.0" tempfile = "3.10.0" serde_json = "1.0.114" + +[dev-dependencies.replicator] +git = "https://github.com/cowlicks/replicator.git" +features = ["utils"] diff --git a/src/ffi.rs b/src/ffi.rs index fdda5d1..e4ec090 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -39,7 +39,7 @@ struct Hyperbee { rust_hyperbee: Shared, } -#[uniffi::export] +#[uniffi::export(async_runtime = "tokio")] impl Hyperbee { /// The number of blocks in the hypercore. /// The first block is always the header block so: @@ -101,7 +101,7 @@ async fn hyperbee_from_ram() -> Result { } /// Helper for creating a Hyperbee from the provided path to a storage directory -#[uniffi::export] +#[uniffi::export(async_runtime = "tokio")] async fn hyperbee_from_storage_dir(path_to_storage_dir: &str) -> Result { let rust_hyperbee = RustHyperbee::from_storage_dir(path_to_storage_dir).await?; Ok(Hyperbee { @@ -114,7 +114,7 @@ struct Prefixed { rust_prefixed: Shared, } -#[uniffi::export] +#[uniffi::export(async_runtime = "tokio")] impl Prefixed { /// Get the value associated with the provided key plus this [`Prefixed`]'s instance's `prefix` async fn get(&self, key: &[u8]) -> Result, HyperbeeError> { diff --git a/src/traverse.rs b/src/traverse.rs index b83a54f..dbb21f7 100644 --- a/src/traverse.rs +++ b/src/traverse.rs @@ -216,7 +216,7 @@ async fn make_child_key_index_iter( } impl TraverseConfig { - fn in_bounds(&self, value: &Vec) -> bool { + fn in_bounds(&self, value: &[u8]) -> bool { // TODO impl Ord for LimitValue and remove the expects match self .min_value @@ -308,7 +308,7 @@ async fn get_child_stream<'a>( Ok(Traverse::new(child, config)) } -impl<'a> Stream for Traverse<'a> { +impl Stream for Traverse<'_> { type Item = TreeItem; #[tracing::instrument(skip(self, cx))] fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { diff --git a/src/tree.rs b/src/tree.rs index 9b9092b..b6a0f71 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -214,12 +214,7 @@ mod test { ); Ok(()) } -} -#[cfg(feature = "debug")] -#[cfg(test)] -mod test { - use super::*; - + #[cfg(feature = "debug")] #[tokio::test] async fn height_zero() -> Result<(), HyperbeeError> { let tree = Tree::from_ram().await?; diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 63d9839..35efe3d 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -146,12 +146,16 @@ macro_rules! write_range_to_hb { pub(crate) use write_range_to_hb; pub fn check_cmd_output(out: Output) -> Result { - eprint!("{}", String::from_utf8_lossy(&out.stdout)); if out.status.code() != Some(0) { + if !out.stdout.is_empty() { + eprintln!("stdout:\n{}", String::from_utf8_lossy(&out.stdout)); + } + if !out.stderr.is_empty() { + eprintln!("stderr:\n{}", String::from_utf8_lossy(&out.stderr)); + } return Err(Box::new(Error::TestError(format!( - "comand output status was not zero. Got:\nstdout: {}\nstderr: {}", - String::from_utf8_lossy(&out.stdout), - String::from_utf8_lossy(&out.stderr), + "command output status was not zero. Got:{:?}", + out.status.code() )))); } Ok(out) diff --git a/tests/python.rs b/tests/python.rs index e22c4a3..cc40c21 100644 --- a/tests/python.rs +++ b/tests/python.rs @@ -6,18 +6,14 @@ use common::{ }; use hyperbee::Hyperbee; -#[tokio::test] -async fn test_sub_prefix() -> Result<()> { - let x = match require_python() { - Err(e) => { - println!("{}", e); - return Err(e); - } - Ok(x) => x, - }; - dbg!(&x); - let out = run_python( - " +#[cfg(test)] +mod python { + use super::*; + #[tokio::test] + async fn test_sub_prefix() -> Result<()> { + require_python()?; + let out = run_python( + " async def main(): prefix = b'myprefix' key = b'keykey' @@ -37,18 +33,16 @@ async def main(): x = await sub_hb.get(key) assert(x.value == val_with_pref) ", - )?; - dbg!(&out); - assert_eq!(out.status.code(), Some(0)); - Ok(()) -} + )?; + assert_eq!(out.status.code(), Some(0)); + Ok(()) + } -#[tokio::test] -async fn hello_world_get_set_del() -> Result<()> { - let x = require_python()?; - dbg!(&x); - let out = run_python( - " + #[tokio::test] + async fn hello_world_get_set_del() -> Result<()> { + require_python()?; + let out = run_python( + " async def main(): hb = await hyperbee_from_ram() x = await hb.put(b'hello', b'world') @@ -61,23 +55,21 @@ async def main(): x = await hb.delete(b'hello') assert(x == 1) ", - )?; - dbg!(&out); - assert_eq!(out.status.code(), Some(0)); - Ok(()) -} - -#[tokio::test] -#[ignore] -async fn optionals() -> Result<()> { - let _x = require_python()?; - let storage_dir = tempfile::tempdir()?; - { - let hb = Hyperbee::from_storage_dir(&storage_dir).await?; - let _ = hb.put(b"hello", None).await?; + )?; + assert_eq!(out.status.code(), Some(0)); + Ok(()) } - let code = format!( - " + + #[tokio::test] + async fn optionals() -> Result<()> { + let _x = require_python()?; + let storage_dir = tempfile::tempdir()?; + { + let hb = Hyperbee::from_storage_dir(&storage_dir).await?; + let _ = hb.put(b"hello", None).await?; + } + let code = format!( + " async def main(): import json hb = await hyperbee_from_storage_dir('{}') @@ -88,19 +80,19 @@ async def main(): res = await hb.get(b'skipval') assert(res.value is None) ", - storage_dir.path().display() - ); + storage_dir.path().display() + ); - let output = run_python(&code)?; - dbg!(&output); - assert_eq!(output.status.code(), Some(0)); - Ok(()) -} -#[tokio::test] -async fn check_version() -> Result<()> { - let _x = require_python()?; - let out = run_python( - " + let output = run_python(&code)?; + assert_eq!(output.status.code(), Some(0)); + Ok(()) + } + + #[tokio::test] + async fn check_version() -> Result<()> { + let _x = require_python()?; + let out = run_python( + " async def main(): hb = await hyperbee_from_ram() x = await hb.version() @@ -109,20 +101,19 @@ async def main(): x = await hb.version() assert(x == 2) ", - )?; - assert_eq!(out.status.code(), Some(0)); - Ok(()) -} + )?; + assert_eq!(out.status.code(), Some(0)); + Ok(()) + } -#[tokio::test] -#[ignore] -async fn zero_to_one_hundred() -> Result<()> { - let _x = require_python()?; - let storage_dir = tempfile::tempdir()?; - let hb = Hyperbee::from_storage_dir(&storage_dir).await?; - let keys = write_range_to_hb!(&hb); - let code = format!( - " + #[tokio::test] + async fn zero_to_one_hundred() -> Result<()> { + let _x = require_python()?; + let storage_dir = tempfile::tempdir()?; + let hb = Hyperbee::from_storage_dir(&storage_dir).await?; + let keys = write_range_to_hb!(&hb); + let code = format!( + " async def main(): import json hb = await hyperbee_from_storage_dir('{}') @@ -131,12 +122,13 @@ async def main(): values = [res.value.decode('utf8') for res in results] print(json.dumps(values)) ", - storage_dir.path().display() - ); + storage_dir.path().display() + ); - let output = run_python(&code)?; - let res = parse_json_result(&output)?; - assert_eq!(res, keys); - assert_eq!(output.status.code(), Some(0)); - Ok(()) + let output = run_python(&code)?; + let res = parse_json_result(&output)?; + assert_eq!(res, keys); + assert_eq!(output.status.code(), Some(0)); + Ok(()) + } }