Skip to content

Commit 0578206

Browse files
authored
Merge pull request #715 from Xuanwo/use-backon
chore: Use backon to replace backoff
2 parents f71185c + d906714 commit 0578206

File tree

3 files changed

+18
-134
lines changed

3 files changed

+18
-134
lines changed

Cargo.lock

Lines changed: 10 additions & 120 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ tracing = { version = "0.1.30", optional = true }
3131

3232
[dev-dependencies]
3333
async-std = { version = "1.9.0", features = ["attributes"] }
34-
backoff = "0.1.5"
34+
backon = { version = "1.2", default-features = false, features = ["std-blocking-sleep"] }
3535
chrono = "0.4.0"
3636
clap = "2.18.0"
3737
env_logger = "0.9.0"

tests/test_admin.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::time::Duration;
44

5-
use backoff::{ExponentialBackoff, Operation};
5+
use backon::{BlockingRetryable, ExponentialBuilder};
66

77
use rdkafka::admin::{
88
AdminClient, AdminOptions, AlterConfig, ConfigEntry, ConfigSource, GroupResult, NewPartitions,
@@ -75,10 +75,6 @@ fn fetch_metadata(topic: &str) -> Metadata {
7575
create_config().create().expect("consumer creation failed");
7676
let timeout = Some(Duration::from_secs(1));
7777

78-
let mut backoff = ExponentialBackoff {
79-
max_elapsed_time: Some(Duration::from_secs(5)),
80-
..Default::default()
81-
};
8278
(|| {
8379
let metadata = consumer
8480
.fetch_metadata(Some(topic), timeout)
@@ -90,9 +86,10 @@ fn fetch_metadata(topic: &str) -> Metadata {
9086
if topic.partitions().is_empty() {
9187
Err("metadata fetch returned a topic with no partitions".to_string())?
9288
}
93-
Ok(metadata)
89+
Ok::<_, String>(metadata)
9490
})
95-
.retry(&mut backoff)
91+
.retry(ExponentialBuilder::default().with_max_delay(Duration::from_secs(5)))
92+
.call()
9693
.unwrap()
9794
}
9895

@@ -101,10 +98,6 @@ fn verify_delete(topic: &str) {
10198
create_config().create().expect("consumer creation failed");
10299
let timeout = Some(Duration::from_secs(1));
103100

104-
let mut backoff = ExponentialBackoff {
105-
max_elapsed_time: Some(Duration::from_secs(5)),
106-
..Default::default()
107-
};
108101
(|| {
109102
// Asking about the topic specifically will recreate it (under the
110103
// default Kafka configuration, at least) so we have to ask for the list
@@ -115,9 +108,10 @@ fn verify_delete(topic: &str) {
115108
if metadata.topics().iter().any(|t| t.name() == topic) {
116109
Err(format!("topic {} still exists", topic))?
117110
}
118-
Ok(())
111+
Ok::<(), String>(())
119112
})
120-
.retry(&mut backoff)
113+
.retry(ExponentialBuilder::default().with_max_delay(Duration::from_secs(5)))
114+
.call()
121115
.unwrap()
122116
}
123117

0 commit comments

Comments
 (0)