need unique names in tests
This commit is contained in:
parent
4091e05f3d
commit
80d50bc2c0
@ -342,7 +342,10 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(a.min_synced_rpcs, 1);
|
assert_eq!(a.min_synced_rpcs, 1);
|
||||||
|
|
||||||
let b: AppConfig = Default::default();
|
let mut b: AppConfig = Default::default();
|
||||||
|
|
||||||
|
// influxdb_id is randomized
|
||||||
|
b.influxdb_id = a.influxdb_id.clone();
|
||||||
|
|
||||||
assert_eq!(b.min_synced_rpcs, 1);
|
assert_eq!(b.min_synced_rpcs, 1);
|
||||||
|
|
||||||
|
@ -141,7 +141,9 @@ impl StatBuffer {
|
|||||||
tokio::select! {
|
tokio::select! {
|
||||||
stat = stat_receiver.recv() => {
|
stat = stat_receiver.recv() => {
|
||||||
if let Some(stat) = stat {
|
if let Some(stat) = stat {
|
||||||
total_frontend_requests += self._buffer_app_stat(stat).await?
|
total_frontend_requests += self._buffer_app_stat(stat).await?;
|
||||||
|
|
||||||
|
// TODO: if buffers are big, flush now?
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ impl TestApp {
|
|||||||
anvil: &TestAnvil,
|
anvil: &TestAnvil,
|
||||||
db: Option<&TestMysql>,
|
db: Option<&TestMysql>,
|
||||||
influx: Option<&TestInflux>,
|
influx: Option<&TestInflux>,
|
||||||
|
influx_id: Option<String>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let chain_id = anvil.instance.chain_id();
|
let chain_id = anvil.instance.chain_id();
|
||||||
let num_workers = 4;
|
let num_workers = 4;
|
||||||
@ -80,6 +81,7 @@ impl TestApp {
|
|||||||
"influxdb_org": influx_org,
|
"influxdb_org": influx_org,
|
||||||
"influxdb_token": influx_token,
|
"influxdb_token": influx_token,
|
||||||
"influxdb_bucket": influx_bucket,
|
"influxdb_bucket": influx_bucket,
|
||||||
|
"influx_id": influx_id,
|
||||||
"default_user_max_requests_per_period": Some(6_000_000),
|
"default_user_max_requests_per_period": Some(6_000_000),
|
||||||
"deposit_factory_contract": Address::from_str(
|
"deposit_factory_contract": Address::from_str(
|
||||||
"4e3BC2054788De923A04936C6ADdB99A05B0Ea36",
|
"4e3BC2054788De923A04936C6ADdB99A05B0Ea36",
|
||||||
|
@ -29,7 +29,7 @@ async fn test_admin_grant_credits() {
|
|||||||
|
|
||||||
let db = TestMysql::spawn().await;
|
let db = TestMysql::spawn().await;
|
||||||
|
|
||||||
let x = TestApp::spawn(&a, Some(&db), None).await;
|
let x = TestApp::spawn(&a, Some(&db), None, None).await;
|
||||||
|
|
||||||
let r = reqwest::Client::builder()
|
let r = reqwest::Client::builder()
|
||||||
.timeout(Duration::from_secs(3))
|
.timeout(Duration::from_secs(3))
|
||||||
|
@ -34,8 +34,8 @@ async fn test_multiple_proxies_stats_add_up() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Since when do indices start with 1
|
// Since when do indices start with 1
|
||||||
let x_0 = TestApp::spawn(&a, Some(&db), Some(&influx)).await;
|
let x_0 = TestApp::spawn(&a, Some(&db), Some(&influx), Some("app_0".to_string())).await;
|
||||||
let x_1 = TestApp::spawn(&a, Some(&db), Some(&influx)).await;
|
let x_1 = TestApp::spawn(&a, Some(&db), Some(&influx), Some("app_1".to_string())).await;
|
||||||
|
|
||||||
// make a user and give them credits
|
// make a user and give them credits
|
||||||
let user_0_wallet = a.wallet(0);
|
let user_0_wallet = a.wallet(0);
|
||||||
@ -62,7 +62,7 @@ async fn test_multiple_proxies_stats_add_up() {
|
|||||||
assert_eq!(user_1_balance_pre, Decimal::from(2000));
|
assert_eq!(user_1_balance_pre, Decimal::from(2000));
|
||||||
|
|
||||||
// Generate the proxies
|
// Generate the proxies
|
||||||
let number_requests = 50;
|
let number_requests = 10;
|
||||||
let mut handles = Vec::new();
|
let mut handles = Vec::new();
|
||||||
|
|
||||||
// Get the RPC key from the user
|
// Get the RPC key from the user
|
||||||
@ -80,8 +80,8 @@ async fn test_multiple_proxies_stats_add_up() {
|
|||||||
|
|
||||||
warn!("Created users, generated providers");
|
warn!("Created users, generated providers");
|
||||||
|
|
||||||
info!("Proxy 1: {:?}", proxy_0_user_0_provider);
|
info!("Proxy 0: {:?}", proxy_0_user_0_provider);
|
||||||
info!("Proxy 2: {:?}", proxy_1_user_0_provider);
|
info!("Proxy 1: {:?}", proxy_1_user_0_provider);
|
||||||
|
|
||||||
for _ in 0..number_requests {
|
for _ in 0..number_requests {
|
||||||
// send 2 to proxy 0 user 0
|
// send 2 to proxy 0 user 0
|
||||||
@ -116,6 +116,10 @@ async fn test_multiple_proxies_stats_add_up() {
|
|||||||
|
|
||||||
try_join_all(handles).await.unwrap();
|
try_join_all(handles).await.unwrap();
|
||||||
|
|
||||||
|
// just because the handles are all joined doesn't mean the stats have had time to make it into the buffer
|
||||||
|
// TODO: don't sleep. watch an atomic counter or something
|
||||||
|
sleep(Duration::from_secs(10)).await;
|
||||||
|
|
||||||
// Flush all stats here
|
// Flush all stats here
|
||||||
// TODO: the test should maybe pause time so that stats definitely flush from our queries.
|
// TODO: the test should maybe pause time so that stats definitely flush from our queries.
|
||||||
let flush_0_count_0 = x_0.flush_stats().await.unwrap();
|
let flush_0_count_0 = x_0.flush_stats().await.unwrap();
|
||||||
@ -265,9 +269,11 @@ async fn test_multiple_proxies_stats_add_up() {
|
|||||||
// user_get_influx_stats_detailed
|
// user_get_influx_stats_detailed
|
||||||
// );
|
// );
|
||||||
|
|
||||||
// drop x first to avoid spurious warnings about anvil/influx/mysql shutting down before the app
|
x_0.stop().unwrap();
|
||||||
drop(x_0);
|
x_1.stop().unwrap();
|
||||||
drop(x_1);
|
|
||||||
|
x_0.wait_for_stop();
|
||||||
|
x_1.wait_for_stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gotta compare stats with influx:
|
// Gotta compare stats with influx:
|
||||||
|
@ -16,7 +16,7 @@ async fn it_migrates_the_db() {
|
|||||||
let a = TestAnvil::spawn(31337).await;
|
let a = TestAnvil::spawn(31337).await;
|
||||||
let db = TestMysql::spawn().await;
|
let db = TestMysql::spawn().await;
|
||||||
|
|
||||||
let x = TestApp::spawn(&a, Some(&db), None).await;
|
let x = TestApp::spawn(&a, Some(&db), None, None).await;
|
||||||
|
|
||||||
// we call flush stats more to be sure it works than because we expect it to save any stats
|
// we call flush stats more to be sure it works than because we expect it to save any stats
|
||||||
x.flush_stats().await.unwrap();
|
x.flush_stats().await.unwrap();
|
||||||
@ -29,7 +29,7 @@ async fn it_migrates_the_db() {
|
|||||||
async fn it_starts_and_stops() {
|
async fn it_starts_and_stops() {
|
||||||
let a = TestAnvil::spawn(31337).await;
|
let a = TestAnvil::spawn(31337).await;
|
||||||
|
|
||||||
let x = TestApp::spawn(&a, None, None).await;
|
let x = TestApp::spawn(&a, None, None, None).await;
|
||||||
|
|
||||||
let anvil_provider = &a.provider;
|
let anvil_provider = &a.provider;
|
||||||
let proxy_provider = &x.proxy_provider;
|
let proxy_provider = &x.proxy_provider;
|
||||||
|
@ -33,8 +33,7 @@ async fn test_single_proxy_stats_add_up() {
|
|||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Since when do indices start with 1
|
let x = TestApp::spawn(&a, Some(&db), Some(&influx), None).await;
|
||||||
let x = TestApp::spawn(&a, Some(&db), Some(&influx)).await;
|
|
||||||
|
|
||||||
// make a user and give them credits
|
// make a user and give them credits
|
||||||
let user_0_wallet = a.wallet(0);
|
let user_0_wallet = a.wallet(0);
|
||||||
@ -79,8 +78,8 @@ async fn test_single_proxy_stats_add_up() {
|
|||||||
|
|
||||||
warn!("Created users, generated providers");
|
warn!("Created users, generated providers");
|
||||||
|
|
||||||
info!("Proxy 1: {:?}", proxy_0_user_0_provider);
|
info!("Proxy 0: {:?}", proxy_0_user_0_provider);
|
||||||
info!("Proxy 2: {:?}", proxy_1_user_0_provider);
|
info!("Proxy 1: {:?}", proxy_1_user_0_provider);
|
||||||
|
|
||||||
for _ in 0..number_requests {
|
for _ in 0..number_requests {
|
||||||
// send 2 to proxy 0 user 0
|
// send 2 to proxy 0 user 0
|
||||||
@ -96,6 +95,10 @@ async fn test_single_proxy_stats_add_up() {
|
|||||||
|
|
||||||
try_join_all(handles).await.unwrap();
|
try_join_all(handles).await.unwrap();
|
||||||
|
|
||||||
|
// give stats time to get into the channel
|
||||||
|
// TODO: do this better
|
||||||
|
sleep(Duration::from_secs(10)).await;
|
||||||
|
|
||||||
// Flush all stats here
|
// Flush all stats here
|
||||||
// TODO: the test should maybe pause time so that stats definitely flush from our queries.
|
// TODO: the test should maybe pause time so that stats definitely flush from our queries.
|
||||||
let flush_0_count_0 = x.flush_stats().await.unwrap();
|
let flush_0_count_0 = x.flush_stats().await.unwrap();
|
||||||
@ -115,12 +118,12 @@ async fn test_single_proxy_stats_add_up() {
|
|||||||
// todo!("Need to validate all the stat accounting now");
|
// todo!("Need to validate all the stat accounting now");
|
||||||
// Get the stats from here
|
// Get the stats from here
|
||||||
let mysql_stats = user_get_mysql_stats(&x, &r, &user_0_login).await;
|
let mysql_stats = user_get_mysql_stats(&x, &r, &user_0_login).await;
|
||||||
info!("mysql stats are: {:?}", mysql_stats);
|
info!("mysql stats are: {:#?}", mysql_stats);
|
||||||
|
|
||||||
let influx_aggregate_stats =
|
let influx_aggregate_stats =
|
||||||
user_get_influx_stats_aggregated(&x, &r, &user_0_login, chain_id).await;
|
user_get_influx_stats_aggregated(&x, &r, &user_0_login, chain_id).await;
|
||||||
info!(
|
info!(
|
||||||
"influx_aggregate_stats stats are: {:?}",
|
"influx_aggregate_stats stats are: {:#?}",
|
||||||
influx_aggregate_stats
|
influx_aggregate_stats
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -232,7 +235,6 @@ async fn test_single_proxy_stats_add_up() {
|
|||||||
// user_get_influx_stats_detailed
|
// user_get_influx_stats_detailed
|
||||||
// );
|
// );
|
||||||
|
|
||||||
|
|
||||||
// drop x first to avoid spurious warnings about anvil/influx/mysql shutting down before the app
|
// drop x first to avoid spurious warnings about anvil/influx/mysql shutting down before the app
|
||||||
drop(x);
|
drop(x);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ async fn test_sum_credits_used() {
|
|||||||
|
|
||||||
let db_conn = db.conn().await;
|
let db_conn = db.conn().await;
|
||||||
|
|
||||||
let x = TestApp::spawn(&a, Some(&db), Some(&i)).await;
|
let x = TestApp::spawn(&a, Some(&db), Some(&i), None).await;
|
||||||
|
|
||||||
let r = reqwest::Client::builder()
|
let r = reqwest::Client::builder()
|
||||||
.timeout(Duration::from_secs(3))
|
.timeout(Duration::from_secs(3))
|
||||||
|
@ -42,7 +42,7 @@ async fn test_log_in_and_out() {
|
|||||||
|
|
||||||
let db = TestMysql::spawn().await;
|
let db = TestMysql::spawn().await;
|
||||||
|
|
||||||
let x = TestApp::spawn(&a, Some(&db), None).await;
|
let x = TestApp::spawn(&a, Some(&db), None, None).await;
|
||||||
|
|
||||||
let r = reqwest::Client::new();
|
let r = reqwest::Client::new();
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ async fn test_admin_balance_increase() {
|
|||||||
|
|
||||||
let db = TestMysql::spawn().await;
|
let db = TestMysql::spawn().await;
|
||||||
|
|
||||||
let x = TestApp::spawn(&a, Some(&db), None).await;
|
let x = TestApp::spawn(&a, Some(&db), None, None).await;
|
||||||
|
|
||||||
let r = reqwest::Client::builder()
|
let r = reqwest::Client::builder()
|
||||||
.timeout(Duration::from_secs(20))
|
.timeout(Duration::from_secs(20))
|
||||||
@ -156,7 +156,7 @@ async fn test_user_balance_decreases() {
|
|||||||
|
|
||||||
let db = TestMysql::spawn().await;
|
let db = TestMysql::spawn().await;
|
||||||
|
|
||||||
let x = TestApp::spawn(&a, Some(&db), None).await;
|
let x = TestApp::spawn(&a, Some(&db), None, None).await;
|
||||||
|
|
||||||
let r = reqwest::Client::builder()
|
let r = reqwest::Client::builder()
|
||||||
.timeout(Duration::from_secs(20))
|
.timeout(Duration::from_secs(20))
|
||||||
@ -264,7 +264,7 @@ async fn test_referral_bonus_non_concurrent() {
|
|||||||
|
|
||||||
let db = TestMysql::spawn().await;
|
let db = TestMysql::spawn().await;
|
||||||
|
|
||||||
let x = TestApp::spawn(&a, Some(&db), None).await;
|
let x = TestApp::spawn(&a, Some(&db), None, None).await;
|
||||||
|
|
||||||
let r = reqwest::Client::builder()
|
let r = reqwest::Client::builder()
|
||||||
.timeout(Duration::from_secs(20))
|
.timeout(Duration::from_secs(20))
|
||||||
@ -413,7 +413,7 @@ async fn test_referral_bonus_concurrent_referrer_only() {
|
|||||||
|
|
||||||
let db = TestMysql::spawn().await;
|
let db = TestMysql::spawn().await;
|
||||||
|
|
||||||
let x = TestApp::spawn(&a, Some(&db), None).await;
|
let x = TestApp::spawn(&a, Some(&db), None, None).await;
|
||||||
|
|
||||||
let r = reqwest::Client::builder()
|
let r = reqwest::Client::builder()
|
||||||
.timeout(Duration::from_secs(20))
|
.timeout(Duration::from_secs(20))
|
||||||
@ -576,7 +576,7 @@ async fn test_referral_bonus_concurrent_referrer_and_user() {
|
|||||||
|
|
||||||
let db = TestMysql::spawn().await;
|
let db = TestMysql::spawn().await;
|
||||||
|
|
||||||
let x = TestApp::spawn(&a, Some(&db), None).await;
|
let x = TestApp::spawn(&a, Some(&db), None, None).await;
|
||||||
|
|
||||||
let r = reqwest::Client::builder()
|
let r = reqwest::Client::builder()
|
||||||
.timeout(Duration::from_secs(20))
|
.timeout(Duration::from_secs(20))
|
||||||
|
Loading…
Reference in New Issue
Block a user