fix migration test with hack
Without sleeping after migration, the tests fail, so...
This commit is contained in:
parent
b691e6ee8d
commit
81adffe7f0
1 changed files with 24 additions and 9 deletions
33
src/db.rs
33
src/db.rs
|
@ -48,15 +48,21 @@ pub async fn get_pool() -> SqlitePool {
|
||||||
.await
|
.await
|
||||||
.expect("can't connect to database");
|
.expect("can't connect to database");
|
||||||
|
|
||||||
let mut m = Migrator::new(std::path::Path::new("./migrations"))
|
{
|
||||||
.await
|
let mut m = Migrator::new(std::path::Path::new("./migrations"))
|
||||||
.expect("Should be able to read the migration directory.");
|
.await
|
||||||
|
.expect("Should be able to read the migration directory.");
|
||||||
|
|
||||||
let m = m.set_locking(true);
|
let m = m.set_locking(true);
|
||||||
|
|
||||||
m.run(&pool)
|
m.run(&pool)
|
||||||
.await
|
.await
|
||||||
.expect("Should be able to run the migration.");
|
.expect("Should be able to run the migration.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// hack to ensure that migration has actually run; surely there is a better
|
||||||
|
// way!!
|
||||||
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||||
|
|
||||||
tracing::info!("Ran migrations");
|
tracing::info!("Ran migrations");
|
||||||
|
|
||||||
|
@ -70,6 +76,10 @@ pub async fn session_layer(pool: SqlitePool, secret: &[u8]) -> SessionLayer<Sqli
|
||||||
.await
|
.await
|
||||||
.expect("Calling `migrate()` should be reliable, is the DB gone?");
|
.expect("Calling `migrate()` should be reliable, is the DB gone?");
|
||||||
|
|
||||||
|
// hack to ensure that migration has actually run; surely there is a better
|
||||||
|
// way!!
|
||||||
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||||
|
|
||||||
// since the secret is new every time the server starts, old sessions won't be
|
// since the secret is new every time the server starts, old sessions won't be
|
||||||
// valid anymore; if there were ever more than one service host or there were
|
// valid anymore; if there were ever more than one service host or there were
|
||||||
// managed secrets, this would need to go away.
|
// managed secrets, this would need to go away.
|
||||||
|
@ -93,14 +103,15 @@ pub async fn auth_layer(
|
||||||
AuthLayer::new(store, secret)
|
AuthLayer::new(store, secret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-************************************************************************
|
||||||
|
// Tests for `db` module.
|
||||||
|
//-************************************************************************
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn it_migrates_the_db() {
|
async fn it_migrates_the_db() {
|
||||||
let db = super::get_pool().await;
|
let db = super::get_pool().await;
|
||||||
tokio::time::sleep(Duration::from_secs(2)).await;
|
|
||||||
let r = sqlx::query("select count(*) from witches")
|
let r = sqlx::query("select count(*) from witches")
|
||||||
.fetch_one(&db)
|
.fetch_one(&db)
|
||||||
.await;
|
.await;
|
||||||
|
@ -108,6 +119,10 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-************************************************************************
|
||||||
|
// End public interface.
|
||||||
|
//-************************************************************************
|
||||||
|
|
||||||
//-************************************************************************
|
//-************************************************************************
|
||||||
// Session store sub-module, not a public lib.
|
// Session store sub-module, not a public lib.
|
||||||
//-************************************************************************
|
//-************************************************************************
|
||||||
|
|
Loading…
Reference in a new issue