@@ -6,25 +6,41 @@ use std::{
66
77use panic_log:: { initialize_hook, Configuration } ;
88
9+ // The test binary runs all tests in parallel by default; this lets multiple tests overwrite the
10+ // panic hook concurrently and cause spurious failure.
11+ static SERIAL_TEST : Mutex < ( ) > = Mutex :: new ( ( ) ) ;
12+
913#[ test]
1014#[ should_panic]
1115fn test ( ) {
16+ let _serial = SERIAL_TEST . lock ( ) . unwrap ( ) ;
17+
1218 initialize_hook ( Configuration :: default ( ) ) ;
19+
20+ // Drop the lock to not poison it
21+ drop ( _serial) ;
1322 panic ! ( "Test" ) ;
1423}
1524
1625#[ test]
1726#[ should_panic]
1827fn test_forced_trace ( ) {
28+ let _serial = SERIAL_TEST . lock ( ) . unwrap ( ) ;
29+
1930 initialize_hook ( Configuration {
2031 force_capture : true ,
2132 ..Default :: default ( )
2233 } ) ;
34+
35+ // Drop the lock to not poison it
36+ drop ( _serial) ;
2337 panic ! ( "Test" ) ;
2438}
2539
2640#[ test]
2741fn test_original_hook ( ) {
42+ let _serial = SERIAL_TEST . lock ( ) . unwrap ( ) ;
43+
2844 let original_hook = panic:: take_hook ( ) ;
2945 let ran_hook = Arc :: new ( Mutex :: new ( false ) ) ;
3046 let ran_hook_copy = Arc :: clone ( & ran_hook) ;
@@ -45,6 +61,8 @@ fn test_original_hook() {
4561
4662#[ test]
4763fn test_no_original_hook ( ) {
64+ let _serial = SERIAL_TEST . lock ( ) . unwrap ( ) ;
65+
4866 let original_hook = panic:: take_hook ( ) ;
4967 let ran_hook = Arc :: new ( Mutex :: new ( false ) ) ;
5068 let ran_hook_copy = Arc :: clone ( & ran_hook) ;
@@ -65,6 +83,8 @@ fn test_no_original_hook() {
6583
6684#[ test]
6785fn test_flush_logger ( ) {
86+ let _serial = SERIAL_TEST . lock ( ) . unwrap ( ) ;
87+
6888 struct Logger {
6989 pub flushed : Arc < Mutex < bool > > ,
7090 }
0 commit comments