@@ -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 {
@@ -277,7 +282,8 @@ impl RedisServer {
277
282
. prefix ( "redis" )
278
283
. tempdir ( )
279
284
. expect ( "failed to create tempdir" ) ;
280
- redis_cmd. arg ( "--logfile" ) . arg ( Self :: log_file ( & tempdir) ) ;
285
+ let log_file = Self :: log_file ( & tempdir) ;
286
+ redis_cmd. arg ( "--logfile" ) . arg ( log_file. clone ( ) ) ;
281
287
match addr {
282
288
redis:: ConnectionAddr :: Tcp ( ref bind, server_port) => {
283
289
redis_cmd
@@ -288,6 +294,7 @@ impl RedisServer {
288
294
289
295
RedisServer {
290
296
process : spawner ( & mut redis_cmd) ,
297
+ log_file,
291
298
tempdir,
292
299
addr,
293
300
tls_paths : None ,
@@ -327,6 +334,7 @@ impl RedisServer {
327
334
328
335
RedisServer {
329
336
process : spawner ( & mut redis_cmd) ,
337
+ log_file,
330
338
tempdir,
331
339
addr,
332
340
tls_paths : Some ( tls_paths) ,
@@ -340,6 +348,7 @@ impl RedisServer {
340
348
. arg ( path) ;
341
349
RedisServer {
342
350
process : spawner ( & mut redis_cmd) ,
351
+ log_file,
343
352
tempdir,
344
353
addr,
345
354
tls_paths : None ,
@@ -417,15 +426,27 @@ impl TestContext {
417
426
}
418
427
419
428
pub fn with_tls ( tls_files : TlsFilePaths , mtls_enabled : bool ) -> TestContext {
429
+ Self :: with_modules_and_tls ( & [ ] , mtls_enabled, Some ( tls_files) )
430
+ }
431
+
432
+ pub fn with_modules ( modules : & [ Module ] , mtls_enabled : bool ) -> TestContext {
433
+ Self :: with_modules_and_tls ( modules, mtls_enabled, None )
434
+ }
435
+
436
+ fn with_modules_and_tls (
437
+ modules : & [ Module ] ,
438
+ mtls_enabled : bool ,
439
+ tls_files : Option < TlsFilePaths > ,
440
+ ) -> Self {
420
441
let redis_port = get_random_available_port ( ) ;
421
442
let addr = RedisServer :: get_addr ( redis_port) ;
422
443
423
444
let server = RedisServer :: new_with_addr_tls_modules_and_spawner (
424
445
addr,
425
446
None ,
426
- Some ( tls_files) ,
447
+ tls_files,
427
448
mtls_enabled,
428
- & [ ] ,
449
+ modules ,
429
450
|cmd| {
430
451
cmd. spawn ( )
431
452
. unwrap_or_else ( |err| panic ! ( "Failed to run {cmd:?}: {err}" ) )
@@ -449,51 +470,16 @@ impl TestContext {
449
470
sleep ( millisecond) ;
450
471
retries += 1 ;
451
472
if retries > 100000 {
452
- panic ! ( "Tried to connect too many times, last error: {err}" ) ;
453
- }
454
- } else {
455
- panic ! ( "Could not connect: {err}" ) ;
456
- }
457
- }
458
- Ok ( x) => {
459
- con = x;
460
- break ;
461
- }
462
- }
463
- }
464
- redis:: cmd ( "FLUSHDB" ) . execute ( & mut con) ;
465
-
466
- TestContext {
467
- server,
468
- client,
469
- protocol : use_protocol ( ) ,
470
- }
471
- }
472
-
473
- pub fn with_modules ( modules : & [ Module ] , mtls_enabled : bool ) -> TestContext {
474
- let server = RedisServer :: with_modules ( modules, mtls_enabled) ;
475
-
476
- #[ cfg( feature = "tls-rustls" ) ]
477
- let client =
478
- build_single_client ( server. connection_info ( ) , & server. tls_paths , mtls_enabled) . unwrap ( ) ;
479
- #[ cfg( not( feature = "tls-rustls" ) ) ]
480
- let client = redis:: Client :: open ( server. connection_info ( ) ) . unwrap ( ) ;
481
-
482
- let mut con;
483
-
484
- let millisecond = Duration :: from_millis ( 1 ) ;
485
- let mut retries = 0 ;
486
- loop {
487
- match client. get_connection ( ) {
488
- Err ( err) => {
489
- if err. is_connection_refusal ( ) {
490
- sleep ( millisecond) ;
491
- retries += 1 ;
492
- if retries > 100000 {
493
- panic ! ( "Tried to connect too many times, last error: {err}" ) ;
473
+ panic ! (
474
+ "Tried to connect too many times, last error: {err}, logfile: {}" ,
475
+ server. log_file_contents( )
476
+ ) ;
494
477
}
495
478
} else {
496
- panic ! ( "Could not connect: {err}" ) ;
479
+ panic ! (
480
+ "Could not connect: {err}, logfile: {}" ,
481
+ server. log_file_contents( )
482
+ ) ;
497
483
}
498
484
}
499
485
Ok ( x) => {
0 commit comments