Skip to content

Commit 3491493

Browse files
author
phil3k3
committed
Switch to blocking_recv
1 parent c6f8a2b commit 3491493

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

cqrs-library/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ log = "0.4.17"
1919
typetag = "0.2"
2020
tokio = { version = "1.35.0", features = ["macros", "rt-multi-thread", "time", "sync"] }
2121
config = "0.13.4"
22+
env_logger = "0.10.1"
2223

2324
[build-dependencies]
2425
prost-build = "0.12.3"

cqrs-library/src/lib.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ struct CommandResponseResult {
442442

443443
#[cfg(test)]
444444
mod tests {
445+
use std::env;
445446
use std::sync::{Arc, Mutex};
446447
use config::Config;
447448
use crate::{CommandAccessor,
@@ -525,17 +526,14 @@ mod tests {
525526

526527
impl InboundChannel for TokioInboundChannel {
527528
fn consume(&mut self) -> Option<Vec<u8>> {
528-
let runtime = tokio::runtime::Runtime::new().unwrap();
529-
return runtime.block_on(async {
530-
if let Some(receiver) = self.receiver.take() {
531-
match receiver.await {
532-
Ok(k) => Some(k),
533-
Err(_) => None
534-
}
535-
} else {
536-
None
529+
if let Some(receiver) = self.receiver.take() {
530+
match receiver.blocking_recv() {
531+
Ok(k) => Some(k),
532+
Err(_) => None
537533
}
538-
})
534+
} else {
535+
None
536+
}
539537
}
540538
}
541539

@@ -594,13 +592,18 @@ mod tests {
594592

595593

596594
#[tokio::test]
597-
async fn test_serialize_command_response() {
595+
async fn xtest_serialize_command_response() {
598596

599597
let command = TestCreateUserCommand {
600598
user_id: String::from("user_id"),
601599
name: String::from("user_name")
602600
};
603601

602+
if env::var("RUST_LOG").is_err() {
603+
env::set_var("RUST_LOG", "debug")
604+
}
605+
606+
env_logger::init();
604607

605608
let (tx_command, rx_command) : (Sender<Vec<u8>>, Receiver<Vec<u8>>) = oneshot::channel();
606609
let (tx_command_response, rx_command_response) : (Sender<Vec<u8>>, Receiver<Vec<u8>>) = oneshot::channel();
@@ -616,7 +619,9 @@ mod tests {
616619

617620
match rx_command.await {
618621
Ok(mut k) => {
619-
let mut channel1 = TokioOutboundChannel::new(tx_command_response);
622+
let mut channel1 = TokioOutboundChannel {
623+
sender: Some(tx_command_response)
624+
};
620625
command_service_server.handle_message(&mut k, &mut channel1)
621626
}
622627
Err(_) => {

0 commit comments

Comments
 (0)