@@ -153,6 +153,21 @@ async fn wait_for_all(test_counter: &std::sync::Arc<TestCounter>) {
153153 test_counter. wait_for_all ( ) ;
154154}
155155
156+ async fn disconnect_connection ( connection : & DbConnection ) {
157+ if connection. is_active ( ) {
158+ connection. disconnect ( ) . unwrap ( ) ;
159+ }
160+
161+ #[ cfg( target_arch = "wasm32" ) ]
162+ {
163+ // wasm tests run inside a long-lived Node event loop. Once the expected callbacks have
164+ // fired, the test must explicitly close its websocket and yield once so the background
165+ // task can process that disconnect before `run()` returns. Native tests can rely on
166+ // process teardown, but web tests will otherwise keep Node alive and appear to hang.
167+ gloo_timers:: future:: TimeoutFuture :: new ( 0 ) . await ;
168+ }
169+ }
170+
156171/// A query that subscribes to all rows from all tables.
157172const SUBSCRIBE_ALL : & [ & str ] = & [
158173 "SELECT * FROM my_table;" ,
@@ -225,6 +240,7 @@ async fn exec_procedure_return_values() {
225240 . await ;
226241
227242 wait_for_all ( & test_counter) . await ;
243+ disconnect_connection ( & _conn) . await ;
228244}
229245
230246async fn exec_procedure_panic ( ) {
@@ -247,6 +263,7 @@ async fn exec_procedure_panic() {
247263 . await ;
248264
249265 wait_for_all ( & test_counter) . await ;
266+ disconnect_connection ( & _conn) . await ;
250267}
251268
252269async fn exec_insert_with_tx_commit ( ) {
@@ -284,6 +301,7 @@ async fn exec_insert_with_tx_commit() {
284301 . await ;
285302
286303 wait_for_all ( & test_counter) . await ;
304+ disconnect_connection ( & _conn) . await ;
287305}
288306
289307async fn exec_insert_with_tx_rollback ( ) {
@@ -311,6 +329,7 @@ async fn exec_insert_with_tx_rollback() {
311329 . await ;
312330
313331 wait_for_all ( & test_counter) . await ;
332+ disconnect_connection ( & _conn) . await ;
314333}
315334
316335/// Test that a procedure can perform an HTTP request and return a string derived from the response.
@@ -348,6 +367,7 @@ async fn exec_procedure_http_ok() {
348367 } )
349368 . await ;
350369 wait_for_all ( & test_counter) . await ;
370+ disconnect_connection ( & _conn) . await ;
351371}
352372
353373/// Test that a procedure can perform an HTTP request, handle its failure and return a string derived from the error.
@@ -379,6 +399,7 @@ async fn exec_procedure_http_err() {
379399 . await ;
380400
381401 wait_for_all ( & test_counter) . await ;
402+ disconnect_connection ( & _conn) . await ;
382403}
383404
384405async fn exec_schedule_procedure ( ) {
@@ -424,6 +445,7 @@ async fn exec_schedule_procedure() {
424445 . await ;
425446
426447 wait_for_all ( & test_counter) . await ;
448+ disconnect_connection ( & _conn) . await ;
427449}
428450
429451/// Test that a procedure can generate sorted UUIDs and insert them into a table
@@ -465,4 +487,5 @@ async fn exec_sorted_uuids_insert() {
465487 . await ;
466488
467489 wait_for_all ( & test_counter) . await ;
490+ disconnect_connection ( & _conn) . await ;
468491}
0 commit comments