feat(gpodder_sqlite): switch to on-disk sqlite for tests and benches

This commit is contained in:
Jef Roosens 2025-03-20 19:19:54 +01:00
parent d329a0e61c
commit 5f57d85584
No known key found for this signature in database
GPG key ID: 21FD3D77D56BAF49
5 changed files with 51 additions and 12 deletions

View file

@ -1,8 +1,17 @@
use std::path::PathBuf;
use gpodder::{AuthStore, User};
use gpodder_sqlite::SqliteRepository;
use rand::{distributions::Alphanumeric, Rng};
pub fn setup() -> (SqliteRepository, Vec<User>) {
let store = SqliteRepository::in_memory().unwrap();
pub fn setup() -> (PathBuf, SqliteRepository, Vec<User>) {
let fname: String = rand::thread_rng()
.sample_iter(Alphanumeric)
.take(10)
.map(char::from)
.collect();
let path = std::env::temp_dir().join(fname);
let store = SqliteRepository::from_path(&path).unwrap();
let mut users = Vec::new();
for i in 0..1000 {
@ -12,5 +21,9 @@ pub fn setup() -> (SqliteRepository, Vec<User>) {
users.push(store.insert_user(&username, &password_hash).unwrap());
}
(store, users)
(path, store, users)
}
pub fn teardown(path: PathBuf) {
let _ = std::fs::remove_file(path);
}

View file

@ -4,7 +4,7 @@ use criterion::{criterion_group, criterion_main, Criterion};
use gpodder::{DevicePatch, DeviceRepository};
pub fn bench_devices_for_user(c: &mut Criterion) {
let (store, users) = common::setup();
let (path, store, users) = common::setup();
for i in 0..100000 {
store
@ -22,6 +22,8 @@ pub fn bench_devices_for_user(c: &mut Criterion) {
c.bench_function("devices for user", |b| {
b.iter(|| store.devices_for_user(&users[0]).unwrap())
});
common::teardown(path);
}
criterion_group!(devices, bench_devices_for_user);