2023-07-21 04:22:25 +03:00
|
|
|
mod common;
|
|
|
|
|
|
|
|
use crate::common::influx::TestInflux;
|
|
|
|
use moka::future::Cache;
|
|
|
|
use tokio::sync::{broadcast, mpsc};
|
|
|
|
use web3_proxy::{caches::UserBalanceCache, stats::StatBuffer};
|
|
|
|
|
2023-07-21 05:05:24 +03:00
|
|
|
#[cfg_attr(not(feature = "tests-needing-docker"), ignore)]
|
2023-07-21 04:22:25 +03:00
|
|
|
#[test_log::test(tokio::test)]
|
|
|
|
async fn test_two_buffers() {
|
|
|
|
let i = TestInflux::spawn().await;
|
|
|
|
|
|
|
|
let billing_period_seconds = 86400 * 7;
|
|
|
|
let chain_id = 999_001_999;
|
|
|
|
let db_save_interval_seconds = 60;
|
|
|
|
let influxdb_bucket = Some(i.bucket.clone());
|
|
|
|
let influxdb_client = Some(i.client.clone());
|
|
|
|
let rpc_secret_key_cache = Cache::builder().build();
|
2023-07-22 01:25:12 +03:00
|
|
|
let tsdb_save_interval_seconds = 30;
|
2023-07-21 04:22:25 +03:00
|
|
|
let user_balance_cache: UserBalanceCache = Cache::builder().build().into();
|
|
|
|
|
|
|
|
let (shutdown_sender, shutdown_receiver_1) = broadcast::channel(1);
|
|
|
|
let shutdown_receiver_2 = shutdown_sender.subscribe();
|
|
|
|
|
|
|
|
let (flush_sender_1, flush_receiver_1) = mpsc::channel(1);
|
|
|
|
let (flush_sender_2, flush_receiver_2) = mpsc::channel(1);
|
|
|
|
|
|
|
|
let buffer_1 = StatBuffer::try_spawn(
|
|
|
|
billing_period_seconds,
|
|
|
|
chain_id,
|
|
|
|
db_save_interval_seconds,
|
|
|
|
influxdb_bucket.clone(),
|
|
|
|
influxdb_client.clone(),
|
|
|
|
rpc_secret_key_cache.clone(),
|
|
|
|
user_balance_cache.clone(),
|
|
|
|
shutdown_receiver_1,
|
|
|
|
tsdb_save_interval_seconds,
|
|
|
|
flush_sender_1,
|
|
|
|
flush_receiver_1,
|
2023-07-22 10:26:02 +03:00
|
|
|
"buffer_1".to_string(),
|
2023-07-21 04:22:25 +03:00
|
|
|
)
|
|
|
|
.unwrap()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let buffer_2 = StatBuffer::try_spawn(
|
|
|
|
billing_period_seconds,
|
|
|
|
chain_id,
|
|
|
|
db_save_interval_seconds,
|
|
|
|
influxdb_bucket,
|
|
|
|
influxdb_client,
|
|
|
|
rpc_secret_key_cache,
|
|
|
|
user_balance_cache,
|
|
|
|
shutdown_receiver_2,
|
|
|
|
tsdb_save_interval_seconds,
|
|
|
|
flush_sender_2,
|
|
|
|
flush_receiver_2,
|
2023-07-22 10:26:02 +03:00
|
|
|
"buffer_2".to_string(),
|
2023-07-21 04:22:25 +03:00
|
|
|
)
|
|
|
|
.unwrap()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// TODO: send things to the buffers
|
|
|
|
|
|
|
|
shutdown_sender.send(()).unwrap();
|
|
|
|
|
|
|
|
buffer_1.background_handle.await.unwrap().unwrap();
|
|
|
|
buffer_2.background_handle.await.unwrap().unwrap();
|
|
|
|
}
|