Skip to content

Commit

Permalink
fix(tests): use UnsyncBoxBody
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Dec 16, 2023
1 parent a1292b1 commit f77d730
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
5 changes: 3 additions & 2 deletions viz-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,18 @@ otel-metrics = ["otel", "opentelemetry?/metrics"]

[dependencies]
async-trait.workspace = true
bytes.workspace = true
dyn-clone.workspace = true
futures-util.workspace = true

bytes.workspace = true
headers.workspace = true
http.workspace = true
http-body.workspace = true
http-body-util.workspace = true

hyper.workspace = true
hyper-util.workspace = true
sync_wrapper = { version = "0.1.2", git = "https://github.com/fundon/sync_wrapper.git", rev = "e2ce8d8" }

mime.workspace = true
thiserror.workspace = true
Expand Down Expand Up @@ -99,7 +101,6 @@ tokio = { workspace = true, optional = true }
tokio-tungstenite = { workspace = true, optional = true }
tokio-stream = { workspace = true, optional = true }
tokio-util = { workspace = true, optional = true }
sync_wrapper = { version = "0.1.2", git = "https://github.com/fundon/sync_wrapper.git", rev = "e2ce8d8" }

[dev-dependencies]
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
Expand Down
16 changes: 9 additions & 7 deletions viz-test/tests/body.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use http_body_util::{combinators::BoxBody, BodyExt, Full};
use http_body_util::{combinators::UnsyncBoxBody, BodyExt, Full};
use viz::{Bytes, Error, IncomingBody, OutgoingBody, Request, RequestExt, Result};

#[tokio::test]
Expand Down Expand Up @@ -176,21 +176,22 @@ async fn outgoing_body() -> Result<()> {
);
assert!(full_some.frame().await.is_none());

let mut boxed: OutgoingBody = BoxBody::new(Full::new(Bytes::new()).map_err(Into::into)).into();
let mut boxed: OutgoingBody =
UnsyncBoxBody::new(Full::new(Bytes::new()).map_err(Into::into)).into();
assert!(boxed.is_end_stream());
let size_hint = boxed.size_hint();
assert_eq!(size_hint.lower(), 0);
assert_eq!(size_hint.upper(), Some(0));
assert_eq!(&format!("{boxed:?}"), r"Boxed(BoxBody)");
assert_eq!(&format!("{boxed:?}"), r"Boxed(SyncWrapper)");
assert!(boxed.frame().await.is_none());

let mut boxed: OutgoingBody =
BoxBody::new(Full::new(Bytes::from(vec![2, 0, 4, 8])).map_err(Into::into)).into();
UnsyncBoxBody::new(Full::new(Bytes::from(vec![2, 0, 4, 8])).map_err(Into::into)).into();
assert!(!boxed.is_end_stream());
let size_hint = boxed.size_hint();
assert_eq!(size_hint.lower(), 4);
assert_eq!(size_hint.upper(), Some(4));
assert_eq!(&format!("{boxed:?}"), r"Boxed(BoxBody)");
assert_eq!(&format!("{boxed:?}"), r"Boxed(SyncWrapper)");
assert_eq!(
boxed
.frame()
Expand Down Expand Up @@ -231,15 +232,16 @@ async fn outgoing_stream() -> Result<()> {
assert_eq!(full_some.size_hint(), (0, Some(0)));
assert!(full_some.next().await.is_none());

let boxed: OutgoingBody = BoxBody::new(Full::new(Bytes::new()).map_err(Into::into)).into();
let boxed: OutgoingBody =
UnsyncBoxBody::new(Full::new(Bytes::new()).map_err(Into::into)).into();
assert_eq!(boxed.size_hint(), (0, Some(0)));
let mut reader = boxed.into_async_read();
let mut buf = Vec::new();
reader.read_to_end(&mut buf).await?;
assert!(buf.is_empty());

let mut boxed: OutgoingBody =
BoxBody::new(Full::new(Bytes::from(vec![2, 0, 4, 8])).map_err(Into::into)).into();
UnsyncBoxBody::new(Full::new(Bytes::from(vec![2, 0, 4, 8])).map_err(Into::into)).into();
assert_eq!(boxed.size_hint(), (4, Some(4)));
assert_eq!(boxed.next().await.unwrap().unwrap(), vec![2, 0, 4, 8]);
assert_eq!(boxed.size_hint(), (0, Some(0)));
Expand Down

0 comments on commit f77d730

Please sign in to comment.