Skip to content

Commit

Permalink
fix(rust): fix unit test
Browse files Browse the repository at this point in the history
Signed-off-by: SSpirits <[email protected]>
  • Loading branch information
ShadowySpirits committed Jul 7, 2023
1 parent 0b41f27 commit 1b51834
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
7 changes: 4 additions & 3 deletions rust/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl Client {
self.transaction_checker = Some(transaction_checker);
}

pub(crate) async fn start(&mut self) {
pub(crate) async fn start(&mut self) -> Result<(), ClientError> {
let logger = self.logger.clone();
let session_manager = self.session_manager.clone();

Expand All @@ -131,7 +131,7 @@ impl Client {
// send heartbeat and handle telemetry command
let (tx, mut rx) = mpsc::channel(16);
self.telemetry_command_tx = Some(tx);
let rpc_client = self.get_session().await.unwrap();
let rpc_client = self.get_session().await?;
let endpoints = self.access_endpoints.clone();
let transaction_checker = self.transaction_checker.take();
// give a placeholder
Expand Down Expand Up @@ -189,6 +189,7 @@ impl Client {
}
}
});
Ok(())
}

async fn handle_telemetry_command<T: RPCClient + 'static>(
Expand Down Expand Up @@ -698,7 +699,7 @@ pub(crate) mod tests {
.returning(|_, _, _| Ok(Session::mock()));

let mut client = new_client_with_session_manager(session_manager);
client.start().await;
client.start().await?;

// TODO use countdown latch instead sleeping
// wait for run
Expand Down
10 changes: 7 additions & 3 deletions rust/src/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Producer {

/// Start the producer
pub async fn start(&mut self) -> Result<(), ClientError> {
self.client.start().await;
self.client.start().await?;
if let Some(topics) = self.option.topics() {
for topic in topics {
self.client.topic_route(topic, true).await?;
Expand Down Expand Up @@ -321,7 +321,7 @@ mod tests {
queue: vec![],
}))
});
client.expect_start().returning(|| ());
client.expect_start().returning(|| Ok(()));
client
.expect_client_id()
.return_const("fake_id".to_string());
Expand All @@ -348,7 +348,7 @@ mod tests {
queue: vec![],
}))
});
client.expect_start().returning(|| ());
client.expect_start().returning(|| Ok(()));
client.expect_set_transaction_checker().returning(|_| ());
client
.expect_client_id()
Expand Down Expand Up @@ -551,6 +551,10 @@ mod tests {
.client
.expect_get_session()
.return_once(|| Ok(Session::mock()));
producer
.client
.expect_has_transaction_checker()
.return_once(|| true);

let _ = producer
.send_transaction_message(
Expand Down
4 changes: 2 additions & 2 deletions rust/src/simple_consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl SimpleConsumer {
Self::OPERATION_START_SIMPLE_CONSUMER,
));
}
self.client.start().await;
self.client.start().await?;
if let Some(topics) = self.option.topics() {
for topic in topics {
self.client.topic_route(topic, true).await?;
Expand Down Expand Up @@ -198,7 +198,7 @@ mod tests {
queue: vec![],
}))
});
client.expect_start().returning(|| ());
client.expect_start().returning(|| Ok(()));
client
.expect_client_id()
.return_const("fake_id".to_string());
Expand Down

0 comments on commit 1b51834

Please sign in to comment.