Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Fix panic in receive_emails benchmark #6306

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions benches/receive_emails.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ use deltachat::{
};
use tempfile::tempdir;

async fn recv_all_emails(context: Context) -> Context {
async fn recv_all_emails(context: Context, iteration: u32) -> Context {
for i in 0..100 {
let imf_raw = format!(
"Subject: Benchmark
Message-ID: Mr.OssSYnOFkhR.{i}@testrun.org
Message-ID: Mr.{iteration}.{i}@testrun.org
Date: Sat, 07 Dec 2019 19:00:27 +0000
To: [email protected]
From: [email protected]
Chat-Version: 1.0
Chat-Disposition-Notification-To: [email protected]
Chat-User-Avatar: 0
In-Reply-To: Mr.OssSYnOFkhR.{i_dec}@testrun.org
In-Reply-To: Mr.{iteration}.{i_dec}@testrun.org
MIME-Version: 1.0

Content-Type: text/plain; charset=utf-8; format=flowed; delsp=no
Expand All @@ -41,25 +41,24 @@ Hello {i}",

/// Receive 100 emails that remove [email protected] and add
/// him back
async fn recv_groupmembership_emails(context: Context) -> Context {
async fn recv_groupmembership_emails(context: Context, iteration: u32) -> Context {
for i in 0..50 {
let imf_raw = format!(
"Subject: Benchmark
Message-ID: Gr.OssSYnOFkhR.{i}@testrun.org
Message-ID: Gr.{iteration}.ADD.{i}@testrun.org
Date: Sat, 07 Dec 2019 19:00:27 +0000
To: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
From: [email protected]
Chat-Version: 1.0
Chat-Disposition-Notification-To: [email protected]
Chat-User-Avatar: 0
Chat-Group-Member-Added: [email protected]
In-Reply-To: Gr.OssSYnOFkhR.{i_dec}@testrun.org
In-Reply-To: Gr.{iteration}.REMOVE.{i_dec}@testrun.org
MIME-Version: 1.0

Content-Type: text/plain; charset=utf-8; format=flowed; delsp=no

Hello {i}",
i = i,
i_dec = i - 1,
);
receive_imf(&context, black_box(imf_raw.as_bytes()), false)
Expand All @@ -68,22 +67,20 @@ Hello {i}",

let imf_raw = format!(
"Subject: Benchmark
Message-ID: Gr.OssSYnOFkhR.{i}@testrun.org
Message-ID: Gr.{iteration}.REMOVE.{i}@testrun.org
Date: Sat, 07 Dec 2019 19:00:27 +0000
To: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
From: [email protected]
Chat-Version: 1.0
Chat-Disposition-Notification-To: [email protected]
Chat-User-Avatar: 0
Chat-Group-Member-Removed: [email protected]
In-Reply-To: Gr.OssSYnOFkhR.{i_dec}@testrun.org
In-Reply-To: Gr.{iteration}.ADD.{i}@testrun.org
MIME-Version: 1.0

Content-Type: text/plain; charset=utf-8; format=flowed; delsp=no

Hello {i}",
i = i,
i_dec = i - 1,
Hello {i}"
);
receive_imf(&context, black_box(imf_raw.as_bytes()), false)
.await
Expand Down Expand Up @@ -129,11 +126,13 @@ fn criterion_benchmark(c: &mut Criterion) {
group.bench_function("Receive 100 simple text msgs", |b| {
let rt = tokio::runtime::Runtime::new().unwrap();
let context = rt.block_on(create_context());
let mut i = 0;

b.to_async(&rt).iter(|| {
let ctx = context.clone();
i += 1;
async move {
recv_all_emails(black_box(ctx)).await;
recv_all_emails(black_box(ctx), i).await;
}
});
});
Expand All @@ -142,11 +141,13 @@ fn criterion_benchmark(c: &mut Criterion) {
|b| {
let rt = tokio::runtime::Runtime::new().unwrap();
let context = rt.block_on(create_context());
let mut i = 0;

b.to_async(&rt).iter(|| {
let ctx = context.clone();
i += 1;
async move {
recv_groupmembership_emails(black_box(ctx)).await;
recv_groupmembership_emails(black_box(ctx), i).await;
}
});
},
Expand Down
Loading