Client can now perform requests asynchronously
This commit is contained in:
22
tests/mod.rs
22
tests/mod.rs
@@ -30,7 +30,7 @@ enum TestProtocol {
|
||||
async fn main() {
|
||||
let (qtx, qrx) = mpsc::channel(16);
|
||||
let (atx, arx) = mpsc::channel(16);
|
||||
let mut client = TestProtocolClient::new(qtx, arx);
|
||||
let client = TestProtocolClient::new(qtx, arx);
|
||||
let server = tokio::spawn(server_loop(qrx, atx));
|
||||
let result = client.addition(2, 5).await.unwrap();
|
||||
assert_eq!(result, 7);
|
||||
@@ -86,3 +86,23 @@ async fn server_loop(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn heavy_async() {
|
||||
let (qtx, qrx) = mpsc::channel(16);
|
||||
let (atx, arx) = mpsc::channel(16);
|
||||
let client = TestProtocolClient::new(qtx, arx);
|
||||
let server = tokio::spawn(server_loop(qrx, atx));
|
||||
let mut tasks = Vec::new();
|
||||
for i in 0..100 {
|
||||
let client = client.clone();
|
||||
tasks.push(tokio::spawn(async move {
|
||||
let result = client.addition(i, i).await.unwrap();
|
||||
assert_eq!(result, i + i);
|
||||
}));
|
||||
}
|
||||
for task in tasks {
|
||||
task.await.unwrap();
|
||||
}
|
||||
server.abort();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user