From d9ace3e71562b15861f40f3dc53b9812477e0e8d Mon Sep 17 00:00:00 2001 From: Gustavo Inacio Date: Fri, 27 Dec 2024 14:57:38 -0300 Subject: [PATCH] test: add test-with for network subgraph test dependent (#557) Signed-off-by: Gustavo Inacio --- Cargo.lock | 221 ++++++++++++++++++- crates/monitor/Cargo.toml | 1 + crates/monitor/src/allocations.rs | 10 +- crates/monitor/src/client/subgraph_client.rs | 8 +- 4 files changed, 220 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa6df19d..6525aee8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1807,6 +1807,17 @@ version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" +[[package]] +name = "byte-unit" +version = "5.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cd29c3c585209b0cbc7309bfe3ed7efd8c84c21b7af29c8bfae908f8777174" +dependencies = [ + "rust_decimal", + "serde", + "utf8-width", +] + [[package]] name = "bytecheck" version = "0.6.12" @@ -1950,8 +1961,10 @@ checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "android-tzdata", "iana-time-zone", + "js-sys", "num-traits", "serde", + "wasm-bindgen", "windows-targets 0.52.6", ] @@ -2213,6 +2226,16 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + [[package]] name = "crossbeam-epoch" version = "0.9.18" @@ -2520,6 +2543,12 @@ dependencies = [ "log", ] +[[package]] +name = "env_home" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f84e12ccf0a7ddc17a6c41c93326024c42920d7ee630d04950e6926645c0fe" + [[package]] name = "env_logger" version = "0.11.6" @@ -3300,7 +3329,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.5.8", "tokio", "tower-service", "tracing", @@ -3403,7 +3432,7 @@ dependencies = [ "http-body 1.0.1", "hyper 1.5.1", "pin-project-lite", - "socket2", + "socket2 0.5.8", "tokio", "tower-service", "tracing", @@ -3420,7 +3449,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -3668,6 +3697,7 @@ dependencies = [ "serde_json", "test-assets", "test-log", + "test-with", "thegraph-core", "thiserror 1.0.69", "tokio", @@ -4447,6 +4477,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38bf9645c8b145698bb0b18a4637dcacbc421ea49bef2317e4fd8065a387cf21" +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -4928,6 +4967,17 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "ping" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "122ee1f5a6843bec84fcbd5c6ba3622115337a6b8965b93a61aad347648f4e8d" +dependencies = [ + "rand", + "socket2 0.4.10", + "thiserror 1.0.69", +] + [[package]] name = "pkcs1" version = "0.7.5" @@ -5215,7 +5265,7 @@ dependencies = [ "quinn-udp", "rustc-hash", "rustls 0.23.19", - "socket2", + "socket2 0.5.8", "thiserror 2.0.3", "tokio", "tracing", @@ -5250,7 +5300,7 @@ dependencies = [ "cfg_aliases 0.2.1", "libc", "once_cell", - "socket2", + "socket2 0.5.8", "tracing", "windows-sys 0.59.0", ] @@ -5344,6 +5394,26 @@ dependencies = [ "bitflags 2.6.0", ] +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "recvmsg" version = "1.0.0" @@ -5475,6 +5545,7 @@ dependencies = [ "base64 0.22.1", "bytes", "encoding_rs", + "futures-channel", "futures-core", "futures-util", "h2 0.4.7", @@ -6332,6 +6403,16 @@ dependencies = [ "serde", ] +[[package]] +name = "socket2" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "socket2" version = "0.5.8" @@ -6739,6 +6820,20 @@ dependencies = [ "syn 2.0.90", ] +[[package]] +name = "sysinfo" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "948512566b1895f93b1592c7574baeb2de842f224f2aab158799ecadb8ebbb46" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "rayon", + "windows", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -6872,6 +6967,27 @@ dependencies = [ "syn 2.0.90", ] +[[package]] +name = "test-with" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfe0744d7360b0ffece0f61e6a33834a0f6d8479bc71f6537fb7c98de10782d2" +dependencies = [ + "byte-unit", + "chrono", + "num_cpus", + "ping", + "proc-macro-error2", + "proc-macro2", + "quote", + "regex", + "reqwest 0.12.9", + "syn 2.0.90", + "sysinfo", + "uzers", + "which", +] + [[package]] name = "thegraph-core" version = "0.9.6" @@ -7035,7 +7151,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2", + "socket2 0.5.8", "tokio-macros", "windows-sys 0.52.0", ] @@ -7194,7 +7310,7 @@ dependencies = [ "prost", "rustls-native-certs 0.8.1", "rustls-pemfile 2.2.0", - "socket2", + "socket2 0.5.8", "tokio", "tokio-rustls 0.26.0", "tokio-stream", @@ -7583,6 +7699,12 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" +[[package]] +name = "utf8-width" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86bd8d4e895da8537e5315b8254664e6b769c4ff3db18321b297a1e7004392e3" + [[package]] name = "utf8_iter" version = "1.0.4" @@ -7604,6 +7726,16 @@ dependencies = [ "getrandom", ] +[[package]] +name = "uzers" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76d283dc7e8c901e79e32d077866eaf599156cbf427fffa8289aecc52c5c3f63" +dependencies = [ + "libc", + "log", +] + [[package]] name = "valuable" version = "0.1.0" @@ -7804,6 +7936,18 @@ dependencies = [ "rustls-pki-types", ] +[[package]] +name = "which" +version = "7.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb4a9e33648339dc1642b0e36e21b3385e6148e289226f657c809dee59df5028" +dependencies = [ + "either", + "env_home", + "rustix", + "winsafe", +] + [[package]] name = "whoami" version = "1.5.2" @@ -7851,6 +7995,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -7860,17 +8014,60 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result 0.1.2", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", +] + [[package]] name = "windows-registry" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" dependencies = [ - "windows-result", + "windows-result 0.2.0", "windows-strings", "windows-targets 0.52.6", ] +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-result" version = "0.2.0" @@ -7886,7 +8083,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" dependencies = [ - "windows-result", + "windows-result 0.2.0", "windows-targets 0.52.6", ] @@ -8057,6 +8254,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "winsafe" +version = "0.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904" + [[package]] name = "wiremock" version = "0.6.2" diff --git a/crates/monitor/Cargo.toml b/crates/monitor/Cargo.toml index 15bbde36..25ef0f1c 100644 --- a/crates/monitor/Cargo.toml +++ b/crates/monitor/Cargo.toml @@ -25,3 +25,4 @@ env_logger = { version = "0.11.0", default-features = false } test-log = { version = "0.2.12", default-features = false } wiremock.workspace = true test-assets = { path = "../test-assets" } +test-with = "0.14.6" diff --git a/crates/monitor/src/allocations.rs b/crates/monitor/src/allocations.rs index ea2230f9..6f7ce0c3 100644 --- a/crates/monitor/src/allocations.rs +++ b/crates/monitor/src/allocations.rs @@ -97,22 +97,20 @@ mod test { use super::*; use crate::client::{DeploymentDetails, SubgraphClient}; - const NETWORK_SUBGRAPH_URL: &str = - "https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-arbitrum"; - async fn network_subgraph_client() -> &'static SubgraphClient { + let url = std::env::var("NETWORK_SUBGRAPH_URL").unwrap(); Box::leak(Box::new( SubgraphClient::new( reqwest::Client::new(), None, - DeploymentDetails::for_query_url(NETWORK_SUBGRAPH_URL).unwrap(), + DeploymentDetails::for_query_url(&url).unwrap(), ) .await, )) } #[tokio::test] - #[ignore = "depends on the defunct hosted-service"] + #[test_with::env(NETWORK_SUBGRAPH_URL)] async fn test_network_query() { let result = get_allocations( network_subgraph_client().await, @@ -124,7 +122,7 @@ mod test { } #[tokio::test] - #[ignore = "depends on the defunct hosted-service"] + #[test_with::env(NETWORK_SUBGRAPH_URL)] async fn test_network_query_empty_response() { let result = get_allocations( network_subgraph_client().await, diff --git a/crates/monitor/src/client/subgraph_client.rs b/crates/monitor/src/client/subgraph_client.rs index 01f6199a..7b17e211 100644 --- a/crates/monitor/src/client/subgraph_client.rs +++ b/crates/monitor/src/client/subgraph_client.rs @@ -262,9 +262,6 @@ mod test { use super::*; - const NETWORK_SUBGRAPH_URL: &str = - "https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-goerli"; - async fn mock_graph_node_server() -> MockServer { let mock_server = MockServer::start().await; let mock = Mock::given(method("POST")) @@ -290,16 +287,17 @@ mod test { } async fn network_subgraph_client() -> SubgraphClient { + let url = std::env::var("NETWORK_SUBGRAPH_URL").unwrap(); SubgraphClient::new( reqwest::Client::new(), None, - DeploymentDetails::for_query_url(NETWORK_SUBGRAPH_URL).unwrap(), + DeploymentDetails::for_query_url(&url).unwrap(), ) .await } #[tokio::test] - #[ignore = "depends on the defunct hosted-service"] + #[test_with::env(NETWORK_SUBGRAPH_URL)] async fn test_network_query() { let _mock_server = mock_graph_node_server().await;