diff --git a/sqlx-mysql/src/testing/mod.rs b/sqlx-mysql/src/testing/mod.rs index 0f7e27ada3..6c25100f0d 100644 --- a/sqlx-mysql/src/testing/mod.rs +++ b/sqlx-mysql/src/testing/mod.rs @@ -176,11 +176,13 @@ async fn test_context(args: &TestArgs) -> Result, Error> { } async fn do_cleanup(conn: &mut MySqlConnection, created_before: Duration) -> Result { + // since SystemTime is not monotonic we added a little margin here to avoid race conditions with other threads + let created_before_as_secs = created_before.as_secs() - 2; let delete_db_ids: Vec = query_scalar( "select db_id from _sqlx_test_databases \ where created_at < from_unixtime(?)", ) - .bind(&created_before.as_secs()) + .bind(&created_before_as_secs) .fetch_all(&mut *conn) .await?; diff --git a/sqlx-postgres/src/testing/mod.rs b/sqlx-postgres/src/testing/mod.rs index 1dfacecbe4..2d2f203b23 100644 --- a/sqlx-postgres/src/testing/mod.rs +++ b/sqlx-postgres/src/testing/mod.rs @@ -183,7 +183,8 @@ async fn test_context(args: &TestArgs) -> Result, Error> { } async fn do_cleanup(conn: &mut PgConnection, created_before: Duration) -> Result { - let created_before = i64::try_from(created_before.as_secs()).unwrap(); + // since SystemTime is not monotonic we added a little margin here to avoid race conditions with other threads + let created_before = i64::try_from(created_before.as_secs()).unwrap() - 2; let delete_db_names: Vec = query_scalar( "select db_name from _sqlx_test.databases \