@@ -169,7 +169,11 @@ impl TestServer {
169169 let state = dbrest:: compat:: app_state_from_pool (
170170 pool,
171171 config,
172- PgVersion { major : 16 , minor : 0 , patch : 0 } ,
172+ PgVersion {
173+ major : 16 ,
174+ minor : 0 ,
175+ patch : 0 ,
176+ } ,
173177 ) ;
174178
175179 let notifier: Arc < dyn ChangeNotifier > = Arc :: new ( AppLevelNotifier :: new ( 1024 ) ) ;
@@ -193,7 +197,11 @@ impl TestServer {
193197 let state = dbrest:: compat:: app_state_from_pool (
194198 pool. clone ( ) ,
195199 config,
196- PgVersion { major : 16 , minor : 0 , patch : 0 } ,
200+ PgVersion {
201+ major : 16 ,
202+ minor : 0 ,
203+ patch : 0 ,
204+ } ,
197205 ) ;
198206
199207 let notifier = PgChangeNotifier :: new ( pool, NOTIFY_CHANNEL , 1024 )
@@ -220,7 +228,11 @@ impl TestServer {
220228 let state = dbrest:: compat:: app_state_from_pool (
221229 pool,
222230 config,
223- PgVersion { major : 16 , minor : 0 , patch : 0 } ,
231+ PgVersion {
232+ major : 16 ,
233+ minor : 0 ,
234+ patch : 0 ,
235+ } ,
224236 ) ;
225237
226238 Self :: boot ( db, state) . await
@@ -284,7 +296,10 @@ impl TestServer {
284296 self . client
285297 . put ( format ! ( "{}{}" , self . base_url, path) )
286298 . header ( "content-type" , "application/json" )
287- . header ( "prefer" , "return=representation,resolution=merge-duplicates" )
299+ . header (
300+ "prefer" ,
301+ "return=representation,resolution=merge-duplicates" ,
302+ )
288303 . json ( body)
289304 . send ( )
290305 . await
@@ -316,7 +331,8 @@ impl TestServer {
316331#[ ignore]
317332async fn sse_returns_503_when_no_notifier ( ) {
318333 let server = TestServer :: start_without_notifier ( ) . await ;
319- let resp = server. client
334+ let resp = server
335+ . client
320336 . get ( server. listen_url ( "users" ) )
321337 . send ( )
322338 . await
@@ -328,14 +344,20 @@ async fn sse_returns_503_when_no_notifier() {
328344#[ ignore]
329345async fn sse_connection_returns_200_event_stream ( ) {
330346 let server = TestServer :: start_with_app_notifier ( ) . await ;
331- let resp = server. client
347+ let resp = server
348+ . client
332349 . get ( server. listen_url ( "products" ) )
333350 . header ( "accept" , "text/event-stream" )
334351 . send ( )
335352 . await
336353 . unwrap ( ) ;
337354 assert_eq ! ( resp. status( ) , StatusCode :: OK ) ;
338- let ct = resp. headers ( ) . get ( "content-type" ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
355+ let ct = resp
356+ . headers ( )
357+ . get ( "content-type" )
358+ . unwrap ( )
359+ . to_str ( )
360+ . unwrap ( ) ;
339361 assert ! (
340362 ct. contains( "text/event-stream" ) ,
341363 "Expected text/event-stream, got: {}" ,
@@ -371,7 +393,10 @@ async fn sse_filters_events_by_table_name() {
371393 } )
372394 . await ;
373395
374- let event = sse. next_event ( Duration :: from_secs ( 2 ) ) . await . expect ( "Should receive products event" ) ;
396+ let event = sse
397+ . next_event ( Duration :: from_secs ( 2 ) )
398+ . await
399+ . expect ( "Should receive products event" ) ;
375400 assert_eq ! ( event. event_type, "UPDATE" ) ;
376401 assert_eq ! ( event. change_event( ) . table, "products" ) ;
377402}
@@ -388,11 +413,17 @@ async fn sse_post_produces_insert_event() {
388413 tokio:: time:: sleep ( Duration :: from_millis ( 50 ) ) . await ;
389414
390415 let resp = server
391- . post_json ( "/products" , & json ! ( { "name" : "PG SSE Widget" , "price" : 5.99 } ) )
416+ . post_json (
417+ "/products" ,
418+ & json ! ( { "name" : "PG SSE Widget" , "price" : 5.99 } ) ,
419+ )
392420 . await ;
393421 assert ! ( resp. status( ) . is_success( ) , "POST failed: {}" , resp. status( ) ) ;
394422
395- let event = sse. next_event ( Duration :: from_secs ( 2 ) ) . await . expect ( "Should receive INSERT event" ) ;
423+ let event = sse
424+ . next_event ( Duration :: from_secs ( 2 ) )
425+ . await
426+ . expect ( "Should receive INSERT event" ) ;
396427 assert_eq ! ( event. event_type, "INSERT" ) ;
397428 let ce = event. change_event ( ) ;
398429 assert_eq ! ( ce. table, "products" ) ;
@@ -409,9 +440,16 @@ async fn sse_patch_produces_update_event() {
409440 let resp = server
410441 . patch_json ( "/products?name=eq.Widget" , & json ! ( { "price" : 19.99 } ) )
411442 . await ;
412- assert ! ( resp. status( ) . is_success( ) , "PATCH failed: {}" , resp. status( ) ) ;
443+ assert ! (
444+ resp. status( ) . is_success( ) ,
445+ "PATCH failed: {}" ,
446+ resp. status( )
447+ ) ;
413448
414- let event = sse. next_event ( Duration :: from_secs ( 2 ) ) . await . expect ( "Should receive UPDATE event" ) ;
449+ let event = sse
450+ . next_event ( Duration :: from_secs ( 2 ) )
451+ . await
452+ . expect ( "Should receive UPDATE event" ) ;
415453 assert_eq ! ( event. event_type, "UPDATE" ) ;
416454 assert_eq ! ( event. change_event( ) . table, "products" ) ;
417455}
@@ -429,7 +467,10 @@ async fn sse_put_produces_update_event() {
429467 . await ;
430468 assert ! ( resp. status( ) . is_success( ) , "PUT failed: {}" , resp. status( ) ) ;
431469
432- let event = sse. next_event ( Duration :: from_secs ( 2 ) ) . await . expect ( "Should receive UPDATE event" ) ;
470+ let event = sse
471+ . next_event ( Duration :: from_secs ( 2 ) )
472+ . await
473+ . expect ( "Should receive UPDATE event" ) ;
433474 assert_eq ! ( event. event_type, "UPDATE" ) ;
434475 assert_eq ! ( event. change_event( ) . table, "products" ) ;
435476}
@@ -442,9 +483,16 @@ async fn sse_delete_produces_delete_event() {
442483 tokio:: time:: sleep ( Duration :: from_millis ( 50 ) ) . await ;
443484
444485 let resp = server. delete ( "/products?name=eq.Doohickey" ) . await ;
445- assert ! ( resp. status( ) . is_success( ) , "DELETE failed: {}" , resp. status( ) ) ;
486+ assert ! (
487+ resp. status( ) . is_success( ) ,
488+ "DELETE failed: {}" ,
489+ resp. status( )
490+ ) ;
446491
447- let event = sse. next_event ( Duration :: from_secs ( 2 ) ) . await . expect ( "Should receive DELETE event" ) ;
492+ let event = sse
493+ . next_event ( Duration :: from_secs ( 2 ) )
494+ . await
495+ . expect ( "Should receive DELETE event" ) ;
448496 assert_eq ! ( event. event_type, "DELETE" ) ;
449497 assert_eq ! ( event. change_event( ) . table, "products" ) ;
450498}
@@ -482,8 +530,7 @@ async fn sse_mutations_different_tables_filtered() {
482530 let server = TestServer :: start_with_app_notifier ( ) . await ;
483531 let mut sse_products =
484532 SseTestClient :: connect ( & server. client , & server. listen_url ( "products" ) ) . await ;
485- let mut sse_tasks =
486- SseTestClient :: connect ( & server. client , & server. listen_url ( "tasks" ) ) . await ;
533+ let mut sse_tasks = SseTestClient :: connect ( & server. client , & server. listen_url ( "tasks" ) ) . await ;
487534 tokio:: time:: sleep ( Duration :: from_millis ( 50 ) ) . await ;
488535
489536 let resp = server
@@ -492,7 +539,10 @@ async fn sse_mutations_different_tables_filtered() {
492539 assert ! ( resp. status( ) . is_success( ) ) ;
493540
494541 let resp = server
495- . post_json ( "/tasks" , & json ! ( { "title" : "PGFilterTask" , "priority" : "low" } ) )
542+ . post_json (
543+ "/tasks" ,
544+ & json ! ( { "title" : "PGFilterTask" , "priority" : "low" } ) ,
545+ )
496546 . await ;
497547 assert ! ( resp. status( ) . is_success( ) ) ;
498548
@@ -508,7 +558,9 @@ async fn sse_mutations_different_tables_filtered() {
508558 . expect ( "tasks client should receive event" ) ;
509559 assert_eq ! ( event. change_event( ) . table, "tasks" ) ;
510560
511- sse_products. expect_no_event ( Duration :: from_millis ( 300 ) ) . await ;
561+ sse_products
562+ . expect_no_event ( Duration :: from_millis ( 300 ) )
563+ . await ;
512564 sse_tasks. expect_no_event ( Duration :: from_millis ( 300 ) ) . await ;
513565}
514566
@@ -536,7 +588,12 @@ async fn pg_notify_raw_sql_produces_sse_event() {
536588 NOTIFY_CHANNEL ,
537589 payload. to_string( ) . replace( '\'' , "''" )
538590 ) ;
539- server. db . pool ( ) . execute ( sql. as_str ( ) ) . await . expect ( "pg_notify failed" ) ;
591+ server
592+ . db
593+ . pool ( )
594+ . execute ( sql. as_str ( ) )
595+ . await
596+ . expect ( "pg_notify failed" ) ;
540597
541598 let event = sse
542599 . next_event ( Duration :: from_secs ( 3 ) )
@@ -547,7 +604,10 @@ async fn pg_notify_raw_sql_produces_sse_event() {
547604 assert_eq ! ( ce. table, "users" ) ;
548605 assert_eq ! ( ce. schema, "test_api" ) ;
549606 // PgChangeNotifier preserves the new/old data from the NOTIFY payload
550- assert ! ( ce. new. is_some( ) , "new should be populated from NOTIFY payload" ) ;
607+ assert ! (
608+ ce. new. is_some( ) ,
609+ "new should be populated from NOTIFY payload"
610+ ) ;
551611 let new_val = ce. new . unwrap ( ) ;
552612 assert_eq ! ( new_val[ "id" ] , 99 ) ;
553613 assert_eq ! ( new_val[ "email" ] , "notify@test.com" ) ;
@@ -596,11 +656,9 @@ async fn pg_notify_with_trigger_produces_event() {
596656 server
597657 . db
598658 . pool ( )
599- . execute (
600- sqlx:: query (
601- "INSERT INTO test_api.users (email, name) VALUES ('trigger@test.com', 'Trigger User')" ,
602- ) ,
603- )
659+ . execute ( sqlx:: query (
660+ "INSERT INTO test_api.users (email, name) VALUES ('trigger@test.com', 'Trigger User')" ,
661+ ) )
604662 . await
605663 . expect ( "INSERT failed" ) ;
606664
@@ -630,7 +688,12 @@ async fn pg_notify_malformed_payload_no_crash() {
630688 "SELECT pg_notify('{}', 'this is not valid json at all')" ,
631689 NOTIFY_CHANNEL
632690 ) ;
633- server. db . pool ( ) . execute ( bad_sql. as_str ( ) ) . await . expect ( "pg_notify failed" ) ;
691+ server
692+ . db
693+ . pool ( )
694+ . execute ( bad_sql. as_str ( ) )
695+ . await
696+ . expect ( "pg_notify failed" ) ;
634697
635698 // Small delay to let the receive_loop process the bad payload
636699 tokio:: time:: sleep ( Duration :: from_millis ( 200 ) ) . await ;
@@ -648,7 +711,12 @@ async fn pg_notify_malformed_payload_no_crash() {
648711 NOTIFY_CHANNEL ,
649712 valid_payload. to_string( ) . replace( '\'' , "''" )
650713 ) ;
651- server. db . pool ( ) . execute ( good_sql. as_str ( ) ) . await . expect ( "pg_notify failed" ) ;
714+ server
715+ . db
716+ . pool ( )
717+ . execute ( good_sql. as_str ( ) )
718+ . await
719+ . expect ( "pg_notify failed" ) ;
652720
653721 let event = sse
654722 . next_event ( Duration :: from_secs ( 3 ) )
@@ -699,7 +767,12 @@ async fn sse_large_notify_payload() {
699767 NOTIFY_CHANNEL ,
700768 payload. to_string( ) . replace( '\'' , "''" )
701769 ) ;
702- server. db . pool ( ) . execute ( sql. as_str ( ) ) . await . expect ( "pg_notify with large payload failed" ) ;
770+ server
771+ . db
772+ . pool ( )
773+ . execute ( sql. as_str ( ) )
774+ . await
775+ . expect ( "pg_notify with large payload failed" ) ;
703776
704777 let event = sse
705778 . next_event ( Duration :: from_secs ( 3 ) )
@@ -716,11 +789,8 @@ async fn sse_large_notify_payload() {
716789#[ ignore]
717790async fn sse_listen_nonexistent_table_connects_pg ( ) {
718791 let server = TestServer :: start_with_app_notifier ( ) . await ;
719- let mut sse = SseTestClient :: connect (
720- & server. client ,
721- & server. listen_url ( "nonexistent_table_xyz" ) ,
722- )
723- . await ;
792+ let mut sse =
793+ SseTestClient :: connect ( & server. client , & server. listen_url ( "nonexistent_table_xyz" ) ) . await ;
724794 tokio:: time:: sleep ( Duration :: from_millis ( 50 ) ) . await ;
725795
726796 let notifier = server. state . notifier . as_ref ( ) . unwrap ( ) ;
0 commit comments