11use assertables:: assert_contains;
2+ use std:: sync:: { Arc , Condvar , Mutex , OnceLock } ;
23
34mod utils;
45
6+ // Global state to track build completion
7+ static BUILD_STATE : OnceLock < ( Arc < Mutex < bool > > , Arc < Condvar > ) > = OnceLock :: new ( ) ;
8+
9+ // Call this function to ensure the build has happened and completed
10+ // All threads will wait for the build to finish before proceeding
11+ fn ensure_setup ( ) {
12+ let ( build_complete, condvar) = BUILD_STATE . get_or_init ( || {
13+ let pair = ( Arc :: new ( Mutex :: new ( false ) ) , Arc :: new ( Condvar :: new ( ) ) ) ;
14+ let ( build_complete, condvar) = pair. clone ( ) ;
15+
16+ // Start the build in the background
17+ std:: thread:: spawn ( move || {
18+ utils:: build ( ) ;
19+ let mut completed = build_complete. lock ( ) . unwrap ( ) ;
20+ * completed = true ;
21+ condvar. notify_all ( ) ;
22+ } ) ;
23+
24+ pair
25+ } ) ;
26+
27+ // Wait for build to complete
28+ let mut completed = build_complete. lock ( ) . unwrap ( ) ;
29+ while !* completed {
30+ completed = condvar. wait ( completed) . unwrap ( ) ;
31+ }
32+ }
33+
534#[ test]
635fn test_build ( ) {
7- utils :: build ( ) ;
36+ ensure_setup ( ) ;
837}
938
1039#[ test]
1140fn test_version ( ) {
12- utils :: build ( ) ;
41+ ensure_setup ( ) ;
1342 let output = utils:: run_cli ( "<?php phpinfo(); ?>" ) ;
1443 assert_contains ! (
1544 output. trim( ) ,
@@ -22,7 +51,7 @@ fn test_version() {
2251
2352#[ test]
2453fn test_cli_error_output_default ( ) {
25- utils :: build ( ) ;
54+ ensure_setup ( ) ;
2655 let code = r#"
2756<?php
2857trigger_error('This is a test error', E_USER_WARNING);
@@ -33,7 +62,7 @@ trigger_error('This is a test error', E_USER_WARNING);
3362
3463#[ test]
3564fn test_cli_error_output ( ) {
36- utils :: build ( ) ;
65+ ensure_setup ( ) ;
3766 let code = r#"
3867<?php
3968ini_set('error_message_format', '{message} with an append');
0 commit comments