tmp actix downgrade

This commit is contained in:
Aravinth Manivannan 2021-04-02 11:17:05 +05:30
parent 9183fae264
commit 61ee89aee3
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
5 changed files with 650 additions and 91 deletions

696
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -23,4 +23,4 @@ rand = "0.8"
pow_sha256 = { version = "0.2.1", git = "https://github.com/mcaptcha/pow_sha256" } pow_sha256 = { version = "0.2.1", git = "https://github.com/mcaptcha/pow_sha256" }
[dev-dependencies] [dev-dependencies]
actix-rt = "2" actix-rt = "1"

View file

@ -60,7 +60,8 @@ impl Actor for HashCache {
impl Handler<Cache> for HashCache { impl Handler<Cache> for HashCache {
type Result = MessageResult<Cache>; type Result = MessageResult<Cache>;
fn handle(&mut self, msg: Cache, ctx: &mut Self::Context) -> Self::Result { fn handle(&mut self, msg: Cache, ctx: &mut Self::Context) -> Self::Result {
use actix::clock::sleep; //use actix::clock::sleep;
use actix::clock::delay_for;
use std::time::Duration; use std::time::Duration;
let addr = ctx.address(); let addr = ctx.address();
@ -68,7 +69,8 @@ impl Handler<Cache> for HashCache {
let duration: Duration = Duration::new(msg.duration.clone(), 0); let duration: Duration = Duration::new(msg.duration.clone(), 0);
let wait_for = async move { let wait_for = async move {
sleep(duration).await; //sleep(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);
@ -102,15 +104,20 @@ mod tests {
use crate::pow::PoWConfig; use crate::pow::PoWConfig;
async fn sleep(time: u64) { async fn sleep(time: u64) {
use actix::clock::sleep; //use actix::clock::sleep;
use actix::clock::delay_for;
use std::time::Duration; use std::time::Duration;
let duration: Duration = Duration::new(time, 0); let duration: Duration = Duration::new(time, 0);
sleep(duration).await; //sleep(duration).await;
delay_for(duration).await;
} }
#[actix_rt::test] #[actix_rt::test]
async fn hashcache_works() { async fn hashcache_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;
let addr = HashCache::default().start(); let addr = HashCache::default().start();
@ -127,7 +134,9 @@ mod tests {
let cache_difficulty_factor = addr.send(Retrive(string.clone())).await.unwrap().unwrap(); let cache_difficulty_factor = addr.send(Retrive(string.clone())).await.unwrap().unwrap();
assert_eq!(DIFFICULTY_FACTOR, cache_difficulty_factor.unwrap()); assert_eq!(DIFFICULTY_FACTOR, cache_difficulty_factor.unwrap());
sleep(DURATION + DURATION).await; let duration: Duration = Duration::new(5, 0);
//sleep(DURATION + DURATION).await;
delay_for(duration + duration).await;
let expired_string = addr.send(Retrive(string)).await.unwrap().unwrap(); let expired_string = addr.send(Retrive(string)).await.unwrap().unwrap();
assert_eq!(None, expired_string); assert_eq!(None, expired_string);

View file

@ -19,7 +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::dev::*; use actix::dev::*;
use derive_builder::Builder; use derive_builder::Builder;
@ -124,7 +125,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;
master.send(CleanUp).await.unwrap(); master.send(CleanUp).await.unwrap();
} }
.into_actor(self); .into_actor(self);
@ -187,8 +189,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;
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

@ -74,7 +74,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};
@ -215,10 +215,12 @@ impl Handler<AddVisitor> for MCaptcha {
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;
let duration: Duration = Duration::new(self.duration.clone(), 0); let duration: Duration = Duration::new(self.duration.clone(), 0);
let wait_for = async move { let wait_for = async move {
sleep(duration).await; //sleep(duration).await;
delay_for(duration).await;
addr.send(DeleteVisitor).await.unwrap(); addr.send(DeleteVisitor).await.unwrap();
} }
.into_actor(self); .into_actor(self);
@ -320,7 +322,8 @@ 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;
let addr: MyActor = get_counter().start(); let addr: MyActor = get_counter().start();
race(addr.clone(), LEVEL_2).await; race(addr.clone(), LEVEL_2).await;
@ -329,7 +332,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;
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);