Skip to content

Commit 72b522f

Browse files
committed
Merge branch 'aip-61-adex-v5' into issue-392-get-all-spenders-info
2 parents 3fc3b18 + aae1400 commit 72b522f

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

sentry/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ migrant_lib = { version = "^0.32", features = ["d-postgres"] }
3636
# Logger
3737
slog = { version = "^2.2.3", features = ["max_level_trace"] }
3838
# Serde
39-
serde = { version = "^1.0", features = ['derive'] }
39+
serde = { version = "^1.0", features = ["derive"] }
4040
serde_json = "^1.0"
4141
serde_urlencoded = "^0.7"
4242
# Other

sentry/src/db.rs

+25-12
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ pub mod tests_postgres {
402402
pub mod redis_pool {
403403

404404
use dashmap::DashMap;
405-
use deadpool::managed::{Manager as ManagerTrait, RecycleError, RecycleResult};
405+
use deadpool::managed::{Manager as ManagerTrait, RecycleResult};
406406
use thiserror::Error;
407407

408408
use crate::db::redis_connection;
@@ -420,6 +420,7 @@ pub mod redis_pool {
420420
#[derive(Clone)]
421421
pub struct Database {
422422
available: bool,
423+
index: u8,
423424
pub connection: MultiplexedConnection,
424425
}
425426

@@ -473,11 +474,10 @@ pub mod redis_pool {
473474

474475
#[derive(Debug, Error)]
475476
pub enum Error {
476-
// when we can't create more databases and all are used
477-
#[error("No more databases can be created")]
478-
OutOfBound,
479477
#[error("A redis error occurred")]
480478
Redis(#[from] RedisError),
479+
#[error("Creation of new database connection failed")]
480+
CreationFailed,
481481
}
482482

483483
#[async_trait]
@@ -495,17 +495,24 @@ pub mod redis_pool {
495495
return Ok(database.clone());
496496
}
497497
// if Some but not available, skip it
498-
Some(_) => continue,
499-
None => {
498+
Some(database) if !database.available => continue,
499+
// if there is no connection or it's available
500+
// always create a new redis connection because of a known issue in redis
501+
// see https://github.com/mitsuhiko/redis-rs/issues/325
502+
_ => {
500503
let mut redis_conn =
501-
redis_connection(&format!("{}{}", Self::URL, record.key())).await?;
504+
redis_connection(&format!("{}{}", Self::URL, record.key()))
505+
.await
506+
.expect("Should connect");
502507

503508
// run `FLUSHDB` to clean any leftovers of previous tests
504509
// even from different test runs as there might be leftovers
505-
Self::flush_db(&mut redis_conn).await?;
510+
// flush never fails as an operation
511+
Self::flush_db(&mut redis_conn).await.expect("Should flush");
506512

507513
let database = Database {
508514
available: false,
515+
index: *record.key(),
509516
connection: redis_conn,
510517
};
511518

@@ -516,15 +523,21 @@ pub mod redis_pool {
516523
}
517524
}
518525

519-
Err(Error::OutOfBound)
526+
Err(Error::CreationFailed)
520527
}
521528

522529
async fn recycle(&self, database: &mut Database) -> RecycleResult<Self::Error> {
523-
// run `FLUSHDB` to clean any leftovers of previous tests
524-
Self::flush_db(&mut database.connection)
530+
// always make a new connection because of know redis crate issue
531+
// see https://github.com/mitsuhiko/redis-rs/issues/325
532+
let connection = redis_connection(&format!("{}{}", Self::URL, database.index))
525533
.await
526-
.map_err(RecycleError::Backend)?;
534+
.expect("Should connect");
535+
// make the database available
527536
database.available = true;
537+
database.connection = connection;
538+
Self::flush_db(&mut database.connection)
539+
.await
540+
.expect("Should flush");
528541

529542
Ok(())
530543
}

sentry/src/routes/campaign.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ mod test {
792792
spender: create.creator,
793793
channel: create.channel.clone(),
794794
deposit: Deposit {
795-
// a deposit equal to double the Campaign Budget
795+
// a deposit 4 times larger than the Campaign Budget
796796
total: UnifiedNum::from(200_000_000_000),
797797
still_on_create2: UnifiedNum::from(0),
798798
},

0 commit comments

Comments
 (0)