@@ -142,6 +142,7 @@ pub enum Module {
142
142
pub struct RedisServer {
143
143
pub process : process:: Child ,
144
144
tempdir : tempfile:: TempDir ,
145
+ log_file : PathBuf ,
145
146
addr : redis:: ConnectionAddr ,
146
147
pub ( crate ) tls_paths : Option < TlsFilePaths > ,
147
148
}
@@ -174,6 +175,10 @@ impl RedisServer {
174
175
RedisServer :: with_modules ( & [ ] , true )
175
176
}
176
177
178
+ pub fn log_file_contents ( & self ) -> String {
179
+ std:: fs:: read_to_string ( self . log_file . clone ( ) ) . unwrap ( )
180
+ }
181
+
177
182
pub fn get_addr ( port : u16 ) -> ConnectionAddr {
178
183
let server_type = ServerType :: get_intended ( ) ;
179
184
match server_type {
@@ -270,7 +275,8 @@ impl RedisServer {
270
275
. prefix ( "redis" )
271
276
. tempdir ( )
272
277
. expect ( "failed to create tempdir" ) ;
273
- redis_cmd. arg ( "--logfile" ) . arg ( Self :: log_file ( & tempdir) ) ;
278
+ let log_file = Self :: log_file ( & tempdir) ;
279
+ redis_cmd. arg ( "--logfile" ) . arg ( log_file. clone ( ) ) ;
274
280
match addr {
275
281
redis:: ConnectionAddr :: Tcp ( ref bind, server_port) => {
276
282
redis_cmd
@@ -281,6 +287,7 @@ impl RedisServer {
281
287
282
288
RedisServer {
283
289
process : spawner ( & mut redis_cmd) ,
290
+ log_file,
284
291
tempdir,
285
292
addr,
286
293
tls_paths : None ,
@@ -320,6 +327,7 @@ impl RedisServer {
320
327
321
328
RedisServer {
322
329
process : spawner ( & mut redis_cmd) ,
330
+ log_file,
323
331
tempdir,
324
332
addr,
325
333
tls_paths : Some ( tls_paths) ,
@@ -333,6 +341,7 @@ impl RedisServer {
333
341
. arg ( path) ;
334
342
RedisServer {
335
343
process : spawner ( & mut redis_cmd) ,
344
+ log_file,
336
345
tempdir,
337
346
addr,
338
347
tls_paths : None ,
@@ -410,15 +419,27 @@ impl TestContext {
410
419
}
411
420
412
421
pub fn with_tls ( tls_files : TlsFilePaths , mtls_enabled : bool ) -> TestContext {
422
+ Self :: with_modules_and_tls ( & [ ] , mtls_enabled, Some ( tls_files) )
423
+ }
424
+
425
+ pub fn with_modules ( modules : & [ Module ] , mtls_enabled : bool ) -> TestContext {
426
+ Self :: with_modules_and_tls ( modules, mtls_enabled, None )
427
+ }
428
+
429
+ fn with_modules_and_tls (
430
+ modules : & [ Module ] ,
431
+ mtls_enabled : bool ,
432
+ tls_files : Option < TlsFilePaths > ,
433
+ ) -> Self {
413
434
let redis_port = get_random_available_port ( ) ;
414
435
let addr = RedisServer :: get_addr ( redis_port) ;
415
436
416
437
let server = RedisServer :: new_with_addr_tls_modules_and_spawner (
417
438
addr,
418
439
None ,
419
- Some ( tls_files) ,
440
+ tls_files,
420
441
mtls_enabled,
421
- & [ ] ,
442
+ modules ,
422
443
|cmd| {
423
444
cmd. spawn ( )
424
445
. unwrap_or_else ( |err| panic ! ( "Failed to run {cmd:?}: {err}" ) )
@@ -442,51 +463,16 @@ impl TestContext {
442
463
sleep ( millisecond) ;
443
464
retries += 1 ;
444
465
if retries > 100000 {
445
- panic ! ( "Tried to connect too many times, last error: {err}" ) ;
446
- }
447
- } else {
448
- panic ! ( "Could not connect: {err}" ) ;
449
- }
450
- }
451
- Ok ( x) => {
452
- con = x;
453
- break ;
454
- }
455
- }
456
- }
457
- redis:: cmd ( "FLUSHDB" ) . execute ( & mut con) ;
458
-
459
- TestContext {
460
- server,
461
- client,
462
- protocol : use_protocol ( ) ,
463
- }
464
- }
465
-
466
- pub fn with_modules ( modules : & [ Module ] , mtls_enabled : bool ) -> TestContext {
467
- let server = RedisServer :: with_modules ( modules, mtls_enabled) ;
468
-
469
- #[ cfg( feature = "tls-rustls" ) ]
470
- let client =
471
- build_single_client ( server. connection_info ( ) , & server. tls_paths , mtls_enabled) . unwrap ( ) ;
472
- #[ cfg( not( feature = "tls-rustls" ) ) ]
473
- let client = redis:: Client :: open ( server. connection_info ( ) ) . unwrap ( ) ;
474
-
475
- let mut con;
476
-
477
- let millisecond = Duration :: from_millis ( 1 ) ;
478
- let mut retries = 0 ;
479
- loop {
480
- match client. get_connection ( ) {
481
- Err ( err) => {
482
- if err. is_connection_refusal ( ) {
483
- sleep ( millisecond) ;
484
- retries += 1 ;
485
- if retries > 100000 {
486
- panic ! ( "Tried to connect too many times, last error: {err}" ) ;
466
+ panic ! (
467
+ "Tried to connect too many times, last error: {err}, logfile: {}" ,
468
+ server. log_file_contents( )
469
+ ) ;
487
470
}
488
471
} else {
489
- panic ! ( "Could not connect: {err}" ) ;
472
+ panic ! (
473
+ "Could not connect: {err}, logfile: {}" ,
474
+ server. log_file_contents( )
475
+ ) ;
490
476
}
491
477
}
492
478
Ok ( x) => {
0 commit comments