@@ -170,7 +170,7 @@ async fn test_http_proxy_get() {
170170 assert_eq ! ( response. status( ) , 200 ) ;
171171
172172 let json: serde_json:: Value = response. json ( ) . await . expect ( "Failed to parse JSON" ) ;
173- assert_eq ! ( json[ "url" ] , "https ://httpbin.org /get" ) ;
173+ assert_eq ! ( json[ "url" ] , "http ://localhost:8888 /get" ) ;
174174}
175175
176176#[ tokio:: test]
@@ -293,48 +293,27 @@ async fn test_websocket_echo() {
293293
294294 let ( mut write, mut read) = ws_stream. split ( ) ;
295295
296- // Skip the initial greeting message from echo.websocket.org
297- // Read and discard the greeting message (e.g., "Request served by ...")
298- if let Ok ( Some ( Ok ( msg) ) ) = tokio:: time:: timeout ( Duration :: from_secs ( 3 ) , read. next ( ) ) . await {
299- println ! ( "Skipped greeting message: {:?}" , msg) ;
300- }
301-
302296 // Send a text message
303297 let test_message = "Hello WebSocket!" ;
304298 write
305299 . send ( Message :: Text ( test_message. to_string ( ) . into ( ) ) )
306300 . await
307301 . expect ( "Failed to send message" ) ;
308302
309- // Receive the echo - may need to skip additional greeting messages
310- let mut received_echo = None ;
311- for _ in 0 ..3 {
312- let received = tokio:: time:: timeout ( Duration :: from_secs ( 5 ) , read. next ( ) )
313- . await
314- . expect ( "Timeout waiting for message" )
315- . expect ( "No message received" )
316- . expect ( "Error receiving message" ) ;
317-
318- match received {
319- Message :: Text ( text) => {
320- let text_str = text. to_string ( ) ;
321- // Skip greeting messages from echo.websocket.org
322- if text_str. starts_with ( "Request served by" ) {
323- println ! ( "Skipping server info: {}" , text_str) ;
324- continue ;
325- }
326- // This is our echo
327- received_echo = Some ( text_str) ;
328- break ;
329- }
330- _ => panic ! ( "Expected text message, got: {:?}" , received) ,
303+ // Receive the echo
304+ let received = tokio:: time:: timeout ( Duration :: from_secs ( 5 ) , read. next ( ) )
305+ . await
306+ . expect ( "Timeout waiting for message" )
307+ . expect ( "No message received" )
308+ . expect ( "Error receiving message" ) ;
309+
310+ match received {
311+ Message :: Text ( text) => {
312+ let text_str = text. to_string ( ) ;
313+ assert_eq ! ( text_str, test_message) ;
331314 }
315+ _ => panic ! ( "Expected text message, got: {:?}" , received) ,
332316 }
333-
334- assert_eq ! (
335- received_echo. expect( "Did not receive echo message" ) ,
336- test_message
337- ) ;
338317}
339318
340319#[ tokio:: test]
@@ -352,51 +331,26 @@ async fn test_websocket_binary_message() {
352331
353332 let ( mut write, mut read) = ws_stream. split ( ) ;
354333
355- // Skip the initial greeting message from echo.websocket.org
356- // Read and discard the greeting message (e.g., "Request served by ...")
357- if let Ok ( Some ( Ok ( msg) ) ) = tokio:: time:: timeout ( Duration :: from_secs ( 3 ) , read. next ( ) ) . await {
358- println ! ( "Skipped greeting message: {:?}" , msg) ;
359- }
360-
361334 // Send binary data
362335 let test_data = vec ! [ 1u8 , 2 , 3 , 4 , 5 ] ;
363336 write
364337 . send ( Message :: Binary ( test_data. clone ( ) . into ( ) ) )
365338 . await
366339 . expect ( "Failed to send binary message" ) ;
367340
368- // Receive the echo - may need to skip additional text messages
369- let mut received_binary = None ;
370- for _ in 0 ..3 {
371- let received = tokio:: time:: timeout ( Duration :: from_secs ( 5 ) , read. next ( ) )
372- . await
373- . expect ( "Timeout waiting for message" )
374- . expect ( "No message received" )
375- . expect ( "Error receiving message" ) ;
341+ // Receive the echo
342+ let received = tokio:: time:: timeout ( Duration :: from_secs ( 5 ) , read. next ( ) )
343+ . await
344+ . expect ( "Timeout waiting for message" )
345+ . expect ( "No message received" )
346+ . expect ( "Error receiving message" ) ;
376347
377- match received {
378- Message :: Binary ( data) => {
379- // This is our echo
380- received_binary = Some ( data. to_vec ( ) ) ;
381- break ;
382- }
383- Message :: Text ( text) => {
384- let text_str = text. to_string ( ) ;
385- // Skip greeting messages from echo.websocket.org
386- if text_str. starts_with ( "Request served by" ) {
387- println ! ( "Skipping server info: {}" , text_str) ;
388- continue ;
389- }
390- panic ! ( "Expected binary message, got unexpected text: {}" , text_str) ;
391- }
392- _ => panic ! ( "Expected binary message, got: {:?}" , received) ,
348+ match received {
349+ Message :: Binary ( data) => {
350+ assert_eq ! ( data. to_vec( ) , test_data) ;
393351 }
352+ _ => panic ! ( "Expected binary message, got: {:?}" , received) ,
394353 }
395-
396- assert_eq ! (
397- received_binary. expect( "Did not receive binary echo" ) ,
398- test_data
399- ) ;
400354}
401355
402356#[ tokio:: test]
@@ -430,9 +384,6 @@ async fn test_websocket_multiple_messages() {
430384
431385 let ( mut write, mut read) = ws_stream. split ( ) ;
432386
433- // Skip the initial greeting message from echo.websocket.org
434- let _ = tokio:: time:: timeout ( Duration :: from_secs ( 2 ) , read. next ( ) ) . await ;
435-
436387 // Send multiple messages
437388 let messages = vec ! [ "Message 1" , "Message 2" , "Message 3" ] ;
438389
@@ -442,26 +393,19 @@ async fn test_websocket_multiple_messages() {
442393 . await
443394 . expect ( "Failed to send message" ) ;
444395
445- // Receive messages, skipping any greeting messages
446- loop {
447- let received = tokio:: time:: timeout ( Duration :: from_secs ( 5 ) , read. next ( ) )
448- . await
449- . expect ( "Timeout waiting for message" )
450- . expect ( "No message received" )
451- . expect ( "Error receiving message" ) ;
452-
453- match received {
454- Message :: Text ( text) => {
455- let text_str = text. to_string ( ) ;
456- // Skip greeting messages from echo.websocket.org
457- if text_str. starts_with ( "Request served by" ) {
458- continue ;
459- }
460- assert_eq ! ( & text_str, msg) ;
461- break ;
462- }
463- _ => panic ! ( "Expected text message" ) ,
396+ // Receive the echo
397+ let received = tokio:: time:: timeout ( Duration :: from_secs ( 5 ) , read. next ( ) )
398+ . await
399+ . expect ( "Timeout waiting for message" )
400+ . expect ( "No message received" )
401+ . expect ( "Error receiving message" ) ;
402+
403+ match received {
404+ Message :: Text ( text) => {
405+ let text_str = text. to_string ( ) ;
406+ assert_eq ! ( & text_str, msg) ;
464407 }
408+ _ => panic ! ( "Expected text message" ) ,
465409 }
466410 }
467411}
0 commit comments