如何测试rust中使用deadpool-postgres池的基于actix-web的服务器应用程序的函数?



我正在构建一个web服务器使用actix-web(版本3)和deadpool-postgres池管理器连接到数据库。我想创建一个运行存储过程的测试,但是当我运行cargo test时,我一直得到错误there is no reactor running, must be called from the context of a Tokio 1.x runtime我在某处读到这是因为有两个版本的tokio crate正在使用,所以我试图将actix-web升级到4.0.0-beta8,但错误仍然存在。

#[test]
async fn test_sp() {
// pool setup code here
let mut client = pool.get().await.unwrap();
let name: &str = "test_user";
let rows = client.query("test_user_add", &[&name]).await.unwrap(); 
}

你需要一个tokio反应堆运行时,tokio有一个测试功能的工具:

#[tokio::test]
async fn my_test() {
assert!(true);
}

请务必阅读文档。

最新更新