Skip to content

Commit c8bffa2

Browse files
mgoldenbergHywan
authored andcommitted
test(event-cache-store): make time-based integration tests compatible with wasm targets
Signed-off-by: Michael Goldenberg <[email protected]>
1 parent b4ef6ce commit c8bffa2

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

Cargo.lock

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

crates/matrix-sdk-base/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ js = [
2525
"matrix-sdk-store-encryption/js",
2626
]
2727
qrcode = ["matrix-sdk-crypto?/qrcode"]
28-
automatic-room-key-forwarding = ["matrix-sdk-crypto?/automatic-room-key-forwarding"]
29-
experimental-send-custom-to-device = ["matrix-sdk-crypto?/experimental-send-custom-to-device"]
28+
automatic-room-key-forwarding = [
29+
"matrix-sdk-crypto?/automatic-room-key-forwarding",
30+
]
31+
experimental-send-custom-to-device = [
32+
"matrix-sdk-crypto?/experimental-send-custom-to-device",
33+
]
3034
uniffi = ["dep:uniffi", "matrix-sdk-crypto?/uniffi", "matrix-sdk-common/uniffi"]
3135

3236
# Private feature, see
@@ -101,6 +105,7 @@ tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
101105

102106
[target.'cfg(target_family = "wasm")'.dev-dependencies]
103107
wasm-bindgen-test.workspace = true
108+
gloo-timers = { workspace = true, features = ["futures"] }
104109

105110
[lints]
106111
workspace = true

crates/matrix-sdk-base/src/event_cache/store/integration_tests.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,11 +1432,14 @@ macro_rules! event_cache_store_integration_tests {
14321432
#[macro_export]
14331433
macro_rules! event_cache_store_integration_tests_time {
14341434
() => {
1435-
#[cfg(not(target_family = "wasm"))]
14361435
mod event_cache_store_integration_tests_time {
14371436
use std::time::Duration;
14381437

1438+
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
1439+
use gloo_timers::future::sleep;
14391440
use matrix_sdk_test::async_test;
1441+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
1442+
use tokio::time::sleep;
14401443
use $crate::event_cache::store::IntoEventCacheStore;
14411444

14421445
use super::get_event_cache_store;
@@ -1465,26 +1468,26 @@ macro_rules! event_cache_store_integration_tests_time {
14651468
assert!(!acquired5);
14661469

14671470
// That's a nice test we got here, go take a little nap.
1468-
tokio::time::sleep(Duration::from_millis(50)).await;
1471+
sleep(Duration::from_millis(50)).await;
14691472

14701473
// Still too early.
14711474
let acquired55 = store.try_take_leased_lock(300, "key", "bob").await.unwrap();
14721475
assert!(!acquired55);
14731476

14741477
// Ok you can take another nap then.
1475-
tokio::time::sleep(Duration::from_millis(250)).await;
1478+
sleep(Duration::from_millis(250)).await;
14761479

14771480
// At some point, we do get the lock.
14781481
let acquired6 = store.try_take_leased_lock(0, "key", "bob").await.unwrap();
14791482
assert!(acquired6);
14801483

1481-
tokio::time::sleep(Duration::from_millis(1)).await;
1484+
sleep(Duration::from_millis(1)).await;
14821485

14831486
// The other gets it almost immediately too.
14841487
let acquired7 = store.try_take_leased_lock(0, "key", "alice").await.unwrap();
14851488
assert!(acquired7);
14861489

1487-
tokio::time::sleep(Duration::from_millis(1)).await;
1490+
sleep(Duration::from_millis(1)).await;
14881491

14891492
// But when we take a longer lease...
14901493
let acquired8 = store.try_take_leased_lock(300, "key", "bob").await.unwrap();

0 commit comments

Comments
 (0)