diff --git a/web3_proxy/src/config.rs b/web3_proxy/src/config.rs index 8a582684..3988bfc3 100644 --- a/web3_proxy/src/config.rs +++ b/web3_proxy/src/config.rs @@ -342,7 +342,10 @@ mod tests { 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); diff --git a/web3_proxy/src/stats/stat_buffer.rs b/web3_proxy/src/stats/stat_buffer.rs index 1ec3a7b2..2c8c65ed 100644 --- a/web3_proxy/src/stats/stat_buffer.rs +++ b/web3_proxy/src/stats/stat_buffer.rs @@ -141,7 +141,9 @@ impl StatBuffer { tokio::select! { stat = stat_receiver.recv() => { 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 { break; } diff --git a/web3_proxy/tests/common/app.rs b/web3_proxy/tests/common/app.rs index 8e95fcdd..a5ebcf75 100644 --- a/web3_proxy/tests/common/app.rs +++ b/web3_proxy/tests/common/app.rs @@ -49,6 +49,7 @@ impl TestApp { anvil: &TestAnvil, db: Option<&TestMysql>, influx: Option<&TestInflux>, + influx_id: Option, ) -> Self { let chain_id = anvil.instance.chain_id(); let num_workers = 4; @@ -80,6 +81,7 @@ impl TestApp { "influxdb_org": influx_org, "influxdb_token": influx_token, "influxdb_bucket": influx_bucket, + "influx_id": influx_id, "default_user_max_requests_per_period": Some(6_000_000), "deposit_factory_contract": Address::from_str( "4e3BC2054788De923A04936C6ADdB99A05B0Ea36", diff --git a/web3_proxy/tests/test_admins.rs b/web3_proxy/tests/test_admins.rs index 18cb0695..b29d70d4 100644 --- a/web3_proxy/tests/test_admins.rs +++ b/web3_proxy/tests/test_admins.rs @@ -29,7 +29,7 @@ async fn test_admin_grant_credits() { 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() .timeout(Duration::from_secs(3)) diff --git a/web3_proxy/tests/test_multiple_proxy.rs b/web3_proxy/tests/test_multiple_proxy.rs index 6ad3f244..9a5d7dea 100644 --- a/web3_proxy/tests/test_multiple_proxy.rs +++ b/web3_proxy/tests/test_multiple_proxy.rs @@ -34,8 +34,8 @@ async fn test_multiple_proxies_stats_add_up() { .unwrap(); // Since when do indices start with 1 - let x_0 = TestApp::spawn(&a, Some(&db), Some(&influx)).await; - let x_1 = 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), Some("app_1".to_string())).await; // make a user and give them credits 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)); // Generate the proxies - let number_requests = 50; + let number_requests = 10; let mut handles = Vec::new(); // Get the RPC key from the user @@ -80,8 +80,8 @@ async fn test_multiple_proxies_stats_add_up() { warn!("Created users, generated providers"); - info!("Proxy 1: {:?}", proxy_0_user_0_provider); - info!("Proxy 2: {:?}", proxy_1_user_0_provider); + info!("Proxy 0: {:?}", proxy_0_user_0_provider); + info!("Proxy 1: {:?}", proxy_1_user_0_provider); for _ in 0..number_requests { // 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(); + // 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 // 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(); @@ -265,9 +269,11 @@ async fn test_multiple_proxies_stats_add_up() { // user_get_influx_stats_detailed // ); - // drop x first to avoid spurious warnings about anvil/influx/mysql shutting down before the app - drop(x_0); - drop(x_1); + x_0.stop().unwrap(); + x_1.stop().unwrap(); + + x_0.wait_for_stop(); + x_1.wait_for_stop(); } // Gotta compare stats with influx: diff --git a/web3_proxy/tests/test_proxy.rs b/web3_proxy/tests/test_proxy.rs index a351af2e..76a7f165 100644 --- a/web3_proxy/tests/test_proxy.rs +++ b/web3_proxy/tests/test_proxy.rs @@ -16,7 +16,7 @@ async fn it_migrates_the_db() { let a = TestAnvil::spawn(31337).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 x.flush_stats().await.unwrap(); @@ -29,7 +29,7 @@ async fn it_migrates_the_db() { async fn it_starts_and_stops() { 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 proxy_provider = &x.proxy_provider; diff --git a/web3_proxy/tests/test_single_proxy.rs b/web3_proxy/tests/test_single_proxy.rs index 6092f0ac..0fae4259 100644 --- a/web3_proxy/tests/test_single_proxy.rs +++ b/web3_proxy/tests/test_single_proxy.rs @@ -33,8 +33,7 @@ async fn test_single_proxy_stats_add_up() { .build() .unwrap(); - // Since when do indices start with 1 - let x = TestApp::spawn(&a, Some(&db), Some(&influx)).await; + let x = TestApp::spawn(&a, Some(&db), Some(&influx), None).await; // make a user and give them credits let user_0_wallet = a.wallet(0); @@ -79,8 +78,8 @@ async fn test_single_proxy_stats_add_up() { warn!("Created users, generated providers"); - info!("Proxy 1: {:?}", proxy_0_user_0_provider); - info!("Proxy 2: {:?}", proxy_1_user_0_provider); + info!("Proxy 0: {:?}", proxy_0_user_0_provider); + info!("Proxy 1: {:?}", proxy_1_user_0_provider); for _ in 0..number_requests { // 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(); + // give stats time to get into the channel + // TODO: do this better + sleep(Duration::from_secs(10)).await; + // Flush all stats here // 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(); @@ -115,12 +118,12 @@ async fn test_single_proxy_stats_add_up() { // todo!("Need to validate all the stat accounting now"); // Get the stats from here 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 = user_get_influx_stats_aggregated(&x, &r, &user_0_login, chain_id).await; info!( - "influx_aggregate_stats stats are: {:?}", + "influx_aggregate_stats stats are: {:#?}", influx_aggregate_stats ); @@ -232,7 +235,6 @@ async fn test_single_proxy_stats_add_up() { // user_get_influx_stats_detailed // ); - // drop x first to avoid spurious warnings about anvil/influx/mysql shutting down before the app drop(x); } diff --git a/web3_proxy/tests/test_sum_credits_used.rs b/web3_proxy/tests/test_sum_credits_used.rs index 0e60e5f7..1401a045 100644 --- a/web3_proxy/tests/test_sum_credits_used.rs +++ b/web3_proxy/tests/test_sum_credits_used.rs @@ -25,7 +25,7 @@ async fn test_sum_credits_used() { 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() .timeout(Duration::from_secs(3)) diff --git a/web3_proxy/tests/test_users.rs b/web3_proxy/tests/test_users.rs index 685e23e1..e39e6471 100644 --- a/web3_proxy/tests/test_users.rs +++ b/web3_proxy/tests/test_users.rs @@ -42,7 +42,7 @@ async fn test_log_in_and_out() { 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(); @@ -103,7 +103,7 @@ async fn test_admin_balance_increase() { 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() .timeout(Duration::from_secs(20)) @@ -156,7 +156,7 @@ async fn test_user_balance_decreases() { 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() .timeout(Duration::from_secs(20)) @@ -264,7 +264,7 @@ async fn test_referral_bonus_non_concurrent() { 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() .timeout(Duration::from_secs(20)) @@ -413,7 +413,7 @@ async fn test_referral_bonus_concurrent_referrer_only() { 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() .timeout(Duration::from_secs(20)) @@ -576,7 +576,7 @@ async fn test_referral_bonus_concurrent_referrer_and_user() { 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() .timeout(Duration::from_secs(20))