Skip to content

Commit 02b0954

Browse files
committed
integration tests: simplify maintaining temp directories alive
1 parent 68670ba commit 02b0954

File tree

1 file changed

+8
-23
lines changed
  • testing/matrix-sdk-integration-testing/src

1 file changed

+8
-23
lines changed

testing/matrix-sdk-integration-testing/src/helpers.rs

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::{
2-
collections::HashMap,
32
ops::Deref,
43
option_env,
54
path::{Path, PathBuf},
@@ -12,20 +11,17 @@ use assign::assign;
1211
use matrix_sdk::{
1312
config::{RequestConfig, SyncSettings},
1413
encryption::EncryptionSettings,
15-
ruma::{
16-
api::client::{account::register::v3::Request as RegistrationRequest, uiaa},
17-
OwnedDeviceId, OwnedUserId,
18-
},
14+
ruma::api::client::{account::register::v3::Request as RegistrationRequest, uiaa},
1915
Client, ClientBuilder,
2016
};
2117
use once_cell::sync::Lazy;
2218
use rand::Rng as _;
2319
use tempfile::{tempdir, TempDir};
2420
use tokio::sync::Mutex;
2521

26-
#[allow(clippy::type_complexity)]
27-
static USERS: Lazy<Mutex<HashMap<(OwnedUserId, OwnedDeviceId), (Client, TempDir)>>> =
28-
Lazy::new(Mutex::default);
22+
/// This global maintains temp directories alive for the whole lifetime of the
23+
/// process.
24+
static TMP_DIRS: Lazy<Mutex<Vec<TempDir>>> = Lazy::new(Mutex::default);
2925

3026
enum SqlitePath {
3127
Random,
@@ -124,15 +120,14 @@ impl TestClientBuilder {
124120
}
125121

126122
pub async fn build(self) -> Result<Client> {
127-
let mut users = USERS.lock().await;
128-
129-
let tmp_dir = tempdir()?;
130-
131123
let client_builder = self.common_client_builder();
132124
let client = match self.use_sqlite_dir {
133125
None => client_builder.build().await?,
134126
Some(SqlitePath::Random) => {
135-
client_builder.sqlite_store(tmp_dir.path(), None).build().await?
127+
let tmp_dir = tempdir()?;
128+
let client = client_builder.sqlite_store(tmp_dir.path(), None).build().await?;
129+
TMP_DIRS.lock().await.push(tmp_dir);
130+
client
136131
}
137132
Some(SqlitePath::Path(path_buf)) => {
138133
client_builder.sqlite_store(&path_buf, None).build().await?
@@ -160,16 +155,6 @@ impl TestClientBuilder {
160155
auth.login_username(&self.username, &self.username).await?;
161156
}
162157

163-
let user_id = client
164-
.user_id()
165-
.expect("We should have access to our user ID now that we logged in.")
166-
.to_owned();
167-
let device_id = client
168-
.device_id()
169-
.expect("We should have access to our device ID now that we logged in.")
170-
.to_owned();
171-
users.insert((user_id, device_id), (client.clone(), tmp_dir)); // keeping temp dir around so it doesn't get destroyed yet
172-
173158
Ok(client)
174159
}
175160
}

0 commit comments

Comments
 (0)