testing: Remove once_cell dependency

Use the types that were stabilized in the standard library instead.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
Kévin Commaille
2026-02-20 15:20:03 +01:00
committed by Andy Balaam
parent 4257649933
commit 1dbd2caeb2
11 changed files with 63 additions and 65 deletions
Generated
-2
View File
@@ -3415,7 +3415,6 @@ dependencies = [
"matrix-sdk-test",
"matrix-sdk-test-utils",
"matrix-sdk-ui",
"once_cell",
"rand 0.8.5",
"reqwest",
"serde_json",
@@ -3525,7 +3524,6 @@ dependencies = [
"insta",
"matrix-sdk-common",
"matrix-sdk-test-macros",
"once_cell",
"ruma",
"serde",
"serde_json",
@@ -37,7 +37,6 @@ matrix-sdk-common.workspace = true
matrix-sdk-test.workspace = true
matrix-sdk-test-utils.workspace = true
matrix-sdk-ui = { workspace = true, default-features = true }
once_cell.workspace = true
rand.workspace = true
reqwest.workspace = true
serde_json.workspace = true
@@ -3,7 +3,7 @@ use std::{
ops::Deref,
option_env,
path::{Path, PathBuf},
sync::{Arc, Mutex as StdMutex},
sync::{Arc, LazyLock, Mutex as StdMutex},
time::Duration,
};
@@ -24,14 +24,13 @@ use matrix_sdk::{
};
use matrix_sdk_base::crypto::{CollectStrategy, DecryptionSettings, TrustRequirement};
use matrix_sdk_common::cross_process_lock::CrossProcessLockConfig;
use once_cell::sync::Lazy;
use rand::Rng as _;
use tempfile::{TempDir, tempdir};
use tokio::{sync::Mutex, time::sleep};
/// This global maintains temp directories alive for the whole lifetime of the
/// process.
static TMP_DIRS: Lazy<Mutex<Vec<TempDir>>> = Lazy::new(Mutex::default);
static TMP_DIRS: LazyLock<Mutex<Vec<TempDir>>> = LazyLock::new(Mutex::default);
enum SqlitePath {
Random,
@@ -3,7 +3,7 @@
use std::{
collections::BTreeMap,
sync::{Arc, Mutex as StdMutex},
sync::{Arc, LazyLock, Mutex as StdMutex},
time::Duration,
};
@@ -49,7 +49,6 @@ use matrix_sdk_ui::{
RoomListService, room_list_service::filters::new_filter_all, sync_service::SyncService,
timeline::RoomExt,
};
use once_cell::sync::Lazy;
use rand::Rng as _;
use serde_json::Value;
use stream_assert::assert_pending;
-1
View File
@@ -27,7 +27,6 @@ http.workspace = true
insta.workspace = true
matrix-sdk-common = { version = "0.16.0", path = "../../crates/matrix-sdk-common" }
matrix-sdk-test-macros = { version = "0.16.0", path = "../matrix-sdk-test-macros" }
once_cell.workspace = true
# Enable the unstable feature for polls support.
# "client-api-s" enables need the "server" feature of ruma-client-api, which is needed to serialize Response objects to JSON.
ruma = { workspace = true, features = ["client-api-s", "rand", "unstable-msc3381", "unstable-msc4274"] }
+6 -7
View File
@@ -1,8 +1,7 @@
use std::fmt;
use std::{fmt, sync::LazyLock};
use http::Response;
pub use matrix_sdk_test_macros::async_test;
use once_cell::sync::Lazy;
use ruma::{
RoomId, UserId,
api::{IncomingResponse, OutgoingResponse},
@@ -82,13 +81,13 @@ pub use self::sync_builder::{
SyncResponseBuilder, bulk_room_members,
};
pub static ALICE: Lazy<&UserId> = Lazy::new(|| user_id!("@alice:server.name"));
pub static BOB: Lazy<&UserId> = Lazy::new(|| user_id!("@bob:other.server"));
pub static CAROL: Lazy<&UserId> = Lazy::new(|| user_id!("@carol:other.server"));
pub static ALICE: LazyLock<&UserId> = LazyLock::new(|| user_id!("@alice:server.name"));
pub static BOB: LazyLock<&UserId> = LazyLock::new(|| user_id!("@bob:other.server"));
pub static CAROL: LazyLock<&UserId> = LazyLock::new(|| user_id!("@carol:other.server"));
/// The default room ID for tests.
pub static DEFAULT_TEST_ROOM_ID: Lazy<&RoomId> =
Lazy::new(|| room_id!("!SVkFJHzfwvuaIEawgC:localhost"));
pub static DEFAULT_TEST_ROOM_ID: LazyLock<&RoomId> =
LazyLock::new(|| room_id!("!SVkFJHzfwvuaIEawgC:localhost"));
/// Build a typed Ruma [`IncomingResponse`] object from a json body.
pub fn ruma_response_from_json<ResponseType: IncomingResponse>(
@@ -1,10 +1,11 @@
//! Responses to client API calls.
use once_cell::sync::Lazy;
use std::sync::LazyLock;
use serde_json::{Value as JsonValue, json};
/// `GET /_matrix/client/v3/devices`
pub static DEVICES: Lazy<JsonValue> = Lazy::new(|| {
pub static DEVICES: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"devices": [
{
@@ -26,7 +27,7 @@ pub static DEVICES: Lazy<JsonValue> = Lazy::new(|| {
});
/// `GET /_matrix/client/v3/device/{deviceId}`
pub static DEVICE: Lazy<JsonValue> = Lazy::new(|| {
pub static DEVICE: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"device_id": "QBUAZIFURK",
"display_name": "android",
@@ -36,7 +37,7 @@ pub static DEVICE: Lazy<JsonValue> = Lazy::new(|| {
});
/// `GET /_matrix/client/v3/directory/room/{roomAlias}`
pub static GET_ALIAS: Lazy<JsonValue> = Lazy::new(|| {
pub static GET_ALIAS: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"room_id": "!lUbmUPdxdXxEQurqOs:example.net",
"servers": [
@@ -48,7 +49,7 @@ pub static GET_ALIAS: Lazy<JsonValue> = Lazy::new(|| {
});
/// `POST /_matrix/client/v3/keys/query`
pub static KEYS_QUERY: Lazy<JsonValue> = Lazy::new(|| {
pub static KEYS_QUERY: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"device_keys": {
"@alice:example.org": {
@@ -81,7 +82,7 @@ pub static KEYS_QUERY: Lazy<JsonValue> = Lazy::new(|| {
/// `POST /_matrix/client/v3/keys/query`
/// For a set of 2 devices own by a user named web2.
/// First device is unsigned, second one is signed
pub static KEYS_QUERY_TWO_DEVICES_ONE_SIGNED: Lazy<JsonValue> = Lazy::new(|| {
pub static KEYS_QUERY_TWO_DEVICES_ONE_SIGNED: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"device_keys":{
"@web2:localhost:8482":{
@@ -164,7 +165,7 @@ pub static KEYS_QUERY_TWO_DEVICES_ONE_SIGNED: Lazy<JsonValue> = Lazy::new(|| {
});
/// ``
pub static KEYS_UPLOAD: Lazy<JsonValue> = Lazy::new(|| {
pub static KEYS_UPLOAD: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"one_time_key_counts": {
"curve25519": 10,
@@ -174,7 +175,7 @@ pub static KEYS_UPLOAD: Lazy<JsonValue> = Lazy::new(|| {
});
/// Successful call to `POST /_matrix/client/v3/login` without auto-discovery.
pub static LOGIN: Lazy<JsonValue> = Lazy::new(|| {
pub static LOGIN: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"access_token": "abc123",
"device_id": "GHTYAJCE",
@@ -184,7 +185,7 @@ pub static LOGIN: Lazy<JsonValue> = Lazy::new(|| {
});
/// Successful call to `POST /_matrix/client/v3/login` with auto-discovery.
pub static LOGIN_WITH_DISCOVERY: Lazy<JsonValue> = Lazy::new(|| {
pub static LOGIN_WITH_DISCOVERY: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"access_token": "abc123",
"device_id": "GHTYAJCE",
@@ -202,7 +203,7 @@ pub static LOGIN_WITH_DISCOVERY: Lazy<JsonValue> = Lazy::new(|| {
});
/// Successful call to `POST /_matrix/client/v3/login` with a refresh token.
pub static LOGIN_WITH_REFRESH_TOKEN: Lazy<JsonValue> = Lazy::new(|| {
pub static LOGIN_WITH_REFRESH_TOKEN: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"access_token": "abc123",
"device_id": "GHTYAJCE",
@@ -214,7 +215,7 @@ pub static LOGIN_WITH_REFRESH_TOKEN: Lazy<JsonValue> = Lazy::new(|| {
});
/// Failed call to `POST /_matrix/client/v3/login`
pub static LOGIN_RESPONSE_ERR: Lazy<JsonValue> = Lazy::new(|| {
pub static LOGIN_RESPONSE_ERR: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"errcode": "M_FORBIDDEN",
"error": "Invalid password"
@@ -222,7 +223,7 @@ pub static LOGIN_RESPONSE_ERR: Lazy<JsonValue> = Lazy::new(|| {
});
/// `GET /_matrix/client/v3/login`
pub static LOGIN_TYPES: Lazy<JsonValue> = Lazy::new(|| {
pub static LOGIN_TYPES: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"flows": [
{
@@ -240,7 +241,7 @@ pub static LOGIN_TYPES: Lazy<JsonValue> = Lazy::new(|| {
/// Failed call to an endpoint when the resource that was asked could not be
/// found.
pub static NOT_FOUND: Lazy<JsonValue> = Lazy::new(|| {
pub static NOT_FOUND: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"errcode": "M_NOT_FOUND",
"error": "No resource was found for this request.",
@@ -250,7 +251,7 @@ pub static NOT_FOUND: Lazy<JsonValue> = Lazy::new(|| {
/// `GET /_matrix/client/v3/publicRooms`
/// `POST /_matrix/client/v3/publicRooms`
pub static PUBLIC_ROOMS: Lazy<JsonValue> = Lazy::new(|| {
pub static PUBLIC_ROOMS: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"chunk": [
{
@@ -274,7 +275,7 @@ pub static PUBLIC_ROOMS: Lazy<JsonValue> = Lazy::new(|| {
/// `GET /_matrix/client/v3/publicRooms`
/// `POST /_matrix/client/v3/publicRooms``
pub static PUBLIC_ROOMS_FINAL_PAGE: Lazy<JsonValue> = Lazy::new(|| {
pub static PUBLIC_ROOMS_FINAL_PAGE: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"chunk": [
{
@@ -295,7 +296,7 @@ pub static PUBLIC_ROOMS_FINAL_PAGE: Lazy<JsonValue> = Lazy::new(|| {
});
/// `POST /_matrix/client/v3/refresh` without new refresh token.
pub static REFRESH_TOKEN: Lazy<JsonValue> = Lazy::new(|| {
pub static REFRESH_TOKEN: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"access_token": "5678",
"expire_in_ms": 432000000,
@@ -303,7 +304,7 @@ pub static REFRESH_TOKEN: Lazy<JsonValue> = Lazy::new(|| {
});
/// `POST /_matrix/client/v3/refresh` with a new refresh token.
pub static REFRESH_TOKEN_WITH_REFRESH_TOKEN: Lazy<JsonValue> = Lazy::new(|| {
pub static REFRESH_TOKEN_WITH_REFRESH_TOKEN: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"access_token": "9012",
"expire_in_ms": 432000000,
@@ -312,7 +313,7 @@ pub static REFRESH_TOKEN_WITH_REFRESH_TOKEN: Lazy<JsonValue> = Lazy::new(|| {
});
/// Failed call to `POST /_matrix/client/v3/register`
pub static REGISTRATION_RESPONSE_ERR: Lazy<JsonValue> = Lazy::new(|| {
pub static REGISTRATION_RESPONSE_ERR: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"errcode": "M_FORBIDDEN",
"error": "Invalid password",
@@ -335,7 +336,7 @@ pub static REGISTRATION_RESPONSE_ERR: Lazy<JsonValue> = Lazy::new(|| {
});
/// Failed called to any endpoint with an expired access token.
pub static UNKNOWN_TOKEN_SOFT_LOGOUT: Lazy<JsonValue> = Lazy::new(|| {
pub static UNKNOWN_TOKEN_SOFT_LOGOUT: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"errcode": "M_UNKNOWN_TOKEN",
"error": "Invalid access token passed.",
@@ -344,7 +345,7 @@ pub static UNKNOWN_TOKEN_SOFT_LOGOUT: Lazy<JsonValue> = Lazy::new(|| {
});
/// `GET /_matrix/client/versions`
pub static VERSIONS: Lazy<JsonValue> = Lazy::new(|| {
pub static VERSIONS: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"versions": [
"r0.0.1",
@@ -365,7 +366,7 @@ pub static VERSIONS: Lazy<JsonValue> = Lazy::new(|| {
});
/// `GET /.well-known/matrix/client`
pub static WELL_KNOWN: Lazy<JsonValue> = Lazy::new(|| {
pub static WELL_KNOWN: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"m.homeserver": {
"base_url": "HOMESERVER_URL"
@@ -380,7 +381,7 @@ pub static WELL_KNOWN: Lazy<JsonValue> = Lazy::new(|| {
});
/// `GET /_matrix/client/v3/account/whoami`
pub static WHOAMI: Lazy<JsonValue> = Lazy::new(|| {
pub static WHOAMI: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"user_id": "@joe:example.org"
})
@@ -1,11 +1,12 @@
//! Example responses to `GET /_matrix/client/v3/rooms/{roomId}/members`
use once_cell::sync::Lazy;
use std::sync::LazyLock;
use serde_json::{Value as JsonValue, json};
use super::DEFAULT_TEST_ROOM_ID;
pub static MEMBERS: Lazy<JsonValue> = Lazy::new(|| {
pub static MEMBERS: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"chunk": [
{
+5 -4
View File
@@ -4,7 +4,8 @@
//! truth. When running `cargo publish` no external folders are allowed so all
//! the test data needs to be contained within this crate.
use once_cell::sync::Lazy;
use std::sync::LazyLock;
use serde_json::{Value as JsonValue, json};
use crate::DEFAULT_TEST_ROOM_ID;
@@ -28,17 +29,17 @@ pub use sync::{
};
/// An empty response.
pub static EMPTY: Lazy<JsonValue> = Lazy::new(|| json!({}));
pub static EMPTY: LazyLock<JsonValue> = LazyLock::new(|| json!({}));
/// A response with only an event ID.
pub static EVENT_ID: Lazy<JsonValue> = Lazy::new(|| {
pub static EVENT_ID: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"event_id": "$h29iv0s8:example.com"
})
});
/// A response with only a room ID.
pub static ROOM_ID: Lazy<JsonValue> = Lazy::new(|| {
pub static ROOM_ID: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"room_id": *DEFAULT_TEST_ROOM_ID
})
@@ -1,14 +1,15 @@
use once_cell::sync::Lazy;
use std::sync::LazyLock;
use serde_json::{Value as JsonValue, json};
pub static SEARCH_USERS_REQUEST: Lazy<JsonValue> = Lazy::new(|| {
pub static SEARCH_USERS_REQUEST: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"search_term": "test",
"limit": 50
})
});
pub static SEARCH_USERS_RESPONSE: Lazy<JsonValue> = Lazy::new(|| {
pub static SEARCH_USERS_RESPONSE: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"limited": false,
"results": [
+19 -18
View File
@@ -1,12 +1,13 @@
//! Complete sync responses.
use once_cell::sync::Lazy;
use std::sync::LazyLock;
use ruma::{RoomId, room_id};
use serde_json::{Value as JsonValue, json};
use crate::DEFAULT_TEST_ROOM_ID;
pub static SYNC: Lazy<JsonValue> = Lazy::new(|| {
pub static SYNC: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"device_one_time_keys_count": {},
"next_batch": "s526_47314_0_7_1_1_1_11444_1",
@@ -267,7 +268,7 @@ pub static SYNC: Lazy<JsonValue> = Lazy::new(|| {
})
});
pub static DEFAULT_SYNC_SUMMARY: Lazy<JsonValue> = Lazy::new(|| {
pub static DEFAULT_SYNC_SUMMARY: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"device_one_time_keys_count": {},
"next_batch": "s526_47314_0_7_1_1_1_11444_1",
@@ -525,7 +526,7 @@ pub static DEFAULT_SYNC_SUMMARY: Lazy<JsonValue> = Lazy::new(|| {
})
});
pub static INVITE_SYNC: Lazy<JsonValue> = Lazy::new(|| {
pub static INVITE_SYNC: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"device_one_time_keys_count": {},
"next_batch": "s526_47314_0_7_1_1_1_11444_2",
@@ -584,7 +585,7 @@ pub static INVITE_SYNC: Lazy<JsonValue> = Lazy::new(|| {
})
});
pub static LEAVE_SYNC: Lazy<JsonValue> = Lazy::new(|| {
pub static LEAVE_SYNC: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"device_one_time_keys_count": {},
"next_batch": "s526_47314_0_7_1_1_1_11444_1",
@@ -867,7 +868,7 @@ pub static LEAVE_SYNC: Lazy<JsonValue> = Lazy::new(|| {
})
});
pub static LEAVE_SYNC_EVENT: Lazy<JsonValue> = Lazy::new(|| {
pub static LEAVE_SYNC_EVENT: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"account_data": {
"events": []
@@ -934,7 +935,7 @@ pub static LEAVE_SYNC_EVENT: Lazy<JsonValue> = Lazy::new(|| {
})
});
pub static JOIN_SPACE_SYNC: Lazy<JsonValue> = Lazy::new(|| {
pub static JOIN_SPACE_SYNC: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"device_one_time_keys_count": {},
"next_batch": "s526_47314_0_7_1_1_1_11444_1",
@@ -1197,20 +1198,20 @@ pub static JOIN_SPACE_SYNC: Lazy<JsonValue> = Lazy::new(|| {
});
/// In the [`MIXED_SYNC`], the room id of the joined room.
pub static MIXED_JOINED_ROOM_ID: Lazy<&RoomId> =
Lazy::new(|| room_id!("!SVkFJHzfwvuaIEawgC:localhost"));
pub static MIXED_JOINED_ROOM_ID: LazyLock<&RoomId> =
LazyLock::new(|| room_id!("!SVkFJHzfwvuaIEawgC:localhost"));
/// In the [`MIXED_SYNC`], the room id of the left room.
pub static MIXED_LEFT_ROOM_ID: Lazy<&RoomId> =
Lazy::new(|| room_id!("!SVkFJHzfwvuaIEawgD:localhost"));
pub static MIXED_LEFT_ROOM_ID: LazyLock<&RoomId> =
LazyLock::new(|| room_id!("!SVkFJHzfwvuaIEawgD:localhost"));
/// In the [`MIXED_SYNC`], the room id of the invited room.
pub static MIXED_INVITED_ROOM_ID: Lazy<&RoomId> =
Lazy::new(|| room_id!("!SVkFJHzfwvuaIEawgE:localhost"));
pub static MIXED_INVITED_ROOM_ID: LazyLock<&RoomId> =
LazyLock::new(|| room_id!("!SVkFJHzfwvuaIEawgE:localhost"));
/// In the [`MIXED_SYNC`], the room id of the knocked room.
pub static MIXED_KNOCKED_ROOM_ID: Lazy<&RoomId> =
Lazy::new(|| room_id!("!SVkFJHzfwvuaIEawgF:localhost"));
pub static MIXED_KNOCKED_ROOM_ID: LazyLock<&RoomId> =
LazyLock::new(|| room_id!("!SVkFJHzfwvuaIEawgF:localhost"));
/// A sync that contains updates to joined/invited/knocked/left rooms.
pub static MIXED_SYNC: Lazy<JsonValue> = Lazy::new(|| {
pub static MIXED_SYNC: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"account_data": {
"events": []
@@ -1398,7 +1399,7 @@ pub static MIXED_SYNC: Lazy<JsonValue> = Lazy::new(|| {
})
});
pub static SYNC_ADMIN_AND_MOD: Lazy<JsonValue> = Lazy::new(|| {
pub static SYNC_ADMIN_AND_MOD: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"device_one_time_keys_count": {},
"next_batch": "s526_47314_0_7_1_1_1_11444_1",
@@ -1587,7 +1588,7 @@ pub static SYNC_ADMIN_AND_MOD: Lazy<JsonValue> = Lazy::new(|| {
})
});
pub static CUSTOM_ROOM_POWER_LEVELS: Lazy<JsonValue> = Lazy::new(|| {
pub static CUSTOM_ROOM_POWER_LEVELS: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"device_one_time_keys_count": {},
"next_batch": "s526_47314_0_7_1_1_1_11444_1",