Skip to content

Commit

Permalink
Fix: avoid Admin API race condition (#30)
Browse files Browse the repository at this point in the history
<!--
Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
-->
  • Loading branch information
avdb13 authored Feb 19, 2024
1 parent 2da3045 commit 5a74daf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 45 deletions.
1 change: 0 additions & 1 deletion crates/matrix/src/admin/resources/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod room;
pub mod token;
pub mod user;
pub mod user_id;
3 changes: 2 additions & 1 deletion crates/matrix/src/admin/resources/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ pub struct ListRoomQuery {
pub search_term: String,
}

#[derive(Debug, Serialize)]
#[derive(Debug, Default, Serialize)]
pub struct MessagesQuery {
#[serde(skip_serializing_if = "String::is_empty")]
pub from: String,

#[serde(skip_serializing_if = "String::is_empty")]
Expand Down
38 changes: 0 additions & 38 deletions crates/matrix/src/admin/resources/user_id.rs

This file was deleted.

28 changes: 23 additions & 5 deletions crates/test/src/matrix/room_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
mod tests {
use std::{thread, time::Duration};

use futures::TryFutureExt;
use futures::{future, TryFutureExt};
use matrix::{
admin::resources::room::{ListRoomQuery, MessagesQuery, RoomService as AdminRoomService},
ruma_common::{RoomId, ServerName},
ruma_events::{room::name::OriginalRoomNameEvent, AnyTimelineEvent, TimelineEventType},
};

use tokio::sync::OnceCell;
Expand All @@ -22,15 +23,32 @@ mod tests {
admin,
} = TEST.get_or_init(util::init).await;

// TODO
thread::sleep(Duration::from_secs(5));

let resp: Vec<_> = AdminRoomService::get_all(admin, ListRoomQuery::default())
.map_ok(|resp| resp.rooms)
.await
.unwrap();

dbg!(samples.iter().map(|s| s.owner()).collect::<Vec<_>>());
while let Some(_) = future::try_join_all(resp.iter().map(|r| {
AdminRoomService::get_room_events(admin, &r.room_id, Default::default())
.map_ok(|resp| resp.chunk.deserialize().unwrap())
}))
.await
.map(|ok| {
ok.into_iter().find(|chunk| {
chunk
.iter()
.all(|event| event.event_type() != TimelineEventType::RoomName)
})
})
.unwrap()
{
tokio::time::sleep(Duration::from_secs(2)).await;
}

let resp: Vec<_> = AdminRoomService::get_all(admin, ListRoomQuery::default())
.map_ok(|resp| resp.rooms)
.await
.unwrap();

assert_eq!(
samples
Expand Down

0 comments on commit 5a74daf

Please sign in to comment.