Skip to content

Commit

Permalink
fix: readd crates to workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
threadexio committed Dec 17, 2023
1 parent f3d39a4 commit 0c71d04
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 25 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[workspace]
resolver = "2"
members = [
"channels",
"channels-packet",
"channels-serdes",
#"tests-integration",
#"stress-tests",
#"examples",
#"examples/chat-app",
"tests-integration",
"stress-tests",
"examples",
"examples/chat-app",
]
resolver = "2"

[workspace.dependencies]
channels = { path = "./channels", features = ["full"] }
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[downloads-badge]: https://img.shields.io/crates/d/channels?style=for-the-badge&label=downloads&labelColor=%23000&color=%23ff0089

<div align="center">
<img src=".github/images/logo.transparent.png">
<img src=".github/images/logo.transparent.png" alt="logo">

<p>
Easy and fast communication between processes, threads and systems.
Expand Down
2 changes: 1 addition & 1 deletion stress-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
publish = false

[dependencies]
channels = { workspace = true }
channels = { workspace = true, features = ["full", "tokio"] }

tokio = { version = "1", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
Expand Down
48 changes: 33 additions & 15 deletions stress-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
use std::thread;
use std::time::Duration;
use std::time::{Duration, Instant};

/// Spawn a server and a client thread and wait for them to complete.
pub fn spawn_server_client<S, C>(server: S, client: C)
pub fn spawn_server_client<S, C, So, Co>(
server: S,
client: C,
) -> (So, Co)
where
S: FnOnce() + Send + 'static,
C: FnOnce() + Send + 'static,
So: Send,
Co: Send,
S: FnOnce() -> So + Send,
C: FnOnce() -> Co + Send,
{
let t1 = thread::Builder::new()
.name("server".into())
.spawn(server)
.unwrap();
thread::scope(|scope| {
let t1 = thread::Builder::new()
.name("server".into())
.spawn_scoped(scope, server)
.unwrap();

thread::sleep(Duration::from_secs(1));
thread::sleep(Duration::from_secs(1));

let t2 = thread::Builder::new()
.name("client".into())
.spawn(client)
.unwrap();
let t2 = thread::Builder::new()
.name("client".into())
.spawn_scoped(scope, client)
.unwrap();

t2.join().unwrap();
t1.join().unwrap();
(t1.join().unwrap(), t2.join().unwrap())
})
}

/// Block until `f` returns `true`.
Expand All @@ -36,3 +42,15 @@ where
thread::sleep(Duration::from_millis(500));
}
}

/// Measure the execution time of _f_.
pub fn time<F, Output>(f: F) -> (Duration, Output)
where
F: FnOnce() -> Output,
{
let start = Instant::now();
let output = f();
let elapsed = start.elapsed();

(elapsed, output)
}
2 changes: 1 addition & 1 deletion stress-tests/tests/async_with_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ async fn client() {
fn async_with_sync() {
stress_tests::spawn_server_client(server, || {
Runtime::new().unwrap().block_on(async { client().await })
})
});
}
2 changes: 1 addition & 1 deletion stress-tests/tests/big_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ mod sync_tests {
#[serial]
#[test]
fn big_data() {
stress_tests::spawn_server_client(server, client)
stress_tests::spawn_server_client(server, client);
}
}

Expand Down
2 changes: 1 addition & 1 deletion stress-tests/tests/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ mod sync_tests {
#[serial]
#[test]
fn transport() {
stress_tests::spawn_server_client(server, client)
stress_tests::spawn_server_client(server, client);
}
}

Expand Down

0 comments on commit 0c71d04

Please sign in to comment.