Skip to content

Commit

Permalink
cont
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Nov 6, 2024
1 parent a2b1df1 commit ebd0242
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions benchmarks/benches/room_list_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criteri
use futures_util::{pin_mut, StreamExt};
use matrix_sdk::test_utils::logged_in_client_with_server;
use matrix_sdk_ui::{room_list_service::filters::new_filter_non_left, RoomListService};
use serde::Deserialize;
use serde_json::{json, Map, Value};
use tokio::runtime::Builder;
use wiremock::{http::Method, Match, Mock, Request, ResponseTemplate};
Expand All @@ -16,11 +15,6 @@ impl Match for SlidingSyncMatcher {
}
}

#[derive(Deserialize)]
pub(crate) struct PartialSlidingSyncRequest {
pub txn_id: Option<String>,
}

fn criterion() -> Criterion {
#[cfg(target_os = "linux")]
let criterion = Criterion::default().with_profiler(pprof::criterion::PProfProfiler::new(
Expand Down Expand Up @@ -99,30 +93,25 @@ pub fn room_list(c: &mut Criterion) {
};

// Mock the response from the server.
let _mock_guard = Mock::given(SlidingSyncMatcher)
.respond_with(move |request: &Request| {
let partial_request: PartialSlidingSyncRequest =
request.body_json().unwrap();

ResponseTemplate::new(200).set_body_json(json!({
"txn_id": partial_request.txn_id,
"pos": "raclette",
"rooms": rooms,
}))
})
let mock_guard = Mock::given(SlidingSyncMatcher)
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
"pos": "raclette",
"rooms": rooms,
})))
.mount_as_scoped(&server)
.await;

(&runtime, client, server, room_list_service)
(&runtime, client, server, room_list_service, mock_guard)
})
},
|(runtime, _client, _server, room_list_service)| {
runtime.block_on(async {
|(runtime, client, server, room_list_service, mock_guard)| {
runtime.block_on(async move {
// Get the `RoomListService` sync stream.
let room_list_stream = room_list_service.sync();
pin_mut!(room_list_stream);

// Get the `RoomList` itself with a default filter.
// // Get the `RoomList` itself with a default
// filter.
let room_list = room_list_service
.all_rooms()
.await
Expand All @@ -147,6 +136,10 @@ pub fn room_list(c: &mut Criterion) {
room_list_entries.next().await.is_some(),
"`room_list_entries` has stopped"
);

let _ = mock_guard;
let _ = client;
let _ = server;
})
},
BatchSize::SmallInput,
Expand Down

0 comments on commit ebd0242

Please sign in to comment.