3
3
4
4
use std:: convert:: identity;
5
5
use std:: env;
6
- use std:: io:: Read ;
7
6
use std:: process;
8
7
use std:: thread:: sleep;
9
8
use std:: time:: Duration ;
@@ -200,44 +199,30 @@ impl RedisCluster {
200
199
folders. push ( tempdir) ;
201
200
addrs. push ( addr. clone ( ) ) ;
202
201
203
- let mut cur_attempts = 0 ;
204
- loop {
205
- let mut process = cmd . spawn ( ) . unwrap ( ) ;
206
- sleep ( Duration :: from_millis ( 50 ) ) ;
202
+ cmd . spawn ( ) . unwrap ( )
203
+ } ,
204
+ ) ) ;
205
+ }
207
206
207
+ for server in servers. iter_mut ( ) {
208
+ let process = & mut server. process ;
209
+ sleep ( Duration :: from_millis ( 50 ) ) ;
208
210
match process. try_wait ( ) {
209
- Ok ( Some ( status) ) => {
210
- let stdout = process. stdout . map_or ( String :: new ( ) , |mut out|{
211
- let mut str = String :: new ( ) ;
212
- out. read_to_string ( & mut str) . unwrap ( ) ;
213
- str
214
- } ) ;
215
- let stderr = process. stderr . map_or ( String :: new ( ) , |mut out|{
216
- let mut str = String :: new ( ) ;
217
- out. read_to_string ( & mut str) . unwrap ( ) ;
218
- str
219
- } ) ;
220
- let err =
221
- format ! ( "redis server creation failed with status {status:?}.\n stdout: `{stdout}`.\n stderr: `{stderr}`" ) ;
222
- if cur_attempts == max_attempts {
223
- let log_file_index = cmd. get_args ( ) . position ( |os_str| os_str == "--logfile" ) . unwrap ( ) + 1 ;
224
- let log_file_path = cmd. get_args ( ) . nth ( log_file_index) . unwrap ( ) ;
225
- let contents = std:: fs:: read_to_string ( log_file_path) . unwrap ( ) ;
226
- panic ! ( "{err} - logfile: {contents}" ) ;
227
- }
228
- eprintln ! ( "Retrying: {err}" ) ;
229
- cur_attempts += 1 ;
211
+ Ok ( Some ( status) ) => {
212
+ let contents = std:: fs:: read_to_string ( server. log_file . clone ( ) ) . unwrap ( ) ;
213
+ panic ! ( "redis server creation failed with status {status:?}.\n logfile: {contents}" ) ;
230
214
}
231
215
Ok ( None ) => {
232
216
// wait for 10 seconds for the server to be available.
233
217
let max_attempts = 200 ;
234
218
let mut cur_attempts = 0 ;
219
+ let addr = & server. addr ;
235
220
loop {
236
221
if cur_attempts == max_attempts {
237
- panic ! ( "redis server creation failed: Port {port } closed" )
222
+ panic ! ( "redis server creation failed: Port {} closed" , & addr )
238
223
}
239
- if port_in_use ( & addr) {
240
- return process ;
224
+ if port_in_use ( & addr. to_string ( ) ) {
225
+ continue ;
241
226
}
242
227
eprintln ! ( "Waiting for redis process to initialize" ) ;
243
228
sleep ( Duration :: from_millis ( 50 ) ) ;
@@ -248,9 +233,6 @@ impl RedisCluster {
248
233
panic ! ( "Unexpected error in redis server creation {e}" ) ;
249
234
}
250
235
}
251
- }
252
- } ,
253
- ) ) ;
254
236
}
255
237
256
238
let mut cmd = process:: Command :: new ( "redis-cli" ) ;
0 commit comments