@@ -85,14 +85,7 @@ fn should_identify_the_open_port() {
85
85
let mut fun = || { count. inc ( ) ; } ;
86
86
assert_eq ! ( 0 , count. get( ) ) ;
87
87
88
- thread:: spawn ( move || {
89
- loop {
90
- match tcpListener. accept ( ) {
91
- Ok ( _) => { println ! ( "Connection received!" ) ; }
92
- Err ( _) => { println ! ( "Error in received connection!" ) ; }
93
- }
94
- }
95
- } ) ;
88
+ listen_async ( tcpListener) ;
96
89
97
90
thread:: sleep ( time:: Duration :: from_millis ( 250 ) ) ;
98
91
wait:: wait ( & sleeper, & new_config ( & hosts, timeout, wait_before, wait_after ) , & mut fun) ;
@@ -119,23 +112,8 @@ fn should_wait_multiple_hosts() {
119
112
let mut fun = || { count. inc ( ) ; } ;
120
113
assert_eq ! ( 0 , count. get( ) ) ;
121
114
122
- thread:: spawn ( move || {
123
- loop {
124
- match tcpListener1. accept ( ) {
125
- Ok ( _) => { println ! ( "Connection received!" ) ; }
126
- Err ( _) => { println ! ( "Error in received connection!" ) ; }
127
- }
128
- }
129
- } ) ;
130
-
131
- thread:: spawn ( move || {
132
- loop {
133
- match tcpListener2. accept ( ) {
134
- Ok ( _) => { println ! ( "Connection received!" ) ; }
135
- Err ( _) => { println ! ( "Error in received connection!" ) ; }
136
- }
137
- }
138
- } ) ;
115
+ listen_async ( tcpListener1) ;
116
+ listen_async ( tcpListener2) ;
139
117
140
118
thread:: sleep ( time:: Duration :: from_millis ( 250 ) ) ;
141
119
wait:: wait ( & sleeper, & new_config ( & hosts, timeout, wait_before, wait_after ) , & mut fun) ;
@@ -161,14 +139,7 @@ fn should_fail_if_not_all_hosts_are_available() {
161
139
let mut fun = || { count. inc ( ) ; } ;
162
140
assert_eq ! ( 0 , count. get( ) ) ;
163
141
164
- thread:: spawn ( move || {
165
- loop {
166
- match tcpListener1. accept ( ) {
167
- Ok ( _) => { println ! ( "Connection received!" ) ; }
168
- Err ( _) => { println ! ( "Error in received connection!" ) ; }
169
- }
170
- }
171
- } ) ;
142
+ listen_async ( tcpListener1) ;
172
143
173
144
thread:: sleep ( time:: Duration :: from_millis ( 250 ) ) ;
174
145
wait:: wait ( & sleeper, & new_config ( & hosts, timeout, wait_before, wait_after ) , & mut fun) ;
@@ -196,6 +167,17 @@ fn newTcpListener() -> TcpListener {
196
167
TcpListener :: bind ( socket) . unwrap ( )
197
168
}
198
169
170
+ fn listen_async ( listener : TcpListener ) {
171
+ thread:: spawn ( move || {
172
+ loop {
173
+ match listener. accept ( ) {
174
+ Ok ( _) => { println ! ( "Connection received!" ) ; }
175
+ Err ( _) => { println ! ( "Error in received connection!" ) ; }
176
+ }
177
+ }
178
+ } ) ;
179
+ }
180
+
199
181
fn free_port ( ) -> u16 {
200
182
newTcpListener ( ) . local_addr ( ) . unwrap ( ) . port ( )
201
183
}
0 commit comments