Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
shachlanAmazon committed Aug 2, 2023
1 parent ec1ab1d commit 1b4e066
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion babushka-core/tests/test_client_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ mod client_cmd_tests {

block_on_all(async {
let mut client = ClientCMD::create_client(connection_request).await.unwrap();
mocks.drain(1..config.number_of_replicas_dropped_after_connection + 1);
for mock in mocks.drain(1..config.number_of_replicas_dropped_after_connection + 1) {
mock.close().await;
}
for _ in 0..config.number_of_requests_sent {
let _ = client.send_packed_command(&cmd).await;
}
Expand Down
10 changes: 10 additions & 0 deletions babushka-core/tests/utilities/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct ServerMock {
received_commands: Arc<AtomicU16>,
runtime: Option<tokio::runtime::Runtime>, // option so that we can take the runtime on drop.
closing_signal: Arc<ManualResetEvent>,
closing_completed_signal: Arc<ManualResetEvent>,
}

async fn read_from_socket(buffer: &mut Vec<u8>, socket: &mut TcpStream) -> Option<usize> {
Expand Down Expand Up @@ -113,6 +114,8 @@ impl ServerMock {
);
let closing_signal = Arc::new(ManualResetEvent::new(false));
let closing_signal_clone = closing_signal.clone();
let closing_completed_signal = Arc::new(ManualResetEvent::new(false));
let closing_completed_signal_clone = closing_completed_signal.clone();
let runtime = tokio::runtime::Builder::new_multi_thread()
.worker_threads(1)
.thread_name(format!("ServerMock - {address}"))
Expand All @@ -134,6 +137,7 @@ impl ServerMock {
.await
{}

closing_completed_signal_clone.set();
log_warn("mocks", format!("closing {:?} mock", listener.local_addr()));
});
Self {
Expand All @@ -142,8 +146,14 @@ impl ServerMock {
received_commands,
runtime: Some(runtime),
closing_signal,
closing_completed_signal,
}
}

pub async fn close(self) {
self.closing_signal.set();
self.closing_completed_signal.wait().await;
}
}

impl Mock for ServerMock {
Expand Down

0 comments on commit 1b4e066

Please sign in to comment.