message: add Metrics integration tests
diff: @@ -5,17 +5,12 @@ inject_indy_dependencies!();
  extern crate indyrs as indy;
  extern crate indyrs as api;
  -
  +use crate::utils::wallet;
  use crate::utils::metrics;
  +use crate::utils::constants::*;
  +use crate::utils::Setup;
  +
  -const THREADPOOL_ACTIVE_COUNT: &str = "threadpool_active_count";
  -const THREADPOOL_QUEUED_COUNT: &str = "threadpool_queued_count";
  -const THREADPOOL_MAX_COUNT: &str = "threadpool_max_count";
  -const THREADPOOL_PANIC_COUNT: &str = "threadpool_panic_count";
  -const OPENED_WALLETS_COUNT: &str = "opened_wallets_count";
  -const OPENED_WALLET_IDS_COUNT: &str = "opened_wallet_ids_count";
  -const PENDING_FOR_IMPORT_WALLETS_COUNT: &str = "pending_for_import_wallets_count";
  -const PENDING_FOR_OPEN_WALLETS_COUNT: &str = "pending_for_open_wallets_count";
  mod collect {
  use super::*;
  @@ -25,13 +20,31 @@ mod collect {
  fn collect_metrics_works() {
  let result_metrics = metrics::collect_metrics().unwrap();
  let metrics_map = serde_json::from_str::<HashMap<String, usize>>(&result_metrics).unwrap();
  - assert!(metrics_map.contains_key(THREADPOOL_ACTIVE_COUNT));
  - assert!(metrics_map.contains_key(THREADPOOL_QUEUED_COUNT));
  - assert!(metrics_map.contains_key(THREADPOOL_MAX_COUNT));
  - assert!(metrics_map.contains_key(THREADPOOL_PANIC_COUNT));
  - assert!(metrics_map.contains_key(OPENED_WALLETS_COUNT));
  - assert!(metrics_map.contains_key(OPENED_WALLET_IDS_COUNT));
  - assert!(metrics_map.contains_key(PENDING_FOR_IMPORT_WALLETS_COUNT));
  - assert!(metrics_map.contains_key(PENDING_FOR_OPEN_WALLETS_COUNT));
  + assert!(metrics_map.contains_key("threadpool_active_count"));
  + assert!(metrics_map.contains_key("threadpool_queued_count"));
  + assert!(metrics_map.contains_key("threadpool_max_count"));
  + assert!(metrics_map.contains_key("threadpool_panic_count"));
  + assert!(metrics_map.contains_key("opened_wallets_count"));
  + assert!(metrics_map.contains_key("opened_wallet_ids_count"));
  + assert!(metrics_map.contains_key("pending_for_import_wallets_count"));
  + assert!(metrics_map.contains_key("pending_for_open_wallets_count"));
  + }
  +
  + #[test]
  + fn collect_metrics_after_works() {
  + let setup = Setup::empty();
  + let config = config(&setup.name);
  + wallet::create_wallet(&config, WALLET_CREDENTIALS).unwrap();
  +
  + let result_metrics = metrics::collect_metrics().unwrap();
  + let metrics_map = serde_json::from_str::<HashMap<String, u128>>(&result_metrics).unwrap();
  +
  + assert_eq!(metrics_map.get("wallet_command_create_queued_commands_count").unwrap(), &1u128);
  + assert!(metrics_map.get("wallet_command_create_queued_commands_duration_ms").unwrap() > &0u128);
  + assert_eq!(metrics_map.get("wallet_command_create_executed_commands_count").unwrap(), &1u128);
  + assert!(metrics_map.get("wallet_command_create_executed_commands_duration_ms").unwrap() > &0u128);
  + }
  + fn config(name: &str) -> String {
  + json!({"id": name}).to_string()
  }
  }
  