upgrade actix and redis to latest versions

This commit is contained in:
Aravinth Manivannan 2021-06-30 20:01:57 +05:30
parent bf9526db39
commit 0a1c9e1e5a
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
7 changed files with 115 additions and 909 deletions

933
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,7 @@ edition = "2018"
readme = "README.md" readme = "README.md"
[dependencies] [dependencies]
actix = { version = "0.10", optional = true} actix = { version = "0.12", optional = true}
serde = "1.0.114" serde = "1.0.114"
serde_json = "1" serde_json = "1"
@ -26,13 +26,13 @@ rand = {version = "0.8", optional = true }
pow_sha256 = { version = "0.2.1", git = "https://github.com/mcaptcha/pow_sha256", optional=true } pow_sha256 = { version = "0.2.1", git = "https://github.com/mcaptcha/pow_sha256", optional=true }
#redis = { version = "0.20.1", features = ["tokio-comp","aio", "cluster"], optional=true } redis = { version = "0.20.2", features = ["tokio-comp","aio", "cluster"], optional=true }
redis = { version = "0.17.0", features = ["tokio-comp","aio", "cluster"], optional=true } #redis = { version = "0.17.0", features = ["tokio-comp","aio", "cluster"], optional=true }
tokio = { version = "0.2.25", features = ["sync"]} tokio = { version = "1", features = ["sync"]}
[dev-dependencies] [dev-dependencies]
actix-rt = "1" actix-rt = "2"
[features] [features]
default = [ default = [

View File

@ -98,8 +98,8 @@ impl Actor for HashCache {
impl Handler<CachePoW> for HashCache { impl Handler<CachePoW> for HashCache {
type Result = MessageResult<CachePoW>; type Result = MessageResult<CachePoW>;
fn handle(&mut self, msg: CachePoW, ctx: &mut Self::Context) -> Self::Result { fn handle(&mut self, msg: CachePoW, ctx: &mut Self::Context) -> Self::Result {
//use actix::clock::sleep; use actix::clock::sleep;
use actix::clock::delay_for; //use actix::clock::delay_for;
use std::time::Duration; use std::time::Duration;
let addr = ctx.address(); let addr = ctx.address();
@ -107,8 +107,8 @@ impl Handler<CachePoW> for HashCache {
let duration: Duration = Duration::new(msg.duration, 0); let duration: Duration = Duration::new(msg.duration, 0);
let wait_for = async move { let wait_for = async move {
//sleep(duration).await; sleep(duration).await;
delay_for(duration).await; //delay_for(duration).await;
addr.send(del_msg).await.unwrap().unwrap(); addr.send(del_msg).await.unwrap().unwrap();
} }
.into_actor(self); .into_actor(self);
@ -143,8 +143,8 @@ impl Handler<RetrivePoW> for HashCache {
impl Handler<CacheResult> for HashCache { impl Handler<CacheResult> for HashCache {
type Result = MessageResult<CacheResult>; type Result = MessageResult<CacheResult>;
fn handle(&mut self, msg: CacheResult, ctx: &mut Self::Context) -> Self::Result { fn handle(&mut self, msg: CacheResult, ctx: &mut Self::Context) -> Self::Result {
//use actix::clock::sleep; use actix::clock::sleep;
use actix::clock::delay_for; //use actix::clock::delay_for;
use std::time::Duration; use std::time::Duration;
let addr = ctx.address(); let addr = ctx.address();
@ -154,8 +154,8 @@ impl Handler<CacheResult> for HashCache {
let duration: Duration = Duration::new(msg.duration, 0); let duration: Duration = Duration::new(msg.duration, 0);
let wait_for = async move { let wait_for = async move {
//sleep(duration).await; sleep(duration).await;
delay_for(duration).await; //delay_for(duration).await;
addr.send(del_msg).await.unwrap().unwrap(); addr.send(del_msg).await.unwrap().unwrap();
} }
.into_actor(self); .into_actor(self);
@ -193,6 +193,9 @@ mod tests {
use crate::master::AddVisitorResult; use crate::master::AddVisitorResult;
use crate::pow::PoWConfig; use crate::pow::PoWConfig;
use actix::clock::sleep;
use std::time::Duration;
// async fn sleep(time: u64) { // async fn sleep(time: u64) {
// //use actix::clock::sleep; // //use actix::clock::sleep;
// use actix::clock::delay_for; // use actix::clock::delay_for;
@ -205,9 +208,6 @@ mod tests {
#[actix_rt::test] #[actix_rt::test]
async fn hashcache_pow_cache_works() { async fn hashcache_pow_cache_works() {
use actix::clock::delay_for;
use actix::clock::Duration;
const DIFFICULTY_FACTOR: u32 = 54; const DIFFICULTY_FACTOR: u32 = 54;
const DURATION: u64 = 5; const DURATION: u64 = 5;
const KEY: &str = "mcaptchakey"; const KEY: &str = "mcaptchakey";
@ -247,7 +247,7 @@ mod tests {
let duration: Duration = Duration::new(5, 0); let duration: Duration = Duration::new(5, 0);
//sleep(DURATION + DURATION).await; //sleep(DURATION + DURATION).await;
delay_for(duration + duration).await; sleep(duration + duration).await;
let expired_string = addr let expired_string = addr
.send(RetrivePoW(msg)) .send(RetrivePoW(msg))
@ -261,9 +261,6 @@ mod tests {
#[actix_rt::test] #[actix_rt::test]
async fn hashcache_result_cache_works() { async fn hashcache_result_cache_works() {
use actix::clock::delay_for;
use actix::clock::Duration;
const DURATION: u64 = 5; const DURATION: u64 = 5;
const KEY: &str = "a"; const KEY: &str = "a";
const RES: &str = "b"; const RES: &str = "b";
@ -304,7 +301,7 @@ mod tests {
assert!(!addr.send(verify_msg).await.unwrap().await.unwrap().unwrap()); assert!(!addr.send(verify_msg).await.unwrap().await.unwrap().unwrap());
let duration: Duration = Duration::new(5, 0); let duration: Duration = Duration::new(5, 0);
delay_for(duration + duration).await; sleep(duration + duration).await;
let verify_msg = VerifyCaptchaResult { let verify_msg = VerifyCaptchaResult {
key: KEY.into(), key: KEY.into(),

18
src/cache/redis.rs vendored
View File

@ -148,6 +148,10 @@ impl Handler<DeletePoW> for RedisCache {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use std::time::Duration;
use actix::clock::sleep;
//use crate::master::AddVisitorResult; //use crate::master::AddVisitorResult;
//use crate::pow::PoWConfig; //use crate::pow::PoWConfig;
@ -165,9 +169,6 @@ mod tests {
#[actix_rt::test] #[actix_rt::test]
async fn rediscache_pow_cache_works() { async fn rediscache_pow_cache_works() {
use actix::clock::delay_for;
use actix::clock::Duration;
const DIFFICULTY_FACTOR: u32 = 54; const DIFFICULTY_FACTOR: u32 = 54;
const DURATION: u64 = 5; const DURATION: u64 = 5;
const KEY: &str = "mcaptchakey"; const KEY: &str = "mcaptchakey";
@ -211,8 +212,8 @@ mod tests {
); );
let duration: Duration = Duration::new(5, 0); let duration: Duration = Duration::new(5, 0);
//sleep(DURATION + DURATION).await; //delay_for(duration + duration).await;
delay_for(duration + duration).await; sleep(duration + duration).await;
let expired_string = addr.send(RetrivePoW(msg)).await.unwrap().await.unwrap(); let expired_string = addr.send(RetrivePoW(msg)).await.unwrap().await.unwrap();
assert!(expired_string.is_err()); assert!(expired_string.is_err());
@ -220,8 +221,8 @@ mod tests {
#[actix_rt::test] #[actix_rt::test]
async fn redishashcache_result_cache_works() { async fn redishashcache_result_cache_works() {
use actix::clock::delay_for; use std::time::Duration;
use actix::clock::Duration; //use actix::clock::delay_for;
const DURATION: u64 = 5; const DURATION: u64 = 5;
const KEY: &str = "a"; const KEY: &str = "a";
@ -267,7 +268,8 @@ mod tests {
assert!(!addr.send(verify_msg).await.unwrap().await.unwrap().unwrap()); assert!(!addr.send(verify_msg).await.unwrap().await.unwrap().unwrap());
let duration: Duration = Duration::new(5, 0); let duration: Duration = Duration::new(5, 0);
delay_for(duration + duration).await; //delay_for(duration + duration).await;
sleep(duration + duration).await;
let verify_msg = VerifyCaptchaResult { let verify_msg = VerifyCaptchaResult {
key: KEY.into(), key: KEY.into(),

View File

@ -82,7 +82,7 @@
use std::time::Duration; use std::time::Duration;
//use actix::clock::sleep; use actix::clock::sleep;
use actix::dev::*; use actix::dev::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -126,12 +126,12 @@ impl Handler<AddVisitor> for Counter {
fn handle(&mut self, _: AddVisitor, ctx: &mut Self::Context) -> Self::Result { fn handle(&mut self, _: AddVisitor, ctx: &mut Self::Context) -> Self::Result {
let addr = ctx.address(); let addr = ctx.address();
use actix::clock::delay_for; //use actix::clock::delay_for;
let duration: Duration = Duration::new(self.0.get_duration(), 0); let duration: Duration = Duration::new(self.0.get_duration(), 0);
let wait_for = async move { let wait_for = async move {
//sleep(duration).await; sleep(duration).await;
delay_for(duration).await; //delay_for(duration).await;
addr.send(DeleteVisitor).await.unwrap(); addr.send(DeleteVisitor).await.unwrap();
} }
.into_actor(self); .into_actor(self);
@ -252,7 +252,7 @@ pub mod tests {
#[actix_rt::test] #[actix_rt::test]
async fn counter_defense_loosenup_works() { async fn counter_defense_loosenup_works() {
//use actix::clock::sleep; //use actix::clock::sleep;
use actix::clock::delay_for; //use actix::clock::delay_for;
let addr: MyActor = get_counter().start(); let addr: MyActor = get_counter().start();
race(addr.clone(), LEVEL_2).await; race(addr.clone(), LEVEL_2).await;
@ -261,8 +261,8 @@ pub mod tests {
assert_eq!(mcaptcha.difficulty_factor, LEVEL_2.1); assert_eq!(mcaptcha.difficulty_factor, LEVEL_2.1);
let duration = Duration::new(DURATION, 0); let duration = Duration::new(DURATION, 0);
//sleep(duration).await; sleep(duration).await;
delay_for(duration).await; //delay_for(duration).await;
mcaptcha = addr.send(AddVisitor).await.unwrap(); mcaptcha = addr.send(AddVisitor).await.unwrap();
assert_eq!(mcaptcha.difficulty_factor, LEVEL_1.1); assert_eq!(mcaptcha.difficulty_factor, LEVEL_1.1);

View File

@ -19,8 +19,8 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::time::Duration; use std::time::Duration;
//use actix::clock::sleep; use actix::clock::sleep;
use actix::clock::delay_for; //use actix::clock::delay_for;
use actix::dev::*; use actix::dev::*;
use log::info; use log::info;
use tokio::sync::oneshot::channel; use tokio::sync::oneshot::channel;
@ -158,8 +158,8 @@ impl Handler<CleanUp> for Master {
} }
let duration = Duration::new(gc, 0); let duration = Duration::new(gc, 0);
//sleep(duration).await; sleep(duration).await;
delay_for(duration).await; //delay_for(duration).await;
master.send(CleanUp).await.unwrap(); master.send(CleanUp).await.unwrap();
} }
.into_actor(self); .into_actor(self);
@ -220,10 +220,10 @@ mod tests {
assert!(addr_doesnt_exist.is_none()); assert!(addr_doesnt_exist.is_none());
let timer_expire = Duration::new(DURATION, 0); let timer_expire = Duration::new(DURATION, 0);
// sleep(timer_expire).await; sleep(timer_expire).await;
// sleep(timer_expire).await; sleep(timer_expire).await;
delay_for(timer_expire).await; // delay_for(timer_expire).await;
delay_for(timer_expire).await; // delay_for(timer_expire).await;
let mcaptcha_addr = addr.send(GetSite(id.into())).await.unwrap(); let mcaptcha_addr = addr.send(GetSite(id.into())).await.unwrap();
assert_eq!(mcaptcha_addr, None); assert_eq!(mcaptcha_addr, None);

View File

@ -115,7 +115,7 @@ mod tests {
assert_eq!(visitors, 1); assert_eq!(visitors, 1);
let timer_expire = std::time::Duration::new(duration, 0); let timer_expire = std::time::Duration::new(duration, 0);
actix::clock::delay_for(timer_expire).await; actix::clock::sleep(timer_expire).await;
let visitors = r.get_visitors(CAPTCHA_NAME).await.unwrap(); let visitors = r.get_visitors(CAPTCHA_NAME).await.unwrap();
assert_eq!(visitors, 0); assert_eq!(visitors, 0);
} }
@ -153,7 +153,7 @@ mod tests {
assert_eq!(visitors, 500); assert_eq!(visitors, 500);
let timer_expire = std::time::Duration::new(duration, 0); let timer_expire = std::time::Duration::new(duration, 0);
actix::clock::delay_for(timer_expire).await; actix::clock::sleep(timer_expire).await;
let visitors = r.get_visitors(CAPTCHA_NAME).await.unwrap(); let visitors = r.get_visitors(CAPTCHA_NAME).await.unwrap();
assert_eq!(visitors, 0); assert_eq!(visitors, 0);
} }