Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ repos:
language: system
types: [nix]
exclude: extra
- id: sqlx-test-needs-migrator
name: Require `#[sqlx::test(migrator = "crate::MIGRATOR")]` for test-build speed
entry: '#\[sqlx::test\]'
language: pygrep
types: [rust]
10 changes: 5 additions & 5 deletions opsqueue/src/common/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ pub mod test {
use super::db::*;
use super::*;

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_insert_chunk(db: sqlx::SqlitePool) {
let db = WriterPool::new(db);
let mut conn = db.writer_conn().await.unwrap();
Expand All @@ -622,7 +622,7 @@ pub mod test {
assert!(count_chunks(&mut conn).await.unwrap() == u63::new(1));
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_get_chunk(db: sqlx::SqlitePool) {
let db = WriterPool::new(db);
let mut conn = db.writer_conn().await.unwrap();
Expand All @@ -642,7 +642,7 @@ pub mod test {
assert!(chunk == fetched_chunk);
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_complete_chunk_raw(db: sqlx::SqlitePool) {
let db = WriterPool::new(db);
let mut conn = db.writer_conn().await.unwrap();
Expand Down Expand Up @@ -680,7 +680,7 @@ pub mod test {
assert!(count_chunks_failed(&mut conn).await.unwrap() == u63::new(0));
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_complete_chunk_raw_updates_submissions_chunk_total(db: sqlx::SqlitePool) {
let db = WriterPool::new(db);
let mut conn = db.writer_conn().await.unwrap();
Expand Down Expand Up @@ -723,7 +723,7 @@ pub mod test {
}
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_fail_chunk(db: sqlx::SqlitePool) {
let db = WriterPool::new(db);
let mut conn = db.writer_conn().await.unwrap();
Expand Down
22 changes: 11 additions & 11 deletions opsqueue/src/common/submission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ pub mod test {
);
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_query_plan_submission_status_in_progress(db: sqlx::SqlitePool) {
let mut conn = db.acquire().await.unwrap();
let query = r#"
Expand Down Expand Up @@ -1098,7 +1098,7 @@ pub mod test {
");
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_query_plan_submission_status_completed(db: sqlx::SqlitePool) {
let mut conn = db.acquire().await.unwrap();
let query = r#"
Expand Down Expand Up @@ -1126,7 +1126,7 @@ pub mod test {
");
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_query_plan_submission_status_failed(db: sqlx::SqlitePool) {
let mut conn = db.acquire().await.unwrap();
let query = r#"
Expand Down Expand Up @@ -1156,7 +1156,7 @@ pub mod test {
");
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_query_plan_submission_status_cancelled(db: sqlx::SqlitePool) {
let mut conn = db.acquire().await.unwrap();
let query = r#"
Expand All @@ -1183,7 +1183,7 @@ pub mod test {
");
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_insert_submission(db: sqlx::SqlitePool) {
let db = WriterPool::new(db);
let mut conn = db.writer_conn().await.unwrap();
Expand All @@ -1203,7 +1203,7 @@ pub mod test {
assert_matches!(count_submissions(&mut conn).await, Ok(1));
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_get_submission(db: sqlx::SqlitePool) {
let db = WriterPool::new(db);
let mut conn = db.writer_conn().await.unwrap();
Expand All @@ -1226,7 +1226,7 @@ pub mod test {
assert_eq!(fetched_submission, submission);
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_submission_strategic_metadata(db: sqlx::SqlitePool) {
let strategic_metadata: StrategicMetadataMap =
[("company_id".to_string(), 123), ("flavour".to_string(), 42)]
Expand All @@ -1253,7 +1253,7 @@ pub mod test {
assert_eq!(fetched_metadata, strategic_metadata);
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_complete_submission_raw(db: sqlx::SqlitePool) {
let db = WriterPool::new(db);
let mut conn = db.writer_conn().await.unwrap();
Expand All @@ -1278,7 +1278,7 @@ pub mod test {
assert_matches!(count_submissions_failed(&mut conn).await, Ok(0));
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_fail_submission_raw(db: sqlx::SqlitePool) {
let db = WriterPool::new(db);
let mut conn = db.writer_conn().await.unwrap();
Expand All @@ -1305,7 +1305,7 @@ pub mod test {
assert_matches!(count_submissions_failed(&mut conn).await, Ok(1));
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_cleanup_old(db: sqlx::SqlitePool) {
let db = WriterPool::new(db);
let mut conn = db.writer_conn().await.unwrap();
Expand Down Expand Up @@ -1432,7 +1432,7 @@ pub mod test {
let _sub2 = submission_status(old_four_unfailed, &mut conn).await;
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
/// Test whether empty submissions are marked as completed right away by `insert_submission_from_chunks`.
pub async fn auto_complete_empty_submission(db: sqlx::SqlitePool) {
let db = WriterPool::new(db);
Expand Down
2 changes: 1 addition & 1 deletion opsqueue/src/consumer/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ mod tests {

use super::*;

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_fetch_chunks(pool: sqlx::SqlitePool) {
let db_pools = db::DBPools::from_test_pool(&pool);
let uri = "0.0.0.0:10083";
Expand Down
16 changes: 8 additions & 8 deletions opsqueue/src/consumer/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub mod test {
);
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_query_plan_oldest(db: sqlx::SqlitePool) {
let mut conn = db.acquire().await.unwrap();
let mut qb = QueryBuilder::new("");
Expand All @@ -162,7 +162,7 @@ pub mod test {
assert_eq!(explained, "3, 0, SCAN chunks");
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_query_plan_newest(db: sqlx::SqlitePool) {
let mut conn = db.acquire().await.unwrap();
let mut qb = QueryBuilder::new("");
Expand All @@ -185,7 +185,7 @@ pub mod test {
assert_eq!(explained, "3, 0, SCAN chunks");
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_query_plan_random(db: sqlx::SqlitePool) {
let mut conn = db.acquire().await.unwrap();
let metastate = MetaState::default();
Expand Down Expand Up @@ -221,7 +221,7 @@ pub mod test {
");
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_query_plan_prefer_distinct_oldest(db: sqlx::SqlitePool) {
use Strategy::*;
let mut conn = db.acquire().await.unwrap();
Expand Down Expand Up @@ -307,7 +307,7 @@ pub mod test {
");
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_query_plan_prefer_distinct_newest(db: sqlx::SqlitePool) {
use Strategy::*;
let mut conn = db.acquire().await.unwrap();
Expand Down Expand Up @@ -393,7 +393,7 @@ pub mod test {
");
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_query_plan_prefer_distinct_random(db: sqlx::SqlitePool) {
use Strategy::*;
let mut conn = db.acquire().await.unwrap();
Expand Down Expand Up @@ -502,7 +502,7 @@ pub mod test {
");
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
pub async fn test_query_plan_prefer_distinct_nested(db: sqlx::SqlitePool) {
use Strategy::*;
let mut conn = db.acquire().await.unwrap();
Expand Down Expand Up @@ -726,7 +726,7 @@ pub mod test {
use crate::db::Connection;
use futures::stream::TryStreamExt as _;

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
/// Tests whether the 'cutting the deck' technique is working
///
/// We do this by checking whether two selects in a huge amount of available chunks
Expand Down
6 changes: 6 additions & 0 deletions opsqueue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ pub const VERSION_CARGO_SEMVER: &str = env!("CARGO_PKG_VERSION");
pub fn version_info() -> String {
format!("v{VERSION_CARGO_SEMVER}")
}

/// Shared constant with the migrations that all the tests can reference, to avoid the generated
/// code bloat as described in
/// https://kobzol.github.io/rust/2026/06/21/optimizing-sqlx-test-rebuild-time.html
#[cfg(all(test, feature = "server-logic"))]
const MIGRATOR: sqlx::migrate::Migrator = sqlx::migrate!();
Comment thread
jerbaroo marked this conversation as resolved.
6 changes: 3 additions & 3 deletions opsqueue/src/producer/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ mod tests {
tokio::task::yield_now().await;
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
async fn test_count_submissions(pool: sqlx::SqlitePool) {
let url = "0.0.0.0:4002";
start_server_in_background(&pool, url).await;
Expand All @@ -339,7 +339,7 @@ mod tests {
assert_eq!(count, 1);
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
async fn test_insert_submission(pool: sqlx::SqlitePool) {
let url = "0.0.0.0:4000";
start_server_in_background(&pool, url).await;
Expand Down Expand Up @@ -389,7 +389,7 @@ mod tests {
assert_eq!(count, 4);
}

#[sqlx::test]
#[sqlx::test(migrator = "crate::MIGRATOR")]
async fn test_get_submission(pool: sqlx::SqlitePool) {
let url = "0.0.0.0:4001";
start_server_in_background(&pool, url).await;
Expand Down
Loading