Upgrade to tokio 1.0 - part 8
@@ -123,24 +123,20 @@ mod test {
use actix_web::web::Json;
use actix_web::{web, App, HttpServer};
use maplit::*;
- use std::sync::Arc;
- use std::sync::Mutex;
use tornado_collector_jmespath::config::JMESPathEventCollectorConfig;
use tornado_common_api::Value;
//use tornado_common_logger::{setup_logger, LoggerConfig};
- #[test]
- fn should_perform_a_post_request() {
+ #[actix_rt::test]
+ async fn should_perform_a_post_request() {
//start_logger();
- let received = Arc::new(Mutex::new(vec![]));
-
- let act_received = received.clone();
-
- let sys = actix_rt::System::new("basic-example");
+ let (sender, mut receiver) = tokio::sync::mpsc::unbounded_channel();
let api = "/v1/events";
let api_clone = api.clone();
+ actix::spawn(async move {
+
HttpServer::new(move || {
App::new().service(web::resource(api).route(web::post().to(
move |body: Json<Stream>| async {
@@ -164,12 +160,11 @@ mod test {
username: "".to_owned(),
sleep_ms_between_connection_attempts: 0,
};
- let app_received = act_received.clone();
+ let sender = sender.clone();
Icinga2StreamActor {
callback: move |event| {
info!("Callback called with Event: {:?}", event);
- let mut message = app_received.lock().unwrap();
- message.push(event);
+ sender.send(event).unwrap();
// The actor tries to establish a long polling connection to the server;
// however, the server used in this test drops the connection after each response.
@@ -177,9 +172,6 @@ mod test {
// it means that the actor was successfully restarted after each connection drop, so the client
// is correctly handling dropped connections.
- if message.len() > 2 {
- System::current().stop();
- }
},
collector: JMESPathEventCollector::build(JMESPathEventCollectorConfig {
event_type: "test".to_owned(),
@@ -200,11 +192,13 @@ mod test {
Ok(server)
})
.expect("Can not bind to port 0")
- .run();
-
- sys.run().unwrap();
+ .run().await.unwrap();
+ });
- let events = received.lock().unwrap().clone();
+ let mut events = vec![];
+ events.push(receiver.recv().await.unwrap());
+ events.push(receiver.recv().await.unwrap());
+ events.push(receiver.recv().await.unwrap());
assert_eq!(3, events.len());
events.iter().for_each(|event| {
