-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Fix panic in
receive_emails
benchmark (#6306)
The benchmark function (e.g. `recv_all_emails()`) is executed multiple times on the same context. During the second iteration, all the emails were already in the database, so, receiving them again failed. This PR fixes that by passing in a second `iteration` counter that is different for every invocation of the benchmark function.
- Loading branch information
Showing
1 changed file
with
15 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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) | ||
|
@@ -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 | ||
|
@@ -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; | ||
} | ||
}); | ||
}); | ||
|
@@ -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; | ||
} | ||
}); | ||
}, | ||
|