Use tokio runtime for tests and actix version

This commit is contained in:
Antoine Gersant 2020-01-16 01:03:39 -08:00
parent 289827d6a3
commit 4194509f45
4 changed files with 28 additions and 12 deletions

14
Cargo.lock generated
View file

@ -2071,7 +2071,6 @@ dependencies = [
"anyhow 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", "anyhow 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
"ape 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "ape 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"app_dirs 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "app_dirs 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"async-trait 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
"base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"diesel 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "diesel 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"diesel_migrations 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "diesel_migrations 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2101,6 +2100,7 @@ dependencies = [
"simplelog 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "simplelog 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"thiserror 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", "thiserror 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
"unix-daemonize 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "unix-daemonize 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2998,9 +2998,11 @@ dependencies = [
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)",
"mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", "mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
"pin-project-lite 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "pin-project-lite 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-macros 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -3042,6 +3044,15 @@ dependencies = [
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "tokio-macros"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "tokio-reactor" name = "tokio-reactor"
version = "0.1.11" version = "0.1.11"
@ -3783,6 +3794,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d16217cad7f1b840c5a97dfb3c43b0c871fef423a6e8d2118c604e843662a443" "checksum tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d16217cad7f1b840c5a97dfb3c43b0c871fef423a6e8d2118c604e843662a443"
"checksum tokio-executor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "ca6df436c42b0c3330a82d855d2ef017cd793090ad550a6bc2184f4b933532ab" "checksum tokio-executor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "ca6df436c42b0c3330a82d855d2ef017cd793090ad550a6bc2184f4b933532ab"
"checksum tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5090db468dad16e1a7a54c8c67280c5e4b544f3d3e018f0b913b400261f85926" "checksum tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5090db468dad16e1a7a54c8c67280c5e4b544f3d3e018f0b913b400261f85926"
"checksum tokio-macros 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "50a61f268a3db2acee8dcab514efc813dc6dbe8a00e86076f935f94304b59a7a"
"checksum tokio-reactor 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "6732fe6b53c8d11178dcb77ac6d9682af27fc6d4cb87789449152e5377377146" "checksum tokio-reactor 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "6732fe6b53c8d11178dcb77ac6d9682af27fc6d4cb87789449152e5377377146"
"checksum tokio-sync 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "d06554cce1ae4a50f42fba8023918afa931413aded705b560e29600ccf7c6d76" "checksum tokio-sync 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "d06554cce1ae4a50f42fba8023918afa931413aded705b560e29600ccf7c6d76"
"checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119" "checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119"

View file

@ -8,18 +8,17 @@ edition = "2018"
default = ["service-actix"] default = ["service-actix"]
ui = [] ui = []
profile-index = ["flame", "flamer"] profile-index = ["flame", "flamer"]
service-actix = ["actix-files", "actix-http", "actix-web"] service-actix = ["actix-files", "actix-http", "actix-rt", "actix-web"]
service-rocket = ["rocket", "rocket_contrib"] service-rocket = ["rocket", "rocket_contrib"]
[dependencies] [dependencies]
actix-files = { version = "0.2", optional = true } actix-files = { version = "0.2", optional = true }
actix-http = { version = "1.0", optional = true } actix-http = { version = "1.0", optional = true }
actix-web = { version = "2.0", optional = true } actix-web = { version = "2.0", optional = true }
actix-rt = { version = "1.0"} actix-rt = { version = "1.0", optional = true}
anyhow = "1.0" anyhow = "1.0"
ape = "0.2.0" ape = "0.2.0"
app_dirs = "1.1.1" app_dirs = "1.1.1"
async-trait = "0.1.22"
base64 = "0.11.0" base64 = "0.11.0"
diesel = { version = "1.4", features = ["sqlite", "r2d2"] } diesel = { version = "1.4", features = ["sqlite", "r2d2"] }
diesel_migrations = { version = "1.4", features = ["sqlite"] } diesel_migrations = { version = "1.4", features = ["sqlite"] }
@ -55,6 +54,10 @@ default_features = false
features = ["json", "serve"] features = ["json", "serve"]
optional = true optional = true
[dependencies.tokio]
version = "0.2"
features = ["macros", "rt-threaded"]
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
uuid = "0.8" uuid = "0.8"

View file

@ -1,4 +1,3 @@
use actix_rt::System;
use actix_web::{App, HttpServer}; use actix_web::{App, HttpServer};
use anyhow::*; use anyhow::*;
use std::path::PathBuf; use std::path::PathBuf;
@ -18,7 +17,9 @@ pub fn run(
db: DB, db: DB,
command_sender: Arc<CommandSender>, command_sender: Arc<CommandSender>,
) -> Result<()> { ) -> Result<()> {
let mut sys = System::new("polaris_service_executor"); let mut runtime = tokio::runtime::Runtime::new()?;
let local_set = tokio::task::LocalSet::new();
let _ = actix_rt::System::run_in_tokio("polaris_service_executor", &local_set);
let server = HttpServer::new(move || { let server = HttpServer::new(move || {
App::new().configure(|cfg| { App::new().configure(|cfg| {
@ -35,5 +36,5 @@ pub fn run(
.bind(format!("0.0.0.0:{}", port))? .bind(format!("0.0.0.0:{}", port))?
.run(); .run();
sys.block_on(server).map_err(Error::new) runtime.block_on(server).map_err(Error::new)
} }

View file

@ -16,21 +16,21 @@ const TEST_MOUNT_NAME: &str = "collection";
const TEST_MOUNT_SOURCE: &str = "test/collection"; const TEST_MOUNT_SOURCE: &str = "test/collection";
#[named] #[named]
#[actix_rt::test] #[tokio::test]
async fn test_index() { async fn test_index() {
let mut service = make_service(function_name!()).await; let mut service = make_service(function_name!()).await;
get(&mut service, "/").await; get(&mut service, "/").await;
} }
#[named] #[named]
#[actix_rt::test] #[tokio::test]
async fn test_swagger_index() { async fn test_swagger_index() {
let mut service = make_service(function_name!()).await; let mut service = make_service(function_name!()).await;
get(&mut service, "/swagger").await; get(&mut service, "/swagger").await;
} }
#[named] #[named]
#[actix_rt::test] #[tokio::test]
async fn test_swagger_index_with_trailing_slash() { async fn test_swagger_index_with_trailing_slash() {
let mut service = make_service(function_name!()).await; let mut service = make_service(function_name!()).await;
get(&mut service, "/swagger/").await; get(&mut service, "/swagger/").await;
@ -56,7 +56,7 @@ async fn complete_initial_setup(service: &mut ServiceType) {
} }
#[named] #[named]
#[actix_rt::test] #[tokio::test]
async fn test_version() { async fn test_version() {
let mut service = make_service(function_name!()).await; let mut service = make_service(function_name!()).await;
let version: dto::Version = get_json(&mut service, "/api/version").await; let version: dto::Version = get_json(&mut service, "/api/version").await;
@ -64,7 +64,7 @@ async fn test_version() {
} }
#[named] #[named]
#[actix_rt::test] #[tokio::test]
async fn test_initial_setup() { async fn test_initial_setup() {
let mut service = make_service(function_name!()).await; let mut service = make_service(function_name!()).await;