Skip to content

Commit fed8b60

Browse files
committed
[bfops/wasm-test]: fixes
1 parent ded62a0 commit fed8b60

7 files changed

Lines changed: 75 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdks/rust/tests/procedure-client/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ web = [
2525
"dep:wasm-bindgen-futures",
2626
"dep:console_error_panic_hook",
2727
"dep:futures",
28+
"dep:gloo-timers",
2829
]
2930

3031
[[bin]]
@@ -41,6 +42,7 @@ env_logger = { workspace = true, optional = true }
4142
tokio = { workspace = true, optional = true }
4243
serde_json.workspace = true
4344
futures = { workspace = true, optional = true }
45+
gloo-timers = { version = "0.3.0", features = ["futures"], optional = true }
4446

4547
wasm-bindgen = { version = "0.2.100", optional = true }
4648
wasm-bindgen-futures = { version = "0.4.45", optional = true }

sdks/rust/tests/procedure-client/src/main.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
157172
const 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

230246
async 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

252269
async 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

289307
async 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

384405
async 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
}

sdks/rust/tests/view-client/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ web = [
2525
"dep:wasm-bindgen-futures",
2626
"dep:console_error_panic_hook",
2727
"dep:futures",
28+
"dep:gloo-timers",
2829
]
2930

3031
[[bin]]
@@ -40,6 +41,7 @@ anyhow.workspace = true
4041
env_logger = { workspace = true, optional = true }
4142
tokio = { workspace = true, optional = true }
4243
futures = { workspace = true, optional = true }
44+
gloo-timers = { version = "0.3.0", features = ["futures"], optional = true }
4345

4446
wasm-bindgen = { version = "0.2.100", optional = true }
4547
wasm-bindgen-futures = { version = "0.4.45", optional = true }

sdks/rust/tests/view-client/src/main.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,21 @@ async fn wait_for_all(test_counter: &std::sync::Arc<TestCounter>) {
129129
test_counter.wait_for_all();
130130
}
131131

132+
async fn disconnect_connection(connection: &DbConnection) {
133+
if connection.is_active() {
134+
connection.disconnect().unwrap();
135+
}
136+
137+
#[cfg(target_arch = "wasm32")]
138+
{
139+
// wasm tests run inside a long-lived Node event loop. Once the expected callbacks have
140+
// fired, the test must explicitly close its websocket and yield once so the background
141+
// task can process that disconnect before `run()` returns. Native tests can rely on
142+
// process teardown, but web tests will otherwise keep Node alive and appear to hang.
143+
gloo_timers::future::TimeoutFuture::new(0).await;
144+
}
145+
}
146+
132147
fn subscribe_these_then(
133148
ctx: &impl RemoteDbContext,
134149
queries: &[&str],
@@ -216,6 +231,7 @@ async fn exec_anonymous_subscribe() {
216231
})
217232
.await;
218233
wait_for_all(&test_counter).await;
234+
disconnect_connection(&_conn).await;
219235
}
220236

221237
async fn exec_anonymous_subscribe_with_query_builder() {
@@ -288,6 +304,7 @@ async fn exec_anonymous_subscribe_with_query_builder() {
288304
})
289305
.await;
290306
wait_for_all(&test_counter).await;
307+
disconnect_connection(&_conn).await;
291308
}
292309

293310
async fn exec_non_anonymous_subscribe() {
@@ -328,6 +345,7 @@ async fn exec_non_anonymous_subscribe() {
328345
})
329346
.await;
330347
wait_for_all(&test_counter).await;
348+
disconnect_connection(&_conn).await;
331349
}
332350

333351
async fn exec_non_table_return() {
@@ -370,6 +388,7 @@ async fn exec_non_table_return() {
370388
})
371389
.await;
372390
wait_for_all(&test_counter).await;
391+
disconnect_connection(&_conn).await;
373392
}
374393

375394
async fn exec_non_table_query_builder_return() {
@@ -417,6 +436,7 @@ async fn exec_non_table_query_builder_return() {
417436
})
418437
.await;
419438
wait_for_all(&test_counter).await;
439+
disconnect_connection(&_conn).await;
420440
}
421441

422442
async fn exec_subscription_update() {
@@ -482,4 +502,6 @@ async fn exec_subscription_update() {
482502
)
483503
.await;
484504
wait_for_all(&test_counter).await;
505+
disconnect_connection(&_conn_0).await;
506+
disconnect_connection(&_conn_1).await;
485507
}

sdks/rust/tests/view-pk-client/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ web = [
2323
"dep:wasm-bindgen-futures",
2424
"dep:console_error_panic_hook",
2525
"dep:futures",
26+
"dep:gloo-timers",
2627
]
2728

2829
[[bin]]
@@ -37,6 +38,7 @@ anyhow.workspace = true
3738
env_logger = { workspace = true, optional = true }
3839
tokio = { workspace = true, optional = true }
3940
futures = { workspace = true, optional = true }
41+
gloo-timers = { version = "0.3.0", features = ["futures"], optional = true }
4042

4143
wasm-bindgen = { version = "0.2.100", optional = true }
4244
wasm-bindgen-futures = { version = "0.4.45", optional = true }

sdks/rust/tests/view-pk-client/src/main.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ async fn wait_for_all(test_counter: &std::sync::Arc<TestCounter>) {
102102
test_counter.wait_for_all();
103103
}
104104

105+
async fn disconnect_connection(connection: &DbConnection) {
106+
if connection.is_active() {
107+
connection.disconnect().unwrap();
108+
}
109+
110+
#[cfg(target_arch = "wasm32")]
111+
{
112+
// wasm tests run inside a long-lived Node event loop. Once the expected callbacks have
113+
// fired, the test must explicitly close its websocket and yield once so the background
114+
// task can process that disconnect before `run()` returns. Native tests can rely on
115+
// process teardown, but web tests will otherwise keep Node alive and appear to hang.
116+
gloo_timers::future::TimeoutFuture::new(0).await;
117+
}
118+
}
119+
105120
fn subscribe_these_then(
106121
ctx: &impl RemoteDbContext,
107122
queries: &[&str],
@@ -161,6 +176,7 @@ async fn exec_view_pk_on_update() {
161176
.await;
162177

163178
wait_for_all(&test_counter).await;
179+
disconnect_connection(&_conn).await;
164180
}
165181

166182
/// Subscribe to a right semijoin whose rhs is a view with primary key.
@@ -239,6 +255,7 @@ async fn exec_view_pk_join_query_builder() {
239255
.await;
240256

241257
wait_for_all(&test_counter).await;
258+
disconnect_connection(&_conn).await;
242259
}
243260

244261
/// Subscribe to a semijoin between two views with primary keys.
@@ -327,6 +344,7 @@ async fn exec_view_pk_semijoin_two_sender_views_query_builder() {
327344
.await;
328345

329346
wait_for_all(&test_counter).await;
347+
disconnect_connection(&_conn).await;
330348
}
331349

332350
#[cfg(not(target_arch = "wasm32"))]
@@ -346,7 +364,9 @@ pub(crate) async fn dispatch(test: &str) {
346364
match &*test {
347365
"view-pk-on-update" => exec_view_pk_on_update().await,
348366
"view-pk-join-query-builder" => exec_view_pk_join_query_builder().await,
349-
"view-pk-semijoin-two-sender-views-query-builder" => exec_view_pk_semijoin_two_sender_views_query_builder().await,
367+
"view-pk-semijoin-two-sender-views-query-builder" => {
368+
exec_view_pk_semijoin_two_sender_views_query_builder().await
369+
}
350370
_ => panic!("Unknown test: {test}"),
351371
}
352372
}

0 commit comments

Comments
 (0)