Skip to content

Commit 49d0e47

Browse files
committed
test: refactor and use channels
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 9336743 commit 49d0e47

File tree

2 files changed

+131
-78
lines changed

2 files changed

+131
-78
lines changed

tap-agent/src/agent/sender_accounts_manager.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,8 @@ mod tests {
598598
use sqlx::postgres::PgListener;
599599
use sqlx::PgPool;
600600
use std::collections::{HashMap, HashSet};
601-
use std::sync::{Arc, Mutex};
602601
use std::time::Duration;
602+
use tokio::sync::mpsc;
603603

604604
const DUMMY_URL: &str = "http://localhost:1234";
605605

@@ -931,12 +931,12 @@ mod tests {
931931
PREFIX_ID.fetch_add(1, std::sync::atomic::Ordering::SeqCst)
932932
);
933933

934-
let last_message_emitted = Arc::new(Mutex::new(vec![]));
934+
let (last_message_emitted, mut rx) = mpsc::channel(64);
935935

936936
let (sender_account, join_handle) = MockSenderAccount::spawn(
937937
Some(format!("{}:{}", prefix.clone(), SENDER.1,)),
938938
MockSenderAccount {
939-
last_message_emitted: last_message_emitted.clone(),
939+
last_message_emitted,
940940
},
941941
(),
942942
)
@@ -958,8 +958,8 @@ mod tests {
958958
tokio::time::sleep(Duration::from_millis(10)).await;
959959

960960
assert_eq!(
961-
last_message_emitted.lock().unwrap().last().unwrap(),
962-
&SenderAccountMessage::NewAllocationId(*ALLOCATION_ID_0)
961+
rx.recv().await.unwrap(),
962+
SenderAccountMessage::NewAllocationId(*ALLOCATION_ID_0)
963963
);
964964
sender_account.stop_and_wait(None, None).await.unwrap();
965965
join_handle.await.unwrap();

0 commit comments

Comments
 (0)