Skip to content

Commit 47777ec

Browse files
committed
Print version at startup
1 parent cefe1a9 commit 47777ec

File tree

5 files changed

+47
-11
lines changed

5 files changed

+47
-11
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
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
@@ -1,6 +1,6 @@
11
[package]
22
name = "wait"
3-
version = "2.7.0"
3+
version = "2.7.1"
44
authors = ["ufoscout <[email protected]>"]
55
edition = "2018"
66

src/env_reader/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,4 @@ mod test {
4141
nanosec = nanosec + 10;
4242
assert_eq!(nanosec.to_string(), env_var(&env_key, nanosec.to_string()));
4343
}
44-
4544
}

src/lib.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,18 @@ pub fn wait(
2020
on_timeout: &mut dyn FnMut(),
2121
) {
2222
println!("{}", LINE_SEPARATOR);
23-
println!("docker-compose-wait - starting with configuration:");
23+
println!(" docker-compose-wait {}", env!("CARGO_PKG_VERSION"));
24+
println!("---------------------------");
25+
println!("Starting with configuration:");
2426
println!(" - Hosts to be waiting for: [{}]", config.hosts);
25-
println!(" - Timeout before failure: {} seconds ", config.global_timeout);
26-
println!(" - TCP connection timeout before retry: {} seconds ", config.tcp_connection_timeout);
27+
println!(
28+
" - Timeout before failure: {} seconds ",
29+
config.global_timeout
30+
);
31+
println!(
32+
" - TCP connection timeout before retry: {} seconds ",
33+
config.tcp_connection_timeout
34+
);
2735
println!(
2836
" - Sleeping time before checking for hosts availability: {} seconds",
2937
config.wait_before
@@ -51,7 +59,14 @@ pub fn wait(
5159
sleep.reset();
5260
for host in config.hosts.trim().split(',') {
5361
println!("Checking availability of {}", host);
54-
while !port_check::is_port_reachable_with_timeout(&host.trim().to_string().parse().expect("The host IP should be valid"), Duration::from_secs(config.tcp_connection_timeout)) {
62+
while !port_check::is_port_reachable_with_timeout(
63+
&host
64+
.trim()
65+
.to_string()
66+
.parse()
67+
.expect("The host IP should be valid"),
68+
Duration::from_secs(config.tcp_connection_timeout),
69+
) {
5570
println!("Host {} not yet available...", host);
5671
if sleep.elapsed(config.global_timeout) {
5772
println!(
@@ -188,7 +203,14 @@ mod test {
188203
assert_eq!(1, config.wait_sleep_interval);
189204
}
190205

191-
fn set_env(hosts: &str, timeout: &str, before: &str, after: &str, sleep: &str, tcp_timeout: &str) {
206+
fn set_env(
207+
hosts: &str,
208+
timeout: &str,
209+
before: &str,
210+
after: &str,
211+
sleep: &str,
212+
tcp_timeout: &str,
213+
) {
192214
env::set_var("WAIT_BEFORE_HOSTS", before.to_string());
193215
env::set_var("WAIT_AFTER_HOSTS", after.to_string());
194216
env::set_var("WAIT_HOSTS_TIMEOUT", timeout.to_string());

tests/integration_test.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,23 @@ fn should_wait_before_and_after() {
4747
fn should_execute_without_wait() {
4848
let start = Instant::now();
4949
let mut sleeper = MillisSleeper::default();
50-
wait::wait(&mut sleeper, &new_config("", 1, 0, 0, 1, 1), &mut on_timeout);
50+
wait::wait(
51+
&mut sleeper,
52+
&new_config("", 1, 0, 0, 1, 1),
53+
&mut on_timeout,
54+
);
5155
assert!(millis_elapsed(start) <= 5)
5256
}
5357

5458
#[test]
5559
fn should_sleep_the_specified_time_between_checks() {
5660
let start = Instant::now();
5761
let mut sleeper = MillisSleeper::default();
58-
wait::wait(&mut sleeper, &new_config("198.19.255.255:1", 2_000, 0, 0, 10, 1), &mut on_timeout);
62+
wait::wait(
63+
&mut sleeper,
64+
&new_config("198.19.255.255:1", 2_000, 0, 0, 10, 1),
65+
&mut on_timeout,
66+
);
5967
let elapsed = millis_elapsed(start);
6068
assert!(elapsed >= 2010);
6169
assert!(elapsed < 3000);
@@ -192,7 +200,14 @@ fn should_fail_if_not_all_hosts_are_available() {
192200

193201
fn on_timeout() {}
194202

195-
fn new_config(hosts: &str, timeout: u64, before: u64, after: u64, sleep: u64, tcp_connection_timeout: u64) -> wait::Config {
203+
fn new_config(
204+
hosts: &str,
205+
timeout: u64,
206+
before: u64,
207+
after: u64,
208+
sleep: u64,
209+
tcp_connection_timeout: u64,
210+
) -> wait::Config {
196211
wait::Config {
197212
hosts: hosts.to_string(),
198213
global_timeout: timeout,

0 commit comments

Comments
 (0)