fix: sqlx::macro db cleanup race condition by adding a margin to current timestamp (#2640)

* fix: sqlx::macro db cleanup race condition by adding a margin to current timestamp

* feat: increase margin to 2 seconds
This commit is contained in:
Fernando Gonçalves
2023-10-11 20:03:53 -03:00
committed by GitHub
parent 5ebe296ecb
commit 3c2471e2dc
2 changed files with 5 additions and 2 deletions

View File

@@ -183,7 +183,8 @@ async fn test_context(args: &TestArgs) -> Result<TestContext<Postgres>, Error> {
}
async fn do_cleanup(conn: &mut PgConnection, created_before: Duration) -> Result<usize, Error> {
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<String> = query_scalar(
"select db_name from _sqlx_test.databases \