Skip to content

Commit 6f7b147

Browse files
committed
test: add a "raw" test
this is really just an example Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
1 parent b36893f commit 6f7b147

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ futures = { workspace = true }
9999
tempfile = { workspace = true }
100100
test-log = { workspace = true, features = ["color", "log", "trace"] }
101101
tokio = { workspace = true, features = ["process", "rt-multi-thread"] }
102+
tokio-util = { workspace = true }
102103
wasmtime = { workspace = true }
103104
wasmtime-wasi = { workspace = true }
104105
wasmtime-cli-flags = { workspace = true, features = [

crates/pack/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "wrpc-pack"
3-
version = "0.3.1"
3+
version = "0.4.0"
44
description = "Temporary stopgap solution for encoding fully-synchronous wRPC values"
55

66
authors.workspace = true

tests/rust.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,53 @@ where
13271327
Ok(())
13281328
}
13291329

1330+
#[test_log::test(tokio::test(flavor = "multi_thread"))]
1331+
#[instrument(ret)]
1332+
async fn rust_oneshot_raw() -> anyhow::Result<()> {
1333+
let (clt, mut srv) = tokio::io::duplex(1024);
1334+
1335+
join!(
1336+
async {
1337+
let (a,) = Oneshot::from(clt)
1338+
.invoke_values_blocking::<_, _, (String,)>((), "foo", "bar", (42,), &[[]; 0])
1339+
.await
1340+
.expect("failed to invoke `foo.bar`");
1341+
assert_eq!(a, "test");
1342+
},
1343+
async {
1344+
use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _};
1345+
use tokio_util::codec::Encoder as _;
1346+
use wrpc_transport::Encode as _;
1347+
1348+
let mut req = Vec::default();
1349+
_ = srv.read_to_end(&mut req).await;
1350+
eprintln!("request: `{:?}`", Bytes::from(req));
1351+
1352+
let mut data = bytes::BytesMut::default();
1353+
let deferred: Option<wrpc_transport::DeferredFn<wrpc_transport::frame::Outgoing>> =
1354+
("test",)
1355+
.encode(&mut Default::default(), &mut data)
1356+
.expect("failed to encode");
1357+
assert!(deferred.is_none());
1358+
1359+
let mut res = bytes::BytesMut::default();
1360+
wrpc_transport::FrameEncoder
1361+
.encode(
1362+
&wrpc_transport::Frame {
1363+
path: Arc::default(),
1364+
data: data.freeze(),
1365+
},
1366+
&mut res,
1367+
)
1368+
.expect("failed to encode response frame");
1369+
eprintln!("response: `{res:?}`");
1370+
1371+
srv.write_all(&res).await.expect("failed to write response");
1372+
}
1373+
);
1374+
Ok(())
1375+
}
1376+
13301377
#[test_log::test(tokio::test(flavor = "multi_thread"))]
13311378
#[instrument(ret)]
13321379
async fn rust_oneshot_duplex() -> anyhow::Result<()> {

0 commit comments

Comments
 (0)