Skip to content

Commit

Permalink
fix: execute requests without retries
Browse files Browse the repository at this point in the history
Closes: ryankurte#36
  • Loading branch information
apohrebniak committed Nov 2, 2023
1 parent f7cf3ca commit 8232bbd
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/backend/backend_tokio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl Tokio {
) -> Result<Option<Packet>, Error> {
// Send request and await response for the allowed number of retries
let mut resp = Ok(None);
for i in 0..opts.retries {
for i in 0..=opts.retries {
// TODO: control / bump message_id each retry?

// Encode data
Expand Down Expand Up @@ -226,7 +226,6 @@ impl Tokio {
resource: String,
opts: RequestOptions,
) -> Result<(u32, Receiver<Packet>), Error> {

// Create response channel
let (tx, mut rx) = channel(10);

Expand Down Expand Up @@ -513,4 +512,26 @@ mod test {
.unwrap();
assert_eq!(resp, b"world".to_vec());
}

#[tokio::test]
async fn tests_no_retries() {
let _ = SimpleLogger::init(LevelFilter::Debug, Config::default());

let mut client = TokioClient::connect("coap://coap.me:5683", &ClientOptions::default())
.await
.unwrap();

let opts = RequestOptions {
retries: 0,
..Default::default()
};

let resp = client
.get("hello", &RequestOptions::default())
.await
.unwrap();
assert_eq!(resp, b"world".to_vec());

client.close().await.unwrap();
}
}

0 comments on commit 8232bbd

Please sign in to comment.