@@ -12,13 +12,13 @@ async fn run_all_sql_test_files() {
1212 // Create a shutdown channel for the echo server
1313 let ( shutdown_tx, shutdown_rx) = oneshot:: channel ( ) ;
1414 // Start echo server once for all tests
15- let echo_handle = crate :: common:: start_echo_server ( shutdown_rx) ;
15+ let ( echo_handle, port ) = crate :: common:: start_echo_server ( shutdown_rx) ;
1616
1717 // Wait for echo server to be ready
18- wait_for_echo_server ( ) . await ;
18+ wait_for_echo_server ( port ) . await ;
1919
2020 for test_file in test_files {
21- let test_result = run_sql_test ( & test_file, & app_data, & echo_handle) . await ;
21+ let test_result = run_sql_test ( & test_file, & app_data, & echo_handle, port ) . await ;
2222 assert_test_result ( test_result, & test_file) ;
2323 }
2424
@@ -31,13 +31,13 @@ async fn run_all_sql_test_files() {
3131 }
3232}
3333
34- async fn wait_for_echo_server ( ) {
34+ async fn wait_for_echo_server ( port : u16 ) {
3535 let client = awc:: Client :: default ( ) ;
3636 let start = std:: time:: Instant :: now ( ) ;
3737 let timeout = Duration :: from_secs ( 5 ) ;
3838
3939 while start. elapsed ( ) < timeout {
40- match client. get ( "http://localhost:62802/" ) . send ( ) . await {
40+ match client. get ( format ! ( "http://localhost:{port}/" ) ) . send ( ) . await {
4141 Ok ( _) => return ,
4242 Err ( _) => {
4343 tokio:: time:: sleep ( Duration :: from_millis ( 100 ) ) . await ;
@@ -64,13 +64,20 @@ fn get_sql_test_files() -> Vec<std::path::PathBuf> {
6464 . collect ( )
6565}
6666
67+ use std:: fmt:: Write ;
68+
6769async fn run_sql_test (
6870 test_file : & std:: path:: Path ,
6971 app_data : & actix_web:: web:: Data < AppState > ,
7072 _echo_handle : & JoinHandle < ( ) > ,
73+ port : u16 ,
7174) -> anyhow:: Result < String > {
7275 let test_file_path = test_file. to_string_lossy ( ) . replace ( '\\' , "/" ) ;
73- let req_str = format ! ( "/{test_file_path}?x=1" ) ;
76+ let mut query_params = "x=1" . to_string ( ) ;
77+ if test_file_path. contains ( "fetch" ) {
78+ write ! ( query_params, "&echo_port={port}" ) . unwrap ( ) ;
79+ }
80+ let req_str = format ! ( "/{test_file_path}?{query_params}" ) ;
7481
7582 let resp = tokio:: time:: timeout (
7683 Duration :: from_secs ( 5 ) ,
@@ -114,11 +121,23 @@ fn assert_html_response(body: &str, test_file: &std::path::Path) {
114121}
115122
116123fn assert_it_works_tests ( body : & str , lowercase_body : & str , test_file : & std:: path:: Path ) {
124+ if body. contains ( "<code class=\" sqlpage-error-description\" >" ) {
125+ let error_desc = body
126+ . split ( "<code class=\" sqlpage-error-description\" >" )
127+ . nth ( 1 )
128+ . and_then ( |s| s. split ( "</code>" ) . next ( ) )
129+ . unwrap_or ( "Unknown error" ) ;
130+ panic ! (
131+ "\n \n ❌ TEST FAILED: {} ❌\n \n Full Response:\n {}\n \n Error Description: {}\n " ,
132+ test_file. display( ) ,
133+ error_desc,
134+ body
135+ ) ;
136+ }
137+
117138 assert ! (
118139 body. contains( "It works !" ) ,
119- "{}\n {}\n expected to contain: It works !" ,
120- test_file. display( ) ,
121- body
140+ "{body}\n ❌ Error in file {test_file:?} ❌\n " ,
122141 ) ;
123142 assert ! (
124143 !lowercase_body. contains( "error" ) ,
0 commit comments