@@ -13,7 +13,7 @@ fn should_wait_5_seconds_before() {
13
13
let wait_for : u64 = 5 ;
14
14
let start = Instant :: now ( ) ;
15
15
let sleeper = MillisSleeper { } ;
16
- wait:: wait ( & sleeper, & new_config ( "" , 1 , wait_for, 0 ) , & mut on_timeout) ;
16
+ wait:: wait ( & sleeper, & new_config ( "" , 1 , wait_for, 0 , 1 ) , & mut on_timeout) ;
17
17
assert ! ( millis_elapsed( start) >= wait_for )
18
18
}
19
19
@@ -23,7 +23,7 @@ fn should_wait_10_seconds_after() {
23
23
let wait_for = 10 ;
24
24
let start = Instant :: now ( ) ;
25
25
let sleeper = MillisSleeper { } ;
26
- wait:: wait ( & sleeper, & new_config ( "" , 1 , 0 , wait_for ) , & mut on_timeout) ;
26
+ wait:: wait ( & sleeper, & new_config ( "" , 1 , 0 , wait_for, 1 ) , & mut on_timeout) ;
27
27
assert ! ( millis_elapsed( start) >= wait_for )
28
28
}
29
29
@@ -32,15 +32,15 @@ fn should_wait_before_and_after() {
32
32
let wait_for = 10 ;
33
33
let start = Instant :: now ( ) ;
34
34
let sleeper = MillisSleeper { } ;
35
- wait:: wait ( & sleeper, & new_config ( "" , 1 , wait_for, wait_for ) , & mut on_timeout) ;
35
+ wait:: wait ( & sleeper, & new_config ( "" , 1 , wait_for, wait_for, 1 ) , & mut on_timeout) ;
36
36
assert ! ( millis_elapsed( start) >= ( wait_for + wait_for) )
37
37
}
38
38
39
39
#[ test]
40
40
fn should_execute_without_wait ( ) {
41
41
let start = Instant :: now ( ) ;
42
42
let sleeper = MillisSleeper { } ;
43
- wait:: wait ( & sleeper, & new_config ( "" , 1 , 0 , 0 ) , & mut on_timeout) ;
43
+ wait:: wait ( & sleeper, & new_config ( "" , 1 , 0 , 0 , 1 ) , & mut on_timeout) ;
44
44
assert ! ( millis_elapsed( start) <= 5 )
45
45
}
46
46
@@ -56,9 +56,9 @@ fn should_exit_on_timeout() {
56
56
let count : atomic_counter:: RelaxedCounter = atomic_counter:: RelaxedCounter :: new ( 0 ) ;
57
57
let mut fun = || { count. inc ( ) ; } ;
58
58
assert_eq ! ( 0 , count. get( ) ) ;
59
-
60
- wait:: wait ( & sleeper, & new_config ( & hosts, timeout, wait_before, wait_after ) , & mut fun) ;
61
-
59
+
60
+ wait:: wait ( & sleeper, & new_config ( & hosts, timeout, wait_before, wait_after, 1 ) , & mut fun) ;
61
+
62
62
// assert that the on_timeout callback was called
63
63
assert_eq ! ( 1 , count. get( ) ) ;
64
64
@@ -83,9 +83,9 @@ fn should_identify_the_open_port() {
83
83
84
84
listen_async ( tcp_listener) ;
85
85
86
- thread:: sleep ( time:: Duration :: from_millis ( 250 ) ) ;
87
- wait:: wait ( & sleeper, & new_config ( & hosts, timeout, wait_before, wait_after ) , & mut fun) ;
88
-
86
+ thread:: sleep ( time:: Duration :: from_millis ( 250 ) ) ;
87
+ wait:: wait ( & sleeper, & new_config ( & hosts, timeout, wait_before, wait_after, 1 ) , & mut fun) ;
88
+
89
89
assert_eq ! ( 0 , count. get( ) ) ;
90
90
91
91
assert ! ( millis_elapsed( start) >= wait_before + wait_after ) ;
@@ -111,9 +111,9 @@ fn should_wait_multiple_hosts() {
111
111
listen_async ( tcp_listener1) ;
112
112
listen_async ( tcp_listener2) ;
113
113
114
- thread:: sleep ( time:: Duration :: from_millis ( 250 ) ) ;
115
- wait:: wait ( & sleeper, & new_config ( & hosts, timeout, wait_before, wait_after ) , & mut fun) ;
116
-
114
+ thread:: sleep ( time:: Duration :: from_millis ( 250 ) ) ;
115
+ wait:: wait ( & sleeper, & new_config ( & hosts, timeout, wait_before, wait_after, 1 ) , & mut fun) ;
116
+
117
117
assert_eq ! ( 0 , count. get( ) ) ;
118
118
119
119
assert ! ( millis_elapsed( start) >= wait_before + wait_after ) ;
@@ -137,9 +137,9 @@ fn should_fail_if_not_all_hosts_are_available() {
137
137
138
138
listen_async ( tcp_listener1) ;
139
139
140
- thread:: sleep ( time:: Duration :: from_millis ( 250 ) ) ;
141
- wait:: wait ( & sleeper, & new_config ( & hosts, timeout, wait_before, wait_after ) , & mut fun) ;
142
-
140
+ thread:: sleep ( time:: Duration :: from_millis ( 250 ) ) ;
141
+ wait:: wait ( & sleeper, & new_config ( & hosts, timeout, wait_before, wait_after, 1 ) , & mut fun) ;
142
+
143
143
assert_eq ! ( 1 , count. get( ) ) ;
144
144
145
145
assert ! ( millis_elapsed( start) >= wait_before + wait_after ) ;
@@ -148,12 +148,13 @@ fn should_fail_if_not_all_hosts_are_available() {
148
148
149
149
fn on_timeout ( ) { }
150
150
151
- fn new_config ( hosts : & str , timeout : u64 , before : u64 , after : u64 ) -> wait:: Config {
151
+ fn new_config ( hosts : & str , timeout : u64 , before : u64 , after : u64 , sleep : u64 ) -> wait:: Config {
152
152
wait:: Config {
153
153
hosts : hosts. to_string ( ) ,
154
154
timeout : timeout,
155
155
wait_before : before,
156
156
wait_after : after,
157
+ wait_sleep_interval : sleep
157
158
}
158
159
}
159
160
@@ -190,4 +191,4 @@ impl Sleeper for MillisSleeper {
190
191
fn sleep ( & self , duration : u64 ) {
191
192
thread:: sleep ( Duration :: from_millis ( duration) )
192
193
}
193
- }
194
+ }
0 commit comments